There are quite a lot of great tools and queries available to the DBA that aid in troubleshooting and performance tuning. The list is incredibly long, but I mainly use RedGate's SQL Monitor (which has come on in the last 5 years in leaps and bounds), Glenn Berry's DMV queries, Adam Machanic's sp_whoisactive and Brent Ozar Unlimited's sp_Blitz suite (predominantly sp_Blitz and sp_BlitzIndex). In writing this, I see that Brent Ozar has expanded his offering, so it looks like I have a weekend project ahead of me!
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 performance. Show all posts
Showing posts with label performance. Show all posts
Friday, 19 January 2018
Tuesday, 2 January 2018
SQL 2016 Database Scoped Configuration: MAXDOP
SQL Server 2016 Microsoft expanded the range and flexibility of database level configuration settings. There are some new features, as well as features which that can be set at more than just the server or database scope. Now, among other things, we are able to:
- set certain options both at the instance and the database level (MAXDOP)
- set instance level trace flag settings at the database level (LEGACY_CARDINALITY_ESTIMATION)
- the Trace Flag 1117 is now set at the FILEGROUP LEVEL
- the brand new database level CLEAR PROCEDURE_CACHE
A summary of the new options can be found on the Technet blog.
In this post I am going to focus on the MAXDOP feature. Having read a few articles and posts about this feature it wasn't clear to me exactly how this feature worked. Especially in regard to the relationship between the instance level setting and the database level setting.
In this post I am going to focus on the MAXDOP feature. Having read a few articles and posts about this feature it wasn't clear to me exactly how this feature worked. Especially in regard to the relationship between the instance level setting and the database level setting.
Wednesday, 25 November 2015
Script to Alter File Growth
I recently inherited a large estate of SQL Servers. Over the years, before I started, it grew organically and was managed by an insufficient number of accidental DBAs. As a result many SQL server instances were built and left with their default settings.
One such setting is file growth, which, tends to be set either at a growth rate of 10% or 1MB. Given the number of databases that can be on a single server I wrote a little script to aid me in making the changes.
I realise that every server and database has different requirements. I am using this script to get my databases and servers to a basic level of "best practice" and avoid any performance issues that may arise.
One such setting is file growth, which, tends to be set either at a growth rate of 10% or 1MB. Given the number of databases that can be on a single server I wrote a little script to aid me in making the changes.
I realise that every server and database has different requirements. I am using this script to get my databases and servers to a basic level of "best practice" and avoid any performance issues that may arise.
Thursday, 30 April 2015
Tracking Query Plan Changes
I was reading a blog post from Brent Ozar (SQL Server Query Store), which detailed Microsoft's announced future feature in SQL Server that aims to store a history of cached execution plans. The main purpose, it seems, of such a feature is to aid in performance troubleshooting and tuning. If something has changed recently and a query or store procedure begins behaving badly, there will be another tool in the DBA toolbelt to aid in finding what happened. Beyond that I'll let others explain it further.
Friday, 17 April 2015
Tracking Page Splits
As a DBA, performance tuning is a regular ongoing task. In my experience it is both a reactive and proactive task. The goal, though, is for your proactive efforts to minimise the time spent on the reactive. This has lead me to focus more on page splitting and index fill factor. Specifically, their interaction. There is a lot of information on the web about the benefits and dangers of fill factor and the performance implications of high rates of page splitting, so I will not go into it too much. I will discuss what I've done to monitor page splits. I then tweak fillfactor on the worst offending tables and indexes.
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).
Monday, 18 March 2013
SQL Server 2005+ Performance Tuning - Part 2
In my last post I covered the reasons for poor performance and the ways of pinpointing performance bottlenecks.
In this post I will detail some of the ways of resolving those performance bottlenecks.
Thursday, 14 March 2013
SQL Server 2005+ Performance Tuning - Part 1
Subscribe to:
Posts (Atom)