I've mentioned a set of DMV queries that I use in a previous post on this blog. I've been chopping and changing the base set of queries for quite a while to suit my needs.
I have also written a series of posts describing how to perform index and statistics maintenance on a SQL Server's databases without losing the very important index stats that the queries mentioned above return.
So, in this post I will show you how I've modified a few of the index focused DMV queries to include the maintenance tables where I now store the cumulative index statistics.
I'm keeping this blog as a repository for SQL tips and tricks I have learned over my time working with SQL Server.
Showing posts with label index maintenance. Show all posts
Showing posts with label index maintenance. Show all posts
Sunday, 18 August 2013
Wednesday, 7 August 2013
Defragging Indexes Without Losing Index Stats - Part 5
The stored procedure
/*********************************************************************************
UPDATE: Bug fixes and increased FILLFACTOR control!
*********************************************************************************/
The first 4 posts of this series covered the concepts of recording index usage statistics for performance tuning while continuing to maintain a database’s tables and indexes. They also presented the individual SQL scripts to perform the various parts of that process. The most recent post put all of those scripts together into a single set of queries that could be run on a single database.
UPDATE: Bug fixes and increased FILLFACTOR control!
*********************************************************************************/
The first 4 posts of this series covered the concepts of recording index usage statistics for performance tuning while continuing to maintain a database’s tables and indexes. They also presented the individual SQL scripts to perform the various parts of that process. The most recent post put all of those scripts together into a single set of queries that could be run on a single database.
Most of us, however, have more than one database on a SQL
Server instance. Therefore, deploying that last script on a large number of
databases is a bit messy. Any modifications will be difficult to manage.
In this post I will present a sample execute statement to
run the stored procedure. It is designed to be run centrally, and will loop
through all the databases in the instance (there is a parameter to
include/exclude the system databases). I deployed the SP onto my Admin_DB where
I also store the tables that keep the index usage statistics and table
maintenance history.
Tuesday, 4 June 2013
Defragging Indexes Without Losing Index Stats - Part 4
Generate UPDATE STATISTICS scripts
In the previous post of this series I provided the script that both determines the indexes that need attention and builds the individual ALTER INDEX scripts. So, now that the indexes have been tended to it’s time to do the same for table and index statistics.The update statements created are based on the defrag type carried out on the table as well as a few thresholds to determine whether it is necessary to rebuild the statistics. Those thresholds are:
- (Time passed since last update: >3 days
- And Minimum row count of the table: >=1000 rows
- And Percentage change in number of rows: >20% more or less)
- Or Time passed since last update: >30 days
Script out the indexes in a database
I'm just about to begin a big performance improvement project. I'll be starting with an evaluation of indexes. This will involve synchronizing a development environment's indexes with those that are in live. I need to, however, keep a record of the existing indexes on that dev environment.
So I've written the code below. It will return a table with the object_id, table name, index name, index_id and a create index script. This script includes the drop and create statements for both primary keys and unique constraints. There are quite a few good scripts out in the wider web world, but I needed a few specific things so I just wrote my own.
So I've written the code below. It will return a table with the object_id, table name, index name, index_id and a create index script. This script includes the drop and create statements for both primary keys and unique constraints. There are quite a few good scripts out in the wider web world, but I needed a few specific things so I just wrote my own.
Thursday, 23 May 2013
Defragging Indexes Without Losing Index Stats - Part 3
In Part 1 and Part 2 of this series I discussed synchronizing index maintenance and index usage statistics logging as an important part of a DBA's performance tuning routine and the script for saving a database's index usage statistics. This part of the series will go into the query that both identifies the indexes that are fragmented and dynamically generates the defrag scripts.
Wednesday, 22 May 2013
Defragging Indexes Without Losing Index Stats - Part 2
In my last post, I introduced the concept of synchronizing index maintenance and index usage statistics logging as an important part of a DBA's performance tuning routine. In this post I will start delving into the individual scripts involved.
UPDATE: The full script (see link at end of post) has been both updated and tested (a bit)
I've also augmented the script below to clean up the atblIndexUsageStats table.
UPDATE: The full script (see link at end of post) has been both updated and tested (a bit)
I've also augmented the script below to clean up the atblIndexUsageStats table.
As a recap, below are the main steps involved:
- Log Index usage stats
- Determine which indexes need defragging and generate scripts
- Generate update statistics scripts based on step 2
- Log defrag operation to maintenance history table
- Execute defrag and update stats scripts
- Cleanup logging tables (optional)
Sunday, 12 May 2013
Defragging Indexes Without Losing Index Stats - Part 1
Introduction
As part of my regular
performance tuning and maintenance schedule I rely heavily on queries that
interrogate the DMV sys.dm_db_index_usage_stats. Based on this DMV I can judge
whether indexes should be removed, modified or left as they are. See my previous blog post on SQL Server DMVs. I also believe in the regular defragging
of indexes in a database (although I recently read a post from Brent Ozar challenging
this idea, but if your servers don’t have the RAM required for such caching as
his article suggests and/or you'll never get the budget to upgrade, you’ll need to keep reading).
Subscribe to:
Posts (Atom)