understanding and controlling transaction logs
DESCRIPTION
SQL In The City - Understanding and Controlling Transaction Logs by Nigel Peter Sammy. - Relational DBMS Basics - Introduction to Transaction Logs - The Architecture - Recovery Models - Managing the Transaction Logs - Red Gate ToolsTRANSCRIPT
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
#sqlinthecity
Agenda
– Relational DBMS Basics
– Introduction to Transaction Logs
– The Architecture
– Recovery Models
– Managing the Transaction Logs
– Red Gate Tools
#sqlinthecity
RELATIONAL DBMS BASICS
#sqlinthecity
Transaction
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.
#sqlinthecity
Properties of a Transaction
Atomicity Either all the operations constituting transaction are performed or non them
Consistency Guarantees that the database evolves from one consistent state to another.
Isolation Concurrent transactions behave as though each were the only transaction running in the system
Durability 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.
#sqlinthecity
Purpose of Transaction Logs
Recovery of individual transactions
Recovery of all incomplete transaction
Restore to the point of failure
Supporting replication and various standby server solutions
#sqlinthecity
How the Transaction Log works
THE ARCHITECTURE
#sqlinthecity
Virtual Log Files
VLF 1
USED
VLF 2
UNUSED
VLF 3
UNUSED
VLF 4
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
#sqlinthecity
Virtual Log Files
VLF 1
USED
VLF 2
UNUSED
VLF 3
UNUSED
VLF 4
UNUSED
Transaction 1
Transaction 3
Transaction 2
#sqlinthecity
Virtual Log Files
VLF 1
USED
VLF 2
UNUSED
VLF 3
UNUSED
VLF 4
UNUSED
Transaction 1
Transaction 3
Transaction 2
#sqlinthecity
VLF 1
USED
VLF 2
USED
VLF 3
USED
VLF 4
UNUSED
VLF 1 VLF 2 VLF 3
USED
VLF 4
UNUSED
VLF 5
USED
VLF 2 VLF 3
USED
VLF 4
USED
TRUNCATED
TRUNCATED
Circular Nature of Logs
#sqlinthecity
Transaction logs backup
These backups are important for:
• Enabling point-in-time restore of your database
• Controlling the size of the log file
#sqlinthecity
Recovery Models
Simple
Bulk Logged
Full
MANAGING THE
TRANSACTION LOGS
#sqlinthecity
Transaction Logs Management
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
#sqlinthecity
DBCC
• DBCC SQLPERF(logspace)
• DBCC SHRINKFILE
• DBCC LOGINFO
• DBCC OPENTRAN
#sqlinthecity
Transaction Logs Issues
Excessive File Growth
Full Transaction Log (SQL Server Error 9002)
VLF Fragmentation
No Log File
#sqlinthecity
Transaction Logs Solutions
• 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
#sqlinthecity
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
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
#sqlinthecity