Interrogating the Transaction Log

Slides:



Advertisements
Similar presentations
Transactions generalities 1 Transactions - generalities.
Advertisements

Transactions - Concurrent access & System failures - Properties of Transactions - Isolation Levels 4/13/2015Databases21.
TRANSACTION PROCESSING SYSTEM ROHIT KHOKHER. TRANSACTION RECOVERY TRANSACTION RECOVERY TRANSACTION STATES SERIALIZABILITY CONFLICT SERIALIZABILITY VIEW.
Transaction Processing Lecture ACID 2 phase commit.
Transaction Management and Concurrency Control
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
Chapter 8 : Transaction Management. u Function and importance of transactions. u Properties of transactions. u Concurrency Control – Meaning of serializability.
Database Administration Part 1 Chapter Six CSCI260 Database Applications.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
Transaction Management WXES 2103 Database. Content What is transaction Transaction properties Transaction management with SQL Transaction log DBMS Transaction.
Transaction Management and Concurrency Control
Transactions and Recovery
Transactions and Locks Lesson 22. Skills Matrix Transaction A transaction is a series of steps that perform a logical unit of work. Transactions must.
Managing Transaction and Lock Vu Tuyet Trinh Hanoi University of Technology 1.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 10 Transaction Management.
Chapter 15 Recovery. Topics in this Chapter Transactions Transaction Recovery System Recovery Media Recovery Two-Phase Commit SQL Facilities.
Ch 10: Transaction Management and Concurrent Control.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 136 Database Systems I SQL Modifications and Transactions.
Chapter 15 Recovery. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.15-2 Topics in this Chapter Transactions Transaction Recovery System.
Transactions and Locks A Quick Reference and Summary BIT 275.
Database structure and space Management. Segments The level of logical database storage above an extent is called a segment. A segment is a set of extents.
Chapter 20 Transaction Management Thomas Connolly, Carolyn Begg, Database System, A Practical Approach to Design Implementation and Management, 4 th Edition,
Transaction Log Internals Dharmendra Keshari President - KDSSG.
SQLintersection Understanding Transaction Isolation Levels Randy Knight Wednesday, 3:45-5:00.
1 Intro stored procedures Declaring parameters Using in a sproc Intro to transactions Concurrency control & recovery States of transactions Desirable.
Transactions, Roles & Privileges Oracle and ANSI Standard SQL Lecture 11.
1 Advanced Database Concepts Transaction Management and Concurrency Control.
Module 11: Managing Transactions and Locks
Backup and Recovery - II - Checkpoint - Transaction log – active portion - Database Recovery.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
3 Database Systems: Design, Implementation, and Management CHAPTER 9 Transaction Management and Concurrency Control.
10 1 Chapter 10 - A Transaction Management Database Systems: Design, Implementation, and Management, Rob and Coronel.
In this session, you will learn to: Implement triggers Implement transactions Objectives.
Chapter 13 Managing Transactions and Concurrency Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition.
Locks, Blocks & Isolation Oh My!. About Me Keith Tate Data Professional for over 14 Years MCITP in both DBA and Dev tracks
Oracle 11g: SQL Chapter 5 Data Manipulation and Transaction Control.
MULTIUSER DATABASES : Concurrency and Transaction Management.
CS422 Principles of Database Systems Failure Recovery Chengyu Sun California State University, Los Angeles.
Database Recovery Techniques
DURABILITY OF TRANSACTIONS AND CRASH RECOVERY
CS422 Principles of Database Systems Failure Recovery
Transaction Log Fundamentals
Transaction Management and Concurrency Control
Transaction Management and Concurrency Control
Isolation Levels Understanding Transaction Temper Tantrums
Database Systems (資料庫系統)
Transactions Properties.
On transactions, and Atomic Operations
Batches, Transactions, & Errors
Chapter 10 Transaction Management and Concurrency Control
SQL SERVER TRANSACTION LOG INSIDE
Transaction Log Fundamentals
Printed on Monday, December 31, 2018 at 2:03 PM.
The PROCESS of Queries John Deardurff Website: ThatAwesomeTrainer.com
Understanding Transaction Isolation Levels
On transactions, and Atomic Operations
Introduction of Week 13 Return assignment 11-1 and 3-1-5
Lecture 13: Transactions in SQL
Lecture 20: Intro to Transactions & Logging II
Transactions and Concurrency
Database Recovery 1 Purpose of Database Recovery
A Beginners Guide to Transactions
STRUCTURE OF PRESENTATION :
A Beginners Guide to Transactions
A Beginners Guide to Transactions
A Beginners Guide to Transactions
Isolation Levels Understanding Transaction Temper Tantrums
A Beginners Guide to Transactions
Lecture 11: Transactions in SQL
Transactions, Properties of Transactions
Presentation transcript:

Interrogating the Transaction Log 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 Finding Log Records Associated with Active Transactions The log file is the most important file in your database and I’ll explain the reasons why in the course of this presentation I’ll also explain how the log file works I will demonstrate methods for looking at the records contained in the transaction log Finally, I’ll show how to identify the log records that are associated with active transactions on the instance

Database 101 - ACID Properties Atomicity Consistency Isolation Durability ACID properties are central to any relational database SQL Server uses the transaction log to adhere to the ACID properties Atomicity – transactions are all or nothing Consistency – Any transaction that modifies the database must leave the data in a consistent state, including triggers and constraints Isolation – No active transaction can affect another transaction; SQL Server uses a combination of transactions and resource locking to achieve isolation Durability – Any committed transaction must be maintained in the database in the event of a system crash

Human sacrifice, dogs and cats living together... mass hysteria! A database that doesn’t adhere to ACID properties gets you… Human sacrifice, dogs and cats living together... mass hysteria!

Transactions and Write-Ahead Logging What is a transaction? Explicit v. Implicit Transactions Write-ahead logging Roll back and roll forward Any activity the modifies the data or schema of a database will be contained in a transaction A block of code can be wrapped in a BEGIN TRANSACTION/COMMIT TRANSACTION, known as an explicit transaction For any statement or series of statements that modify the database not contained in a BEGIN/COMMIT, SQL Server will wrap them in a BEGIN/COMMIT Write-ahead logging guarantees that log records are written to disk prior to the associated data pages If the system crashes prior to the data pages being written, committed transactions will be rolled forward and and uncommitted transactions will be rolled back All transactional activity is recorded in the transaction log

Log Space Reservation SQL Server uses log space for transaction records Additional space is reserved for potential rollback activity Committed transaction releases reserved space To account for the possibility of a transaction roll back, SQL Server reserves space in the transaction log If a transaction rolls back, SQL Server generates an anti-operation for each log record Once a transaction completes, the reserve

Log Space Reservation Demo SMALLER TRANSACTIONS ARE BETTER!

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 fn_dblog is a table-based functions that allows you to select the contents of the transaction log It takes two input parameters, starting and ending lsn numbers Passing NULLs will return the entire contents of the log Passing in lsn values will limit the log records returned The transaction log acts as the stream of consciousness for the database; if you pass in a begin and end lsn, you will return all of the records for that range but may see multiple transactions

fn_dblog demo

sys.dm_tran_database_transactions Returns information about active transactions Results contain the begin and end LSN for each transaction

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?

Image Source - http://4. bp. blogspot

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.”

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)