Download presentation
Presentation is loading. Please wait.
1
SQL Server Performance Tuning
2
Presenter: Jim Steiner
Company: Rackspace Experience: 21 years in IT, 18 with SQL Server Versions: 6.5 – 2016 President of SALSSA since Dec. 2005
3
Information gathered from:
Ten years at Rackspace 8 other DBAs with a total of over 100 years experience Nine datacenters in 4 countries Over 10,000 SQL Instances It still ‘depends’ on your environment
4
Max Memory On a 64-bit box SQL MUST have a max memory setting. Otherwise SQL could take almost all of the memory on the box and starve out the OS. If lock pages in memory is not set the OS might steal memory from SQL causing a performance issue. If you have a lot of CLR, SSIS or other non SQL items running on the server you might have to adjust the max memory setting even lower. Changing the value can cause a cache flush
5
Max Memory Starting guidelines: Total memory Max Memory 6 16 12 28 58
28 58
6
Max Memory Demo – GUI and sp_configure
7
Optimize for Ad Hoc The server option optimize for ad hoc workloads is turned off by default. This option is used to improve the efficiency of the plan cache for workloads that contain many single use ad hoc batches. When this option is set to 1, the Database Engine stores a small compiled plan stub in the plan cache (352 bytes) when a batch is compiled for the first time, instead of the full compiled plan. Setting the optimize for ad hoc workloads to true affects only new plans; plans that are already in the plan cache are unaffected.
8
Optimize for Ad Hoc Demo – sp_configure Demo – query to see cache size
9
CLR Setting If you’re not using it, you should turn this option off, as it consumes memory even if unused and is a possible attack vector. By default it is off on install It can be changed with sp_configure (0 off, 1 on)
10
Priority Boost Setting
This setting should be off; with it enabled, it’s possible for SQL server to consume all resources and not allow other processes time, including authentication. The only time is should be on is if Microsoft directs it while running a trouble shooting case with them. I have opened at least 100 cases and they have never asked me to turn it on. It can cause unexplainable performance issues. This is one of the few system settings that still take a restart to take effect. Can be turned on and off with GUI and sp_configure
11
Priority Boost Setting
Demo – GUI setting
12
Max Degree of Parallelism
Determines the number of cores to run queries against if the exceed the max threshold for parallelism By default this value is 0 – use all cores For multi proc boxes is should be set to the total number of cores per proc. Further information:
13
Max Degree of Parallelism
This value can be changed at any time Demo – GUI (can be done with sp_configure)
14
SQL Server Version Check
Each new version ‘should’ bring a performance increase even on the same hardware. Make sure the most recent SQL Server service pack is applied. I like to wait till about a month after it is released before applying to see if there are any major issues reported. My favorite site for patch releases:
15
SQL Server Version Check
There are many ways to see the version number. It will show in the tag line of the registered box in SSMS. SQL Server Error log Select SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY ('productlevel'), SERVERPROPERTY ('edition')
16
SQL Server Version Check
Starting with SQL Server 2008, you can also use the Installed SQL Server Features Discovery report. Demo of each method
17
Compress Backup Option
Starting in SQL Server 2008 Enterprise Edition automatic backup compression became available. This feature was added to the Standard Edition in 2008 R2 and future releases. You can get up to about 1/6th the current size of your current backup files. This is highly dependent on data types and repeated data.
18
Compress Backup Option
This will allow the backups and restores to run faster and the backups to use less space. The trade off is it will use more CPU. The amount will vary so you will need to test. There is a system level setting for this. It can also be done with tsql. Demo – system setting, plans and tsql
19
Database Default Growth Rate
For versions 2005 to 2014 the default growth rate for data files is 1mb. In 2016 it was changed to 64mb. This causes a lot of fragmentation and slow performance on large inserts. A rate such as 10% for small DBs and 250mb for large DBs (10 gigs or more) would be better. This can be changed at any time.
20
Database Default Growth Rate
Demo – Gui and script
21
Autogrowth It is recommended you do not put a limit on the data or log files sizes our you risk down time. Instead monitor the free space on the drive. Demo – GUI plus xp_fixeddrives
22
Autoshrink Do NOT use this setting!
If is set a background process runs on a regular basis and shrinks the files if they are beyond the default growth rate. Space is only removed from the end of the file. This will cause major performance issues. If a shrink is needed it should be done one time manually. Free space in the DB is a good thing.
23
Autoclose Do NOT use this setting.
It is left over from very early versions of SQL where RAM was in measured in MB. If there are no open connections on the DB then it is closed. The saves a tiny amount of RAM.
24
Autoclose There are serval bad side effects:
The RAM for the DB is flushed. All data from RAM and cached plans are removed There is a delay on the next query run as the DB must be opened first. From SQL 2008 on it is possible to open just the data file on the DB. Occasionally something will be touching the log file as the DB is opened so only the data file is brought on line making the DB read only. This is only fixable by manual interaction.
25
Autoclose and Autoshrink
Demo - GUI
26
Compatibility Mode If you upgrade SQL or import an old DB backup to a newer version the mode stays in the old version. This can be changed at any time but should be tested first. Demo - GUI
27
Recovery model Any DB that is production and not read only data should be set to ‘full’ recovery mode. All DBs in full recovery mode must have regular log backups taken. This is the only thing that will clear the log. If log backups are not taken you risk data loss and filling up the drive as the log files will continue to grow.
28
Recovery Model The time between log backups is the worst case scenario for amount of data loss. Automated jobs to backup the logs should be taken to backup the logs and remove old backups after a certain amount of time. Demo – maintenance plan log backups
29
Separate I/O Paths When ever possible the data files, log files and tempdb should be on different drives. Data files are random reads/writes and log files are sequential. The tempdb can be the busiest DB on the server. Demo – I/O file break down
30
Needed Jobs Integrity Check – You should be checking the integrity of your databases at least once a week, preferably daily and before taking database backups. This helps ensure that a valid restore can be done. Index and statistics maintenance – The default maintenance steps touch every index which is over kill and bloats the logs. The scripts at the following site examine the fragmentation to decide what action to take.
31
Needed jobs http://ola.hallengren.com/
Backup jobs - It’s important to have some kind of backup strategy for both your system databases and your user databases, so that you can ensure recoverability in the event of a disaster.
32
Missing Index DMV This is a good tool, but do not add the indexes without a lot of examination. Only add ones with a high improvement measure. Combine where possible to each other and existing indexes. Be careful with large include lists or large data types. Occasionally it will recommend already existing indexes. This was fixed in SQL 2012
33
Missing Index DMV Demo
34
Unused Indexes The DMV sys.dm_db_index_usage_stats will show how many times since engine startup that an index has been used versus how many times it has been updated. If the updates far outweigh the usage then you should consider removing the index. Be careful with this DMV is memory pressure or a manual cache flush will clear it.
35
Unused Indexes Demo
36
Duplicate Indexes Look out for indexes that are exactly the same, differ only in the include columns or are the same index just a different order. Demo
37
Remove Hypothetical Indexes
If the Tuning Advisor is stopped during a run it can leave behind hypothetical indexes. These can cause performance issues as the system will try and use them like a real index. Demo
38
Tempdb Setup You should have one data file per core up to 8 to avoid contention in the tempdb. This will assist on servers where a large amount of temp tables are used. In 2016 this can be done on install. Only add more than 8 files on large systems in there is still contention in the GAM, SGAM and PFS pages. All files should have the same growth rate and initial size so they are evenly used. Do not add more files than cores.
39
Tempdb Setup Demo – add additional files
Demo – look for further contention
40
Transaction Log Size and VLFs
Generally, we expect to see the transaction log file to be sized between 10-25% of the data file size. There should not be a high number of VLFs. Fixing this does not require a restart, but it should occur during a less busy time.
41
Transaction Log Size and VLFs
Demo – dbcc loginfo
42
CXPACKET Waits
43
Power Plan Setting Starting with Windows 2008 the CPU on servers by default is set to balanced. This will lower power consumption and server temperature. The issue is it can throttle the CPU by as much as 50%. You can use a free tool to see the effect: CPU-Z More info from Brent Ozar:
44
Power Plan Settings Demo
45
Hard Drive Fragmentation
Disk defragmentation at the disk level can cause performance issues. In order to defrag a drive SQL database files are on you need to stop the service unless you use a third party tool.
46
Profile Trace This is a great tool for finding the longest running and most run queries. Always run it from your desktop or passive cluster server when available. Do not run it on a server if the CPU is above 90%. It can cause the server to lock up. Consider using extended events instead.
47
Profile Trace Demo
48
Tuning Advisor Demo
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.