interrogating the transaction log
DESCRIPTION
Or, The Transaction Log: Why You Can’t Run Your Database Without It. Interrogating the Transaction Log. What We’ll Cover. ACID Properties Transactions Write-ahead Logging Log Space Reservation Reading the Log with fn_dblog Identifying Active Transactions - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Interrogating the Transaction Log](https://reader035.vdocuments.mx/reader035/viewer/2022062305/56816355550346895dd3ff58/html5/thumbnails/1.jpg)
Interrogating the Transaction Log
Or, The Transaction Log: Why You Can’t Run Your Database Without It
![Page 2: Interrogating the Transaction Log](https://reader035.vdocuments.mx/reader035/viewer/2022062305/56816355550346895dd3ff58/html5/thumbnails/2.jpg)
![Page 3: Interrogating the Transaction Log](https://reader035.vdocuments.mx/reader035/viewer/2022062305/56816355550346895dd3ff58/html5/thumbnails/3.jpg)
What We’ll Cover
ACID Properties Transactions Write-ahead Logging Log Space Reservation Reading the Log with fn_dblog Identifying Active Transactions Finding Log Records Associated with
Active Transactions
![Page 4: Interrogating the Transaction Log](https://reader035.vdocuments.mx/reader035/viewer/2022062305/56816355550346895dd3ff58/html5/thumbnails/4.jpg)
Database 101 - ACID Properties Atomicity Consistency Isolation Durability
![Page 5: Interrogating the Transaction Log](https://reader035.vdocuments.mx/reader035/viewer/2022062305/56816355550346895dd3ff58/html5/thumbnails/5.jpg)
Human sacrifice, dogs and cats living together... mass hysteria!
![Page 6: Interrogating the Transaction Log](https://reader035.vdocuments.mx/reader035/viewer/2022062305/56816355550346895dd3ff58/html5/thumbnails/6.jpg)
Transactions and Write-Ahead Logging What is a transaction? Explicit v. Implicit Transactions Write-ahead logging Roll back and roll forward
![Page 7: Interrogating the Transaction Log](https://reader035.vdocuments.mx/reader035/viewer/2022062305/56816355550346895dd3ff58/html5/thumbnails/7.jpg)
Log Space Reservation
SQL Server uses log space for transaction records
Additional space is reserved for potential rollback activity
Committed transaction releases reserved space
![Page 8: Interrogating the Transaction Log](https://reader035.vdocuments.mx/reader035/viewer/2022062305/56816355550346895dd3ff58/html5/thumbnails/8.jpg)
Log Space Reservation Demo SMALLER TRANSACTIONS ARE
BETTER!
![Page 9: Interrogating the Transaction Log](https://reader035.vdocuments.mx/reader035/viewer/2022062305/56816355550346895dd3ff58/html5/thumbnails/9.jpg)
Reading the Transaction Log Table-based function that allows the
transaction log to be read Takes 2 parameters, starting and
ending log sequence numbers (LSN) SELECT * FROM fn_dblog(NULL,NULL)
returns the contents of the log
![Page 10: Interrogating the Transaction Log](https://reader035.vdocuments.mx/reader035/viewer/2022062305/56816355550346895dd3ff58/html5/thumbnails/10.jpg)
fn_dblog demo
![Page 11: Interrogating the Transaction Log](https://reader035.vdocuments.mx/reader035/viewer/2022062305/56816355550346895dd3ff58/html5/thumbnails/11.jpg)
sys.dm_tran_database_transactions Returns information about active
transactions Results contain the begin and end
LSN for each transaction
![Page 12: Interrogating the Transaction Log](https://reader035.vdocuments.mx/reader035/viewer/2022062305/56816355550346895dd3ff58/html5/thumbnails/12.jpg)
Finding Log Records for Active Transactions – Attempt #1
Both the DMV and function contain a transaction_id
The DMV id is hexadecimal and the function id is decimal, so converting one of them should work, right?
![Page 13: Interrogating the Transaction Log](https://reader035.vdocuments.mx/reader035/viewer/2022062305/56816355550346895dd3ff58/html5/thumbnails/13.jpg)
Image Source - http://4.bp.blogspot.com/-DY_k_dCp9EE/TvzOLaf17JI/AAAAAAAABBM/dBff_mOtNws/s1600/wrong+answer.jpg
![Page 14: Interrogating the Transaction Log](https://reader035.vdocuments.mx/reader035/viewer/2022062305/56816355550346895dd3ff58/html5/thumbnails/14.jpg)
Finding Log Records for Active Transactions – Failed Attempt #1
Converting the transaction IDs from either source did not result in a match
After several attempts to make it work (octal, double and add 30, multiply by 9/5 and add 32) I wrote Paul Randal
His response? “They don’t match. It’s annoying.”
![Page 15: Interrogating the Transaction Log](https://reader035.vdocuments.mx/reader035/viewer/2022062305/56816355550346895dd3ff58/html5/thumbnails/15.jpg)
Finding Log Records for Active Transactions – Attempt #2
Both the DMV and the function contain begin and end LSNs
The function returns colon-delimited hex LSNs (0000001a:000027a5:0001)
The DMV returns a decimal value (26000001014900001)