managing log file obesity - art of the dba fal - •sql’s eating habits what is the log and how...

17
Mike Fal - www.mikefal.net MANAGING LOG FILE OBESITY SQL Saturday Sacramento, July 27, 2013

Upload: lynhu

Post on 11-Jun-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Managing Log File Obesity - Art of the DBA Fal - •SQL’s Eating Habits What is the log and how does it work? •Daily Diet How does the log file mange itself? •Eating Healthy

Mike Fal - www.mikefal.net

MANAGING LOG FILE OBESITY SQL Saturday Sacramento, July 27, 2013

Page 2: Managing Log File Obesity - Art of the DBA Fal - •SQL’s Eating Habits What is the log and how does it work? •Daily Diet How does the log file mange itself? •Eating Healthy

Mike Fal - www.mikefal.net

Mike Fal

Page 3: Managing Log File Obesity - Art of the DBA Fal - •SQL’s Eating Habits What is the log and how does it work? •Daily Diet How does the log file mange itself? •Eating Healthy

Mike Fal - www.mikefal.net

Has this ever happened to you?

Page 4: Managing Log File Obesity - Art of the DBA Fal - •SQL’s Eating Habits What is the log and how does it work? •Daily Diet How does the log file mange itself? •Eating Healthy

Mike Fal - www.mikefal.net

Has this ever happened to you?

Page 5: Managing Log File Obesity - Art of the DBA Fal - •SQL’s Eating Habits What is the log and how does it work? •Daily Diet How does the log file mange itself? •Eating Healthy

Mike Fal - www.mikefal.net

• SQL’s Eating Habits What is the log and how does it work?

• Daily Diet How does the log file mange itself?

• Eating Healthy What can we do to keep our log file the right size?

The Finish Line

Page 6: Managing Log File Obesity - Art of the DBA Fal - •SQL’s Eating Habits What is the log and how does it work? •Daily Diet How does the log file mange itself? •Eating Healthy

Mike Fal - www.mikefal.net

The Big Picture

Data Files

Buffer Pool

Log File

Page 7: Managing Log File Obesity - Art of the DBA Fal - •SQL’s Eating Habits What is the log and how does it work? •Daily Diet How does the log file mange itself? •Eating Healthy

Mike Fal - www.mikefal.net

Where SQL keeps track of its work

Holds on to that until it’s safe to “throw it away”

Includes work that is complete as well as work in progress

What is the log file?

SQL Server’s Scratch Pad

Page 8: Managing Log File Obesity - Art of the DBA Fal - •SQL’s Eating Habits What is the log and how does it work? •Daily Diet How does the log file mange itself? •Eating Healthy

Mike Fal - www.mikefal.net

Recovery

Data

Data

Data

Page 9: Managing Log File Obesity - Art of the DBA Fal - •SQL’s Eating Habits What is the log and how does it work? •Daily Diet How does the log file mange itself? •Eating Healthy

Mike Fal - www.mikefal.net

Recovery Models

Page 10: Managing Log File Obesity - Art of the DBA Fal - •SQL’s Eating Habits What is the log and how does it work? •Daily Diet How does the log file mange itself? •Eating Healthy

Mike Fal - www.mikefal.net

Process that empties certain parts of the log

Occurs based on different factors

– Checkpoint in Simple Recovery

– Log backup after checkpoint in Full or Bulk Logged

Log Truncation

Page 11: Managing Log File Obesity - Art of the DBA Fal - •SQL’s Eating Habits What is the log and how does it work? •Daily Diet How does the log file mange itself? •Eating Healthy

Mike Fal - www.mikefal.net

• Flushes dirty pages to disk from memory • Recovery Interval

– Number of minutes between checkpoints – Default 0 – Automatic, usually once a minute

• Database is – Backed up – Taken offline (also, SQL Service is stopped) – Database files are added or removed

• Log becomes 70% full (SIMPLE only) • CHECKPOINT issued

Checkpoints

Page 12: Managing Log File Obesity - Art of the DBA Fal - •SQL’s Eating Habits What is the log and how does it work? •Daily Diet How does the log file mange itself? •Eating Healthy

Mike Fal - www.mikefal.net

Virtual Log Files (VLFs)

• Segments within the log file

• Unit of log truncation – When a VLF no longer contains active transactions, it

can be truncated

• Created when log file is created or grows, number is determined by how big the file/addition.

• Used in sequential order, round-robin – So having more than one log file doesn’t really help

Right Sized Portions

Page 13: Managing Log File Obesity - Art of the DBA Fal - •SQL’s Eating Habits What is the log and how does it work? •Daily Diet How does the log file mange itself? •Eating Healthy

Mike Fal - www.mikefal.net

As long as a transaction is active, a VLF is active

Open Late

DBCC OPENTRAN sys.dm_tran_active_transactions

Page 14: Managing Log File Obesity - Art of the DBA Fal - •SQL’s Eating Habits What is the log and how does it work? •Daily Diet How does the log file mange itself? •Eating Healthy

Mike Fal - www.mikefal.net

Demo

Page 15: Managing Log File Obesity - Art of the DBA Fal - •SQL’s Eating Habits What is the log and how does it work? •Daily Diet How does the log file mange itself? •Eating Healthy

Mike Fal - www.mikefal.net

• Pre-size log – Mike’s rule of thumb: 1/3rd data file size

– Depends on activity, don’t make it to small

• Avoid eating to much – Batch large INSERTS/UPDATES/DELETES

– Regular log backups (SIMPLE is not always the answer)

– Monitor your behavior and adjust as necessary

• Cleanup after every meal – Close/rollback transactions

Maintaining a Healthy Log

Page 16: Managing Log File Obesity - Art of the DBA Fal - •SQL’s Eating Habits What is the log and how does it work? •Daily Diet How does the log file mange itself? •Eating Healthy

Mike Fal - www.mikefal.net

• MSDN - http://msdn.microsoft.com/en-us/library/ms190925.aspx

• Kimberly Tripp (VLFs) - http://www.sqlskills.com/blogs/kimberly/transaction-log-vlfs-too-many-or-too-few/

Resources

Page 17: Managing Log File Obesity - Art of the DBA Fal - •SQL’s Eating Habits What is the log and how does it work? •Daily Diet How does the log file mange itself? •Eating Healthy

Mike Fal - www.mikefal.net

HUH?

www.mikefal.net

@Mike_Fal

Questions