The Top 5 SQL Server Mistakes Kathi Kellenberger Kathi.Kellenberger@linchpinpeople.com http://auntkathisql.com
Who am I? Data Platform MVP Author Trainer Database Consultant
Agenda Physical resources Configuration Maintenance Plan Index Strategy Queries
Physical Resources: Memory Memory is the air that SQL Server breaths
Data must be in memory to be used by SQL Server Data Cache
What happens if not enough RAM for the next query? Data Cache
What if we need the first table again? Data Cache
How do you know if memory is adequate? Page Life Expectancy *The number of seconds a page is expected to live in memory
PLE Published value is 300. Inadequate for today’s servers. Jonathan Keyhaias’ recommendation for minimum RAM/4 * 300 16 GB = 1,200 minimum Watch for sustained low values Use perfmon to measure \SQLServer:Buffer Manager\Page life expectancy
PLE Example
Configuration: Tempdb Tempdb is the work horse of SQL Server
When is Tempdb Used? Temp tables and table variables live there Sorting Index maintenance (sort in tempdb option) Work tables DBCC CHECKDB Snapshot isolation Others…
Default Tempdb Configuration (pre-2016)
What Happens? Restart Temp tables Temp tables Sorting Sorting DBCC And more… Restart Temp tables Sorting DBCC And more…
How to Fix? ALTER DATABASE [tempdb] MODIFY FILE ( NAME = N'tempdev', SIZE = 8192MB ); --8GB. ALTER DATABASE [tempdb] MODIFY FILE ( NAME = N'templog', SIZE = 1024MB ); --1GB
Option: Turn Off Or Modify File Growth ALTER DATABASE [tempdb] MODIFY FILE ( NAME = N'tempdev', SIZE = 8192MB, FILEGROWTH = 0 ); -- Turn off ALTER DATABASE [tempdb] MODIFY FILE ( NAME = N'templog', SIZE = 1024MB, FILEGRWOTH = 50MB ); -- Set at 50 MB
Ultimate Tempdb Configuration Create one tempdb data file for each core up to 8 of equal size and growth characteristics Place files on separate drives Place files on fastest storage Startup trace flags 1117 and 1118 (pre-2016)
Maintenance Plan: Shrinking Files Why is it even an option???
The Maintenance Plan Wizard
What Happens? Transactions Maintenance Transactions
How to Fix? Step 1
How to Fix? Step 2 Shrinking
Index Strategy Don’t blindly follow SQL Server’s indexing advice
Missing Index Information
Database Engine Tuning Advisor
Database Engine Tuning Advisor
How to Fix?
Queries: Sargability Don’t misuse a perfectly good index
Functions on Columns Cause Scans 1
Functions on Columns Cause Scans 2
How to Fix?
How to Fix?