Understanding and Controlling Transaction Logs Nigel Peter Sammy #sqlinthecity
http://www.nigelpsammy.com
#sqlinthecity Managing Expectations This is a 100-300 level session. This session does not cover Tempdb Transaction Log.
#sqlinthecity Agenda Relational DBMS Basics Introduction to Transaction Logs The Architecture Recovery Models Managing the Transaction Logs Red Gate Tools
RELATIONAL DBMS BASICS
Transaction #sqlinthecity Transaction is an action or series of actions carried out by a single user or application that reads and/or updates the contents of a database.
Properties of a Transaction #sqlinthecity Atomicity Consistency Isolation Durability Either all the operations constituting transaction are performed or non them Guarantees that the database evolves from one consistent state to another. Concurrent transactions behave as though each were the only transaction running in the system Committed transactions are guaranteed to be physically performed
INTRODUCTION TO TRANSACTION LOGS
#sqlinthecity The Transaction Log The transaction log is a serial record of all the transactions and the modifications that occurred in a database. Each SQL Server database has at least one transaction log file and generally has the.ldf extension.
Purpose of Transaction Logs #sqlinthecity Recovery of individual transactions Recovery of all incomplete transaction Restore to the point of failure Supporting replication and various standby server solutions
How the Transaction Log works #sqlinthecity
THE ARCHITECTURE
Virtual Log Files #sqlinthecity VLF 1 VLF 2 VLF 3 VLF 4 USED UNUSED UNUSED UNUSED Number of VLFs <64 MB = 4 VLFs 64 MB 1 GB = 8 VLFs >1GB = 16 VLFs Size of VLFs <64 MB = approx. 1/4 size or growth size 64 MB 1 GB = approx. 1/8 size or growth size >1GB = approx. 1/16 size or growth size
Virtual Log Files #sqlinthecity VLF 1 VLF 2 VLF 3 VLF 4 USED UNUSED UNUSED UNUSED Transaction 1 Transaction 2 Transaction 3
Virtual Log Files #sqlinthecity VLF 1 VLF 2 VLF 3 VLF 4 USED UNUSED UNUSED UNUSED Transaction 1 Transaction 2 Transaction 3
Circular Nature of Logs #sqlinthecity VLF 1 VLF 2 VLF 3 VLF 4 USED USED USED UNUSED VLF 1 VLF 2 VLF 3 VLF 4 TRUNCATED USED UNUSED VLF 5 VLF 2 VLF 3 VLF 4 USED TRUNCATED USED USED
#sqlinthecity Transaction logs backup These backups are important for: Enabling point-in-time restore of your database Controlling the size of the log file
Recovery Models #sqlinthecity Simple Bulk Logged Full
MANAGING THE TRANSACTION LOGS
Transaction Logs Management #sqlinthecity Create one log file on a separate disk Create a reasonably sized transaction log Auto-growth is good but Perform Transaction Log backups Monitor, Monitor and of course Monitor
DBCC #sqlinthecity DBCC SQLPERF(logspace) DBCC SHRINKFILE DBCC LOGINFO DBCC OPENTRAN
Transaction Logs Issues #sqlinthecity Excessive File Growth Full Transaction Log (SQL Server Error 9002) VLF Fragmentation No Log File
Transaction Logs Solutions #sqlinthecity Excessive File Growth Truncate the log (log_reuse_wait_desc from sys.database) Full Transaction Log Depends on if your disk is full or auto-growth was not enabled VLF Fragmentation Modify the log file size after truncating and shrinking it No Log File Restore from backup files Log rebuild and repair
#sqlinthecity Demo DBCC Commands and DMVs
RED GATE TOOLS
#sqlinthecity SQL Monitor Red Gate s Performance monitoring and alerting tool Allows users to monitor log file Allows user to monitor disk space Allows users to find long running transactions
#sqlinthecity SQL Backup Pro Improves the performance of your backups and restores considerably. Allows users to easily restore a transaction log to a point in time.
QUESTIONS
#sqlinthecity Extra Resources Blogs and Articles Paul Randall Kimberly L. Tripp Brad McGehee Gail Shaw SQL Server Central
#sqlinthecity Thank you for attending, please complete the online feedback form www.red-gate.com/sitc13-feedback In return you can: - Collect a Red Gate book of your choice from 5PM - Have a chance to win a Conference pass to SQL Server LIVE! 2013, which will be drawn at 5.15PM