Senior SQL DBA Microsoft Certified Master: SQL Server · Smallest Log File Size can be 512KB on...

15
16/11/2011 1 Chirag Roy – Senior SQL DBA Microsoft Certified Master: SQL Server http://sqlking.wordpress.com http://www.twitter.com/chiragroy Transaction Log Architecture Design Options for Performance Hardware Options for Performance Transaction Log Troubleshooting Summary

Transcript of Senior SQL DBA Microsoft Certified Master: SQL Server · Smallest Log File Size can be 512KB on...

Page 1: Senior SQL DBA Microsoft Certified Master: SQL Server · Smallest Log File Size can be 512KB on creation VLF Sizing should be carefully planned according to ... Increases database

16/11/2011

1

Chirag Roy – Senior SQL DBA

Microsoft Certified Master: SQL Server

http://sqlking.wordpress.com

http://www.twitter.com/chiragroy

Transaction Log Architecture

Design Options for Performance

Hardware Options for Performance

Transaction Log Troubleshooting

Summary

Page 2: Senior SQL DBA Microsoft Certified Master: SQL Server · Smallest Log File Size can be 512KB on creation VLF Sizing should be carefully planned according to ... Increases database

16/11/2011

2

Physical/Logical Architecture

* http://msdn.microsoft.com/en-us/library/ms179355.aspx

VLF1 VLF2 VLF3 VLF4 VLF5

Virtual Log Files

Logical Log File

Page 3: Senior SQL DBA Microsoft Certified Master: SQL Server · Smallest Log File Size can be 512KB on creation VLF Sizing should be carefully planned according to ... Increases database

16/11/2011

3

Check T-LOG VLFs

DBCC LOGINFO

Tools to Check T-LOG -

DBCC SQLPERF(LOGSPACE)

Disk Usage Report

Page 4: Senior SQL DBA Microsoft Certified Master: SQL Server · Smallest Log File Size can be 512KB on creation VLF Sizing should be carefully planned according to ... Increases database

16/11/2011

4

Recovery Type Considerations -

Simple Recovery - Log file cleared on checkpoint

Full/Bulk Logged Recovery – Log file cleared on Log Backup

Bulk Logged Recovery

Potentially Larger Log Backups when running - • ALTER INDEX REORGANIZE

• DBCC INDEXDEFRAG

Page 5: Senior SQL DBA Microsoft Certified Master: SQL Server · Smallest Log File Size can be 512KB on creation VLF Sizing should be carefully planned according to ... Increases database

16/11/2011

5

VLF Design

Too few Large VLF’s due to poor design

Too many Small VLF’s in case of Autogrow

Smallest Log File Size can be 512KB on creation

VLF Sizing should be carefully planned according to environment needs

VLF Design

Chunk Size Number of VLFs

<= 1MB 2

>=1MB and < 64MB 4

>=64MB and < 1GB 8

1GB and larger 16

Page 6: Senior SQL DBA Microsoft Certified Master: SQL Server · Smallest Log File Size can be 512KB on creation VLF Sizing should be carefully planned according to ... Increases database

16/11/2011

6

VLF Design Recommendation

If log file designed for VLDBs > 8GB, expand Log File in Increments of 8GB on DB Creation to create 512MB VLFs

If log file designed < 8GB, size Log File as per requirements

Considerations –

Autoshrink – Switch OFF

Autogrowth by %, causes VLF Fragmentation

http://support.microsoft.com/kb/315512

VLF Fragmentation -

Leads to I/O overhead

Affects Redo/Undo phase performance

Increases database recovery/restore time

Cluster Failover Timing

Page 7: Senior SQL DBA Microsoft Certified Master: SQL Server · Smallest Log File Size can be 512KB on creation VLF Sizing should be carefully planned according to ... Increases database

16/11/2011

7

Considerations -

Place Data and Log files on separate LUNS to distribute I/O

Data Files experience Random Read/Writes

Log Files experience Sequential Read/Writes

SAN Admins need to provision LUNS optimized for the type of load

Considerations -

Change Model Database Recovery Mode to Simple

Full Recovery Database in Pseudo Simple Until First Full Backup

Runaway Log file if subsequently no Log backups are taken

Instant File Initialization does not work with Log Files

Page 8: Senior SQL DBA Microsoft Certified Master: SQL Server · Smallest Log File Size can be 512KB on creation VLF Sizing should be carefully planned according to ... Increases database

16/11/2011

8

Check T-LOG Zeroing

TRACE FLAG 3004

Considerations -

Log clearing can be affected by –

Recovery Model

Replication

Database Mirroring

Switch on Backup Compression in SQL 2008/R2

Switch ON Trace Flag 3042 to prevent Backup File pre-allocation

http://support.microsoft.com/kb/2001026

Page 9: Senior SQL DBA Microsoft Certified Master: SQL Server · Smallest Log File Size can be 512KB on creation VLF Sizing should be carefully planned according to ... Increases database

16/11/2011

9

In Large OLTP Environment Size Tempdb data and log file appropriately

Test using Autogrow

Size before going into production

Checkpoint occurs when Log File is 70% Full

Slow Disk I/O can cause delayed checkpoint

Mitigate using Alerts to notify

Manual Checkpoint precedes over System Checkpoint

TempDB - Special Case

Page 10: Senior SQL DBA Microsoft Certified Master: SQL Server · Smallest Log File Size can be 512KB on creation VLF Sizing should be carefully planned according to ... Increases database

16/11/2011

10

SCSI RAID1 SCSI RAID10 NAND based Technology

Read Speed Good Good Excellent

Write Speed Slower Good Excellent

Data Redundancy Good Good Depends!

Cost Affordable Expensive Very

Expensive

Page 11: Senior SQL DBA Microsoft Certified Master: SQL Server · Smallest Log File Size can be 512KB on creation VLF Sizing should be carefully planned according to ... Increases database

16/11/2011

11

Storage

Check the file latency within SQL Server using sys.dm_io_virtual_file_stats (db_id,file_id)

Use this script to get the latency for transaction log: select db_name(database_id),

io_stall_read_ms/num_of_reads AS ‘Avg. Read Wait(ms)',

io_stall_write_ms/num_of_writes AS ‘Avg. Write Wait(ms)'

from sys.dm_io_virtual_file_stats (DB_ID(),2)

ASYNC_IO_COMPLETION Can be for "zeroing" out a transaction log file during log creation or growth

WRITELOG Writing transaction log to disk

LOGBUFFER Indicates worker thread is waiting for a log buffer to write log blocks for a transaction

*http://blogs.msdn.com/psssql/archive/2009/11/03/the-sql-server-wait-type-repository.aspx

Page 12: Senior SQL DBA Microsoft Certified Master: SQL Server · Smallest Log File Size can be 512KB on creation VLF Sizing should be carefully planned according to ... Increases database

16/11/2011

12

sys.dm_os_waiting_tasks Wait information

Task level

Very accurate

Transient data

sys.dm_os_wait_stats Wait information

Cumulative by wait type

Persistent data

Page 13: Senior SQL DBA Microsoft Certified Master: SQL Server · Smallest Log File Size can be 512KB on creation VLF Sizing should be carefully planned according to ... Increases database

16/11/2011

13

Log_reuse_wait_desc in sys.databases

NOTHING

CHECKPOINT

LOG_BACKUP

ACTIVE_BACKUP_OR_RESTORE

ACTIVE_TRANSACTION

DATABASE_MIRRORING

REPLICATION

DATABASE_SNAPSHOT_CREATION

LOG_SCAN

OTHER_TRANSIENT

Page 14: Senior SQL DBA Microsoft Certified Master: SQL Server · Smallest Log File Size can be 512KB on creation VLF Sizing should be carefully planned according to ... Increases database

16/11/2011

14

Page 15: Senior SQL DBA Microsoft Certified Master: SQL Server · Smallest Log File Size can be 512KB on creation VLF Sizing should be carefully planned according to ... Increases database

16/11/2011

15