There’s just so much to do to get your systems to run in an optimal fashion, but where do you start. This session will walk you through an extensive checklist of things you can do to better manage your servers, databases and code. We’ll start with server configurations and what you can do with them. We’ll then move through standard administrative tasks that will help with performance. Then it’s off to the intricacies of database design and how that can affect performance. We’ll finish up with T-SQL and where it can hurt or help your systems. Get your own systems to run faster with the information you’ll receive.
5. Grant Fritchey | www.ScaryDBA.com
Remember
This is focused on performance tuning
5
6. Grant Fritchey | www.ScaryDBA.com
Remember
This is focused on performance tuning
6
There are always exceptions
7. Grant Fritchey | www.ScaryDBA.com
Remember
This is focused on performance tuning
There are always exceptions
7
Your hardware may be DIFFERENT
8. Grant Fritchey | www.ScaryDBA.com
Remember
This is focused on performance tuning
There are always exceptions
Your hardware may be different
8
Did I mention test?
9. Grant Fritchey | www.ScaryDBA.com
Remember
This is focused on performance tuning
There are always exceptions
Your hardware may be different
Did I mention test?
9
In
cre
men
tal changes
10. Grant Fritchey | www.ScaryDBA.com
Remember
This is focused on performance tuning
There are always exceptions
Your hardware may be different
Did I mention test?
Incremental changes
10
onitoryour servers
11. Grant Fritchey | www.ScaryDBA.com
Remember
This is focused on performance tuning
There are always exceptions
Your hardware may be different
Did I mention test?
Incremental changes
Monitor your servers
11
I am NOT a systems expert
12. Grant Fritchey | www.ScaryDBA.com
Remember
This is focused on performance tuning
There are always exceptions
Your hardware may be different
Did I mention test?
Incremental changes
Monitor your servers
I am not a systems expert
12
You might want toTEST
13. Grant Fritchey | www.ScaryDBA.com
Remember
This is focused on performance tuning
There are always exceptions
Your hardware may be different
Did I mention test?
Incremental changes
Monitor your servers
I am not a systems expert
You might want to test
13
14. Grant Fritchey | www.ScaryDBA.com
Server Configuration
14
Memory CPU Disks
15. Grant Fritchey | www.ScaryDBA.com
SQL Server Configuration:
Memory
>4g enable AWE
» On 2008R2 or less
» On 32-bit systems
Dynamic
» but set a minimum and a maximum value
Optimize for Ad HocWorkloads
» Enable on all servers
15
16. Grant Fritchey | www.ScaryDBA.com
SQL Server Configuration:
CPU
CostThreshold for parallelism
» 5, the default, is too low
» OLTP = 40
» Reporting = 25
Max Degree of Parallelism
» Leave it on, after you change the cost threshold
Consider using Query Governor
» Set a cost limit
16
17. Grant Fritchey | www.ScaryDBA.com
SQL Server Configuration:
Storage
TEMPDB
» Separate from other data when possible
» Multiple Files
— Not equal to #of processors
— Equal sized files
Compression
» Minimum, index compression
More disks is better
» But only if you have more controllers
Spend money
» Buy faster disks
17
18. Grant Fritchey | www.ScaryDBA.com
SQL Server
Administration
Maintain Statistics
» Enable AUTO_CREATE & AUTO_UPDATE
» You must also plan for manual updates
» You may need FULL SCAN
» Consider ASYNC
Defragment your indexes
» Number of pages does matter
» You can defrag below 1000 pages
» You can’t defrag below 8 pages
» Separate defrag & statistics updates
18
19. Grant Fritchey | www.ScaryDBA.com
SQL Server
Administration 2
Avoid dangerous settings
» Disable AUTO_CLOSE
» Disable AUTO_SHRINK
Do not use the Profiler GUI on production systems
» Create a server-side trace usingTSQL scripts
(prior to 2008)
» Use extended events
— Consider for 2008 or better
— Absolutely for 2012 or better
Set Blocked ProcessThreshold
» Based on your system
19
21. Grant Fritchey | www.ScaryDBA.com
Database Design: Storage
Separate Log & Data
Multiple File Groups
» Even on a single drive
Turn off auto-grow
» If not possible, used fixed growth, not percentage
Consider In-Memory
» 2014 only
» I/O Latch waits
21
22. Grant Fritchey | www.ScaryDBA.com
Database Design:
Constraints
Normalize your Data
» Normalization benefits performance
Enforce Constraints
» Foreign keys
» Primary keys
» Unique values
22
23. Grant Fritchey | www.ScaryDBA.com
Database Design: Indexes -
General
Narrow
» As narrow as possible
Integers
» Believe it or not, they’re better
Choose leading edge carefully
» Most selective column
Covering Indexes are fastest
» Use INCLUDE
23
24. Grant Fritchey | www.ScaryDBA.com
Database Design: Indexes -
Clustered
Again, Narrow
» As narrow as possible
Design around the clustered index
» Most frequent used path to data
Rebuilding clustered index
» Use DROP_EXISTING
Avoid columns that get updated frequently
» This means all non-clustered indexes are updated
too
24
25. Grant Fritchey | www.ScaryDBA.com
TSQL Coding
Return only the data you need, when you need it
Use stored procedures or parameterized queries
» Encourages plan reuse
» Prevents SQL Injection
Avoid cursors,WHILE, LOOP
» Row By Agonizing Row style processing
Qualify all object names
» Reduces lookup costs
Avoid using ‘sp_*’ for procedure names
» Eliminates additional read to the master database
25
26. Grant Fritchey | www.ScaryDBA.com
TSQL Coding 2
Avoid nonsargeable conditions
» Meaning functions on columns
» Or, using LIKE ‘%Anything’
Use SET NOCOUNT ON
» Reduces returns on network
Do not nest views
» Or join them. It confuses the optimizer
Don’t use optimizer hints
» More often than not it causes problems
» Especially NOLOCK
26
27. Grant Fritchey | www.ScaryDBA.com
TSQL Coding 3
Avoid Recompiling Execution Plans
» Stored procedures & parameterized queries
» Table variables instead of temp tables
» ANSI standards on connection settings
— And Don’t change them within a query
» Don’t interleave DDL & DML
Adopt best practices for transactions
» Keep scope as short as possible
» Use SET XACT_ABORT
» Consider using READ COMMITTED SNAPSHOT
27
28. Grant Fritchey | www.ScaryDBA.com
Relax
It’s not that bad
Most things can be changed
Help is available
Test everything
28