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
![Page 1: Understanding and controlling transaction logs](https://reader033.vdocuments.net/reader033/viewer/2022052621/557d5722d8b42ad14f8b45d9/html5/thumbnails/1.jpg)
Understanding and Controlling
Transaction Logs
Nigel Peter Sammy
#sqlinthecity
![Page 2: Understanding and controlling transaction logs](https://reader033.vdocuments.net/reader033/viewer/2022052621/557d5722d8b42ad14f8b45d9/html5/thumbnails/2.jpg)
http://www.nigelpsammy.com
![Page 3: Understanding and controlling transaction logs](https://reader033.vdocuments.net/reader033/viewer/2022052621/557d5722d8b42ad14f8b45d9/html5/thumbnails/3.jpg)
#sqlinthecity
Managing Expectations
• This is a 100-300 level session.
• This session does not cover Tempdb Transaction
Log.
#sqlinthecity
![Page 4: Understanding and controlling transaction logs](https://reader033.vdocuments.net/reader033/viewer/2022052621/557d5722d8b42ad14f8b45d9/html5/thumbnails/4.jpg)
#sqlinthecity
Agenda
– Relational DBMS Basics
– Introduction to Transaction Logs
– The Architecture
– Recovery Models
– Managing the Transaction Logs
– Red Gate Tools
#sqlinthecity
![Page 5: Understanding and controlling transaction logs](https://reader033.vdocuments.net/reader033/viewer/2022052621/557d5722d8b42ad14f8b45d9/html5/thumbnails/5.jpg)
RELATIONAL DBMS BASICS
![Page 6: Understanding and controlling transaction logs](https://reader033.vdocuments.net/reader033/viewer/2022052621/557d5722d8b42ad14f8b45d9/html5/thumbnails/6.jpg)
#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.
![Page 7: Understanding and controlling transaction logs](https://reader033.vdocuments.net/reader033/viewer/2022052621/557d5722d8b42ad14f8b45d9/html5/thumbnails/7.jpg)
#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
![Page 8: Understanding and controlling transaction logs](https://reader033.vdocuments.net/reader033/viewer/2022052621/557d5722d8b42ad14f8b45d9/html5/thumbnails/8.jpg)
INTRODUCTION TO
TRANSACTION LOGS
![Page 9: Understanding and controlling transaction logs](https://reader033.vdocuments.net/reader033/viewer/2022052621/557d5722d8b42ad14f8b45d9/html5/thumbnails/9.jpg)
#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.
![Page 10: Understanding and controlling transaction logs](https://reader033.vdocuments.net/reader033/viewer/2022052621/557d5722d8b42ad14f8b45d9/html5/thumbnails/10.jpg)
#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
![Page 11: Understanding and controlling transaction logs](https://reader033.vdocuments.net/reader033/viewer/2022052621/557d5722d8b42ad14f8b45d9/html5/thumbnails/11.jpg)
#sqlinthecity
How the Transaction Log works
![Page 12: Understanding and controlling transaction logs](https://reader033.vdocuments.net/reader033/viewer/2022052621/557d5722d8b42ad14f8b45d9/html5/thumbnails/12.jpg)
THE ARCHITECTURE
![Page 13: Understanding and controlling transaction logs](https://reader033.vdocuments.net/reader033/viewer/2022052621/557d5722d8b42ad14f8b45d9/html5/thumbnails/13.jpg)
#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
![Page 14: Understanding and controlling transaction logs](https://reader033.vdocuments.net/reader033/viewer/2022052621/557d5722d8b42ad14f8b45d9/html5/thumbnails/14.jpg)
#sqlinthecity
Virtual Log Files
VLF 1
USED
VLF 2
UNUSED
VLF 3
UNUSED
VLF 4
UNUSED
Transaction 1
Transaction 3
Transaction 2
![Page 15: Understanding and controlling transaction logs](https://reader033.vdocuments.net/reader033/viewer/2022052621/557d5722d8b42ad14f8b45d9/html5/thumbnails/15.jpg)
#sqlinthecity
Virtual Log Files
VLF 1
USED
VLF 2
UNUSED
VLF 3
UNUSED
VLF 4
UNUSED
Transaction 1
Transaction 3
Transaction 2
![Page 16: Understanding and controlling transaction logs](https://reader033.vdocuments.net/reader033/viewer/2022052621/557d5722d8b42ad14f8b45d9/html5/thumbnails/16.jpg)
#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
![Page 17: Understanding and controlling transaction logs](https://reader033.vdocuments.net/reader033/viewer/2022052621/557d5722d8b42ad14f8b45d9/html5/thumbnails/17.jpg)
#sqlinthecity
Transaction logs backup
These backups are important for:
• Enabling point-in-time restore of your database
• Controlling the size of the log file
![Page 18: Understanding and controlling transaction logs](https://reader033.vdocuments.net/reader033/viewer/2022052621/557d5722d8b42ad14f8b45d9/html5/thumbnails/18.jpg)
#sqlinthecity
Recovery Models
Simple
Bulk Logged
Full
![Page 19: Understanding and controlling transaction logs](https://reader033.vdocuments.net/reader033/viewer/2022052621/557d5722d8b42ad14f8b45d9/html5/thumbnails/19.jpg)
MANAGING THE
TRANSACTION LOGS
![Page 20: Understanding and controlling transaction logs](https://reader033.vdocuments.net/reader033/viewer/2022052621/557d5722d8b42ad14f8b45d9/html5/thumbnails/20.jpg)
#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
![Page 21: Understanding and controlling transaction logs](https://reader033.vdocuments.net/reader033/viewer/2022052621/557d5722d8b42ad14f8b45d9/html5/thumbnails/21.jpg)
#sqlinthecity
DBCC
• DBCC SQLPERF(logspace)
• DBCC SHRINKFILE
• DBCC LOGINFO
• DBCC OPENTRAN
![Page 22: Understanding and controlling transaction logs](https://reader033.vdocuments.net/reader033/viewer/2022052621/557d5722d8b42ad14f8b45d9/html5/thumbnails/22.jpg)
#sqlinthecity
Transaction Logs Issues
Excessive File Growth
Full Transaction Log (SQL Server Error 9002)
VLF Fragmentation
No Log File
![Page 23: Understanding and controlling transaction logs](https://reader033.vdocuments.net/reader033/viewer/2022052621/557d5722d8b42ad14f8b45d9/html5/thumbnails/23.jpg)
#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
![Page 24: Understanding and controlling transaction logs](https://reader033.vdocuments.net/reader033/viewer/2022052621/557d5722d8b42ad14f8b45d9/html5/thumbnails/24.jpg)
#sqlinthecity
Demo
DBCC Commands and DMVs
#sqlinthecity
![Page 25: Understanding and controlling transaction logs](https://reader033.vdocuments.net/reader033/viewer/2022052621/557d5722d8b42ad14f8b45d9/html5/thumbnails/25.jpg)
RED GATE TOOLS
![Page 26: Understanding and controlling transaction logs](https://reader033.vdocuments.net/reader033/viewer/2022052621/557d5722d8b42ad14f8b45d9/html5/thumbnails/26.jpg)
#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
![Page 27: Understanding and controlling transaction logs](https://reader033.vdocuments.net/reader033/viewer/2022052621/557d5722d8b42ad14f8b45d9/html5/thumbnails/27.jpg)
#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.
![Page 28: Understanding and controlling transaction logs](https://reader033.vdocuments.net/reader033/viewer/2022052621/557d5722d8b42ad14f8b45d9/html5/thumbnails/28.jpg)
QUESTIONS
![Page 29: Understanding and controlling transaction logs](https://reader033.vdocuments.net/reader033/viewer/2022052621/557d5722d8b42ad14f8b45d9/html5/thumbnails/29.jpg)
#sqlinthecity
Extra Resources
• Blogs and Articles
– Paul Randall
– Kimberly L. Tripp
– Brad McGehee
– Gail Shaw
– SQL Server Central
![Page 30: Understanding and controlling transaction logs](https://reader033.vdocuments.net/reader033/viewer/2022052621/557d5722d8b42ad14f8b45d9/html5/thumbnails/30.jpg)
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