understanding and controlling transaction logs

30
Understanding and Controlling Transaction Logs Nigel Peter Sammy #sqlinthecity

Upload: red-gate-software

Post on 14-Jun-2015

1.727 views

Category:

Technology


1 download

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 Tools

TRANSCRIPT

Page 1: Understanding and controlling transaction logs

Understanding and Controlling

Transaction Logs

Nigel Peter Sammy

#sqlinthecity

Page 2: Understanding and controlling transaction logs

http://www.nigelpsammy.com

Page 3: Understanding and controlling transaction logs

#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

#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

RELATIONAL DBMS BASICS

Page 6: Understanding and controlling transaction logs

#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

#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

INTRODUCTION TO

TRANSACTION LOGS

Page 9: Understanding and controlling 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.

Page 10: Understanding and controlling transaction logs

#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

#sqlinthecity

How the Transaction Log works

Page 12: Understanding and controlling transaction logs

THE ARCHITECTURE

Page 13: Understanding and controlling transaction logs

#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

#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

#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

#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

#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

#sqlinthecity

Recovery Models

Simple

Bulk Logged

Full

Page 19: Understanding and controlling transaction logs

MANAGING THE

TRANSACTION LOGS

Page 20: Understanding and controlling 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

Page 21: Understanding and controlling transaction logs

#sqlinthecity

DBCC

• DBCC SQLPERF(logspace)

• DBCC SHRINKFILE

• DBCC LOGINFO

• DBCC OPENTRAN

Page 22: Understanding and controlling transaction logs

#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

#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

#sqlinthecity

Demo

DBCC Commands and DMVs

#sqlinthecity

Page 25: Understanding and controlling transaction logs

RED GATE TOOLS

Page 26: Understanding and controlling transaction logs

#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

#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

QUESTIONS

Page 29: Understanding and controlling transaction logs

#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

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