Presentation is loading. Please wait.

Presentation is loading. Please wait.

Transaction Log Internals and Performance David M Maxwell

Similar presentations


Presentation on theme: "Transaction Log Internals and Performance David M Maxwell"— Presentation transcript:

1 Transaction Log Internals and Performance David M Maxwell
2/23/2019 4:22 PM Transaction Log Internals and Performance David M Maxwell © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

2 Who am I? David M Maxwell Where I’m at: twitter.com/dmmaxwell
2/23/2019 4:22 PM Who am I? David M Maxwell Where I’m at: twitter.com/dmmaxwell dmmaxwell.wordpress.com © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

3 Agenda What’s really in the Transaction Log?
2/23/2019 4:22 PM Agenda What’s really in the Transaction Log? How does SQL Server manage the Log file? Resolving common Transaction Log issues. Performance tuning for the Transaction Log. © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

4 Transaction Log Contents
2/23/2019 4:22 PM Transaction Log Contents By example: an UPDATE statement. Data page is read into Buffer Pool memory. Write-Ahead Logging details the change in the Transaction Log. The page is modified in the Buffer Pool. Not all changes are user-initiated, but all changes are logged. © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

5 Commit vs. Rollback COMMIT TRANSACTION ROLLBACK TRANSACTION
2/23/2019 4:22 PM Commit vs. Rollback COMMIT TRANSACTION A “commit” record is written to the log and the transaction ends. ROLLBACK TRANSACTION “Compensation” and “Abort” records are written to the log. The modified page in the Buffer Pool memory is changed back. Compensation records are roll-forward only. © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

6 2/23/2019 4:22 PM The role of CHECKPOINT CHECKPOINT writes changed (dirty) pages to disk. The transaction does not have to be completed. By default, this happens every 60 seconds. Configuring the CHECKPOINT interval: At the server level: use “Recovery Interval (minutes)” At the database level: use “Target Recovery Time (seconds)” © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

7 Demo: Reading the log contents using fn_dblog(). 2/23/2019 4:22 PM
© 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

8 How SQL manages Transaction Log space.
2/23/2019 4:22 PM How SQL manages Transaction Log space. The log file contains smaller Virtual Log Files (VLFs). The number of VLFs depends on the create or growth size of the Log, and the version of SQL Server. For SQL Server versions 2014 and later, if the growth is less than 1/8 of the current log size, only 1 VLF is created. Create / Growth Size Number of VLFs Created < 64 MB 4 VLFs at 1/4 of the size Between 64 MB and 1 GB 8 VLFs at 1/8 of the size > 1 GB 16 VLFs at 1/16 of the size © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

9 Example of VLF Creation
2/23/2019 4:22 PM Example of VLF Creation Consider a 2GB log file created with 16 VLFs, at 128 MB each. If the log is set to grow 10%... SQL 2012 or earlier will create 8 VLFs at 25 MB each SQL 2014 or later will create 1 VLF at 204 MB If the log is set to grow 1GB… SQL 2012 or earlier will create 8 VLFs at 128 MB each SQL 2014 or later will create 8 VLFs at 128 MB each Note that as this log passes 8GB in size, things change for SQL 2014 and later. © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

10 2/23/2019 4:22 PM How VLFs are used When a transaction begins writing to the log, the VLF containing the information becomes “Active”. The last VLF written to is always active. VLFs become inactive (truncated) when the records are no longer needed. SIMPLE recovery model: CHECKPOINT FULL or BULK_LOGGED recovery models: Log Backup Secondary Truncation Points: Open or Un-Replicated Transactions Availability Group or Mirrored Transactions © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

11 2/23/2019 4:22 PM VLFs in Action © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

12 Demos: Examining VLFs with fn_dblog() and LOGINFO.
2/23/2019 4:22 PM Demos: Examining VLFs with fn_dblog() and LOGINFO. Troubleshooting Common Transaction Log Issues © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

13 Performance Tuning: IO or Workload?
2/23/2019 4:22 PM Performance Tuning: IO or Workload? Examine the Wait Stats against your baseline. Long individual waits? Probably an IO issue. Small but more frequent waits? Probably a change in the workload. IO Tuning Check VLF counts, Fragmentation, Pre-Allocation Random vs. Sequential IO No, I don’t care if you have SSDs. This all still applies.  Workload Tuning Configuring recovery intervals Mitigating page splits. Batching transactions. © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

14 Demo Performance Tuning Methods for the Transaction Log
2/23/2019 4:22 PM Demo Performance Tuning Methods for the Transaction Log © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

15 Summary Understand the roles of COMMIT, ROLLBACK, and CHECKPOINT.
2/23/2019 4:22 PM Summary Understand the roles of COMMIT, ROLLBACK, and CHECKPOINT. Understand how SQL manages VLFs, and how to pre-allocate for transaction log space. Understand what happens when things go wrong, and how to fix them. Understand when to tune for IO or Workload. © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

16 2/23/2019 4:22 PM Resources Microsoft: SQL Server Transaction Log Architecture and Management Guide. SQL Skills: Transaction Log archives (Kimberly Tripp) eBook: SQL Server Transaction Log Management by Tony Davis and Gail Shaw © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

17 2/23/2019 4:22 PM Thanks  Here’s that contact info again: David M Maxwell Where I’m at: twitter.com/dmmaxwell dmmaxwell.wordpress.com © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.


Download ppt "Transaction Log Internals and Performance David M Maxwell"

Similar presentations


Ads by Google