Sie sind auf Seite 1von 26

01/05/2012

Twitter: @christianbolton

christian@coeo.com

Christian Bolton Technical Director


Microsoft Certified Architect Microsoft Certified Master MVP

http://sqlblogcasts.com/blogs/christian

01/05/2012

Introduced in SQL Server 2008 Enterprise Edition

Standard Edition feature from 2008 R2


Not enabled by default Use the BACKUP command WITH COMPRESSION Change the default behaviour
sp_configure backup compression default, 1;

Every Edition can restore a compressed backup Calculate your compression ratio with
SELECT backup_size/compressed_backup_size FROM msdb..backupset;

Compression ratios vary but usually 70%-90%

01/05/2012

Helps to prevent plan cache bloat Use of Ad-Hoc T-SQL can make plans difficult to re-use Plan cache fills up with many single use plans

Can cause internal memory pressure as memory is taken away from the data cache

01/05/2012

Optimize for Adhoc Workloads is an instance level option


sp_configure optimize for adhoc workloads, 1;

Only a small execution plan stub is cached on first use The full plan is only cached if its used more than once

sys.dm_exec_cached_plans

01/05/2012

SELECT COUNT(*) AS 'Single Use Plans', SUM(CAST(size_in_bytes AS BIGINT)/1024/1024) AS 'Total Size (MB)' FROM sys.dm_exec_cached_plans WHERE usecounts = 1

This setting should be enabled by default on every instance

01/05/2012

Legacy, deprecated setting SQL Servers threads are started in high priority Can prevent non-SQL Server threads from running

Symptoms include an unresponsive server


Un-planned cluster failovers

Do not use!

01/05/2012

Instant File Initialization The good bits Uses NTFS technology introduced in Win 2003 Skips initializing files with zero Data file creation and expansion VERY fast
Large databases created within seconds Manually expand data files by large amounts Set large data file autogrow amounts Restores will be quicker with large freespace

01/05/2012

Instant File Initialization The bad bits

Isnt used for transaction log files


Old data on disk isnt scrubbed

What is the effect of not using it

01/05/2012

What results does it show when working

When is it enabled? SQL Server service account is a Windows administrator SQL Server is running under LocalSystem SQL Server service account is a local or domain user with the Perform Volume Maintenance Tasks advanced user right
Use gpedit.msc or Group Policy

01/05/2012

How can you be sure SQL Server has permission? whoami /priv

10

01/05/2012

Default Database autogrow values SQL Server autogrows database files by default to keep databases running 1MB by default for data files 10% for transaction log files These defaults are inherited from the Model database

11

01/05/2012

Why might 1MB be bad for data files?

Production databases are usually larger than a few MB If they need to grow then 1MB usually isnt enough for very long
Continuous bursts of autogrow events

Potentially a very fragmented database on disk How about 10% for log files?

Frequent autogrow events

12

01/05/2012

Virtual Log Files Internal structure of the physical .ldf file DBCC LOGINFO returns 1 row for every VLF

13

01/05/2012

How many is too many? Generally, anything in the 100s But it does depend on size
350GB log with 350 VLFs is a good balance

Too few, large VLFs is also bad

Why is it bad? Transaction log backups and restores take a lot longer The recovery process takes longer (database startup) Transactional Replication performance is affected

14

01/05/2012

What causes it? Bad autogrow values Not sizing the log properly How do I fix it? Shrink the log with DBCC SHRINKFILE User ALTER DATABASE to grow it in appropriate chunks

How do I fix it? <64MB = 4 VLFs 64MB-1GB = 8 VLFS >1GB = 16 VLFs Blog post by Kimberly Tripp
http://tinyurl.com/59mo9m

SQL Server 2012 has some changes!

15

01/05/2012

Un-used indexes Still need to be updated Will still be part of your index maintenance How do I know if theyre not being used? Indexes that are not read from but are written to
Except unique indexes

16

01/05/2012

How do I find my un-used indexes? sys.dm_db_index_usage_stats

Join to sys.indexes to get index names Loop through each database to get object names

Un-used indexes script

17

01/05/2012

Un-used indexes output

Unique indexes are harder to check for usage

18

01/05/2012

Auto-Close Database configuration option On by default in SQL Express Takes the database offline after a short period Queries can time-out as the database is starting up again Typically indicates the database has been moved from SQL Express

Auto-Shrink Database configuration option Automatically shrinks the database and log file to remove free space Often leads to a cycle of autogrow and autoshrink every day Turn it off and right-size your database

19

01/05/2012

Max Degree of Parallelism The maximum number of threads to use in a parallel plan

20

01/05/2012

Session Task Thread Scheduler Logical CPU

What can go wrong? Lots of processes running parallel tasks can cause thread starvation
SELECT max_workers_count FROM sys.dm_os_sys_info SELECT count(*) FROM sys.dm_os_workers

Performance is severely affected Look for THREADPOOL waits

21

01/05/2012

How do you resolve it?

Optimize queries to remove parallelism where possible Significantly reduce Max Degree of Parallelism to allow more simultaneous executions Raise the cost threshold for parallelism from the default of 5
Can be useful to only focus on more expensive plans

22

01/05/2012

Default sizing

Number of database files

Physical Properties
tempdev primary data templog log Tempdb.mdf Templog.ldf 8.0 MB 1 MB SQL Server is restarted

DBA sets the tempdb size appropriately

Operations in tempdb cause database to autogrow

Initial State tempdev 8.0 MB templog 1 MB

DBA set State tempdev 2 GB templog 500 MB

Working State tempdev 10 GB templog 2 GB

After Restart State tempdev 2 GB templog 500 MB

23

01/05/2012

Size your tempdb properly Its hard to say how much is enough
Usually GBs

Put it on its own disk and fill it if you can

Multiple data files


Why?
Reduce allocation page contention Increase throughput of tempdb

24

01/05/2012

Allocation Contention
TEMPDB
PFS 64MB SGAM 4GB SGAM PFS

How do you know if you have contention?


SELECT * FROM sys.dm_os_waiting_tasks

25

01/05/2012

Reducing Allocation Contention More data files!


One set of allocation pages per file All the files are equal size
Proportional fill algorithm balances the load

How many files?


1 per logical CPU up to 8 More than 8 when latch contention is still an issue 8 is the sweet spot

26

Das könnte Ihnen auch gefallen