Friday, March 20, 2009
BottleNecks
In my 5 years as a DBA I often encounter this very standard set of issues
SQL is spiking at 100%, my queries are slow, and their server is not responsive. My queries time out and the list goes on. The truth is there is no easy answer to this problem. There is no magic option to be set or no magic command that will solve this. The best thing to do is run a trace on the database and see what is going on. Most likely you will come across queries that are causing unnecessary disk io operations or page splits, you might find some that are using table scanning all the time (this means you do not have indexes set up correctly).
Here are a few possible reasons for processing spiking
• Poorly designed queries
• Bad table design
• Database files not set up for optimal performance
• No or incorrect indexes on tables
• Indexes are on tables but they are fragmented and need to be rebuilt
• Server does not have enough processing power or ram to handle the tasks required of it
By running a trace you can identify all of these situations and even inexperienced users should be able to determine most issues. Its fixing them that is the hard thing.
So let us go over these issues one by one and give some advice on each one.
• Poorly designed queries
This is the first thing you should check for because it does not require any hardware upgrades and also is the most common issue. Remember that just because queries return the correct result does not make them right. Query tuning is one of the hardest things to master. Thank god we have some great tools to aid us like profile and DTA (database engine tuning advisor).
In my carrier I have seen some really bad queries most of the time due to the developer not understanding how the storage engine works and how to take advantage of the query plan. I would strongly suggest reading “inside sql server 2005 the storage engine” By Microsoft press. This will empower you with the knowledge you need to write high performance queries. In later blogs I will dive in to this topic further and try and explain the best practices of writing queries. I am also always willing to help anyone out (If I can ) on this topic so just drop me a line (see my email at the bottom) .
• Bad table design
This is by far the hardest to fix and often imposable, no matter how good your queries are if the table (s) you are hitting are not set up properly you will have performance issues. You can think of it like this. If SQL has to work harder to get the information it needs then it’s going to take longer for it to return the dataset. Again in later blogs I will dive further in to this topic as it can be placed in a book itself.
• Database files not set up for optimal performance
This is a very common issue and is reacted to the actual storage media used to store the data files for the database. Database files should be stored on a raid configuration at the least. And most enterprise level solutions have multiple database files per database stored on different raid drives. This is the most expensive issue to fix and most of the tomes clients are unwilling to spend the money to resolve this issue.
Also people tend to throw new hardware at problems before determining or fixing other issues related to bottlenecks. In most cases even if you have the greatest hardware, if your tables, indexes, or queries are not doing their job it will not solve the problem.
• No or incorrect indexes on tables
SQL server implements a very powerful indexing system that can be the difference for a query running 2 minutes or 2 hours. Indexing a table gives huge read benefits to queries. They should however be used with caution. The more indexes you place on a table the longer it will take to update and insert records in to the table. I often hear arguments like “why can’t we index the whole table” . The reason is you would have a huge bottleneck on every update and insert statement you though at a table. So you need to think about the impact on every column you index. Things like “how often is this table going to be updated”. Again this is a huge topic that really needs a full understanding of when and what to index. The DTA is a good place to start and will usually pick the right indexes. Again feel free to drop me a line with any specific questions,
• Indexes are on tables but they are fragmented and need to be rebuilt
This is actually the easiest to fix. The problem is once an index is created it can become fragmented over time due to updates and inserts. I won’t go in to much detail about this issue right here. I am planning to do a whole series on indexes in the next couple of weeks and will dive in to the different types of fragmentation and how to rebuild the index (and when to rebuild and when to recreate) again if you need help just drop me a line.
• Server does not have enough processing power or ram to handle the tasks required of it
Sometimes it is simply a matter of asking your server to do too much. SQL Server Needs the hardware to be able to perform its tasks. That’s as simple as I can put it.
You could do everything right but if the server does not have the cycles to execute tasks in a high performing way then there’s really nothing that can be done other then upgrading the box . I have a client who has 2 servers both doing the exact same thing (one is production and one is history) . The production server has 4 CPUS 30 gigs of ram while the other server has one cpu and 8 gigs of ram.
If you ran the same query on both servers the production server would finish in let’s say 5 minutes while the history one would take over an hour.
I hope this at least can get you in the right mind set for tackling your bottlenecks
As always feel free to drop me a line for more advise or questions. I will answer all emails send at mccannblogs@gmail.com
McCann Out
Wednesday, March 18, 2009
Primary keys (1 of 2)
• Guid
• Identity
• A column that represents a unique property of the entity in question
In this 2 part blog I will weigh in on my personal preference as well as discuss all three solutions
Today in part one we will discuss the goals we wish to achieve for the primary key and we will discuss the first option. Then tomorrow we will discuss the other 2 options and come to our conclusion
Let me just say now my personal preference is Guids
I have worked and seen the impact on all 3 solutions and feel this is the best one. Is it perfect? No but it comes the closest.
First let’s examine the criteria we would like in a perfect word for our primary key to have.
1. It has to be able to uniquely identify a row
2. Since in most cases the key will be clustered it should be what I call a “light weight” data type
3. It would be great if we could attached some meaning to the column we choose
4. Whatever method we choose it should be implemented though out the whole database
OK I know a lot of people are not going to agree with goal 4.
Let me explain. In my view all tables in a system should follow the same basic design for no other reason than ease of use and understanding by all developers and administrators on staff. What goes for one table should work for all other tables.
Are there exceptions? Yes but they better be good ones I want to know why and have a chance to make our implantation work.
So let’s examine the three choices
Off our three choices the one that might have a chance of obtaining all our primary goals is
Choosing a column represents a unique property of the entity in question
So obviously this method is the only one that will satisfy goal 3. The problem lies with the other 3 goals. And the time costs to everyone evolved by implementing this method
Let’s look at goal 1 again. We have to be able to identify a row with this column.
That means for every table we create we need to be able to identify a row by one column (or a combination of columns) . Has anyone actually implemented this on a whole database??? I think not it is next to imposable to do this for every table in your system
That means it will most likely violate rule 4 and quite possibly rule 2.
I have seen this happen many times people start banging their heads together trying to find that one column that will uniquely identify this entity. All of a sudden columns like email address and some weird long string representing a product number., Or my favourite some combination of 3 characters from one column and 2 characters from this column to make a unique value. ....... do I even have to comment . and yes OldBalls if you are reading this I am talking to you. Then there is the time its going to take to go through every table and design this solution the frustrations that will happen when you realize that you can’t find any column to use for x table and resort to mixing methods and then what do you have? One cluster **** of a database that’s what
In closing this is the worst method to choose and should be avoided like ketchup on a white suit.
comments, questions? drop me a line at
mccannblogs@gmail.com
McCann OUT!!!!!!!!
Wednesday, February 11, 2009
disable a user instances in SQL Server full text search
sp_configure ‘user instances enabled’,0
If you have any tips, tricks, resources or questions please email Susan Fischer at susan@clinchportal.com
Tuesday, February 10, 2009
Sunday, January 18, 2009
Full Text Indexing On SQL Express 2005
The download size is larger but its worth it for the full text indexing feature.
Detailed instructions can be found at:
http://rpsetzer.wordpress.com/2007/01/24/configuring-and-using-full-text-search-in-sql-server-2005-express-edition/
- Install SQL Server Express Advanced
- Make sure that you include the installation of Full-text Search(not included by default)
- Disable user instances, either by unchecking it at setup or by running
sp_configure ‘user instances enabled’,0 - Make sure your database has full-text search enabled, by checking the “use full-text indexing” in the “Create new database” window or by accessing the properties window for an existing dabase, Going to “Files” and checking the “use full-text indexing” option
- With your database active, run
CREATE FULLTEXT CATALOG MyFullTextCatalog
to create a full-text catalog. - Make sure that the tables that you want to be indexed under full-text search have a unique, non-nullable index
- Create your unique indexes as follows:
CREATE FULLTEXT INDEX ON Production.ProductReview(Comments)KEY INDEX ui_ProductReview ON MyFullTextCatalogWITH CHANGE_TRACKING AUTO
If you run into trouble check the article link I supplied above there is a lot of info there and a link to a step by step video
Thursday, December 18, 2008
SSIS Component Addins
Thanks to John the Greek God again. It seems he has come across another piece of valuable info. It seems you can purchase SSIS development components. Maybe some of these will be useful to you. Also now that you know they can be created, you could possibly generate your own as well to help others. Here is the link:
http://www.cozyroc.com/support/ssis_home.html
If you have any tips, tricks, resources you would like to share with the group please email Susan Fischer at susan@clinchportal.com
Thursday, December 11, 2008
Data Warehousing Architecture event in Toronto
For thoses interested in data warehousing architecture or for those who are friends of people who are here is the link to an event in Toronto on December 16, 2008
http://www.tsql.ca/Events/200812DataWarehouseArchitecture/tabid/723/Default.aspx
We look forward to seeing you there. We will be hanging out with Susan Fischer.
She is so supportive of us even though she doesn't understand any of these technologies.