Successfully reported this slideshow.

How minimalloggingcanhelpme bartoszratajczyk_sql_sat534

0

Share

Loading in …3
×
1 of 24
1 of 24

More Related Content

Related Books

Free with a 14 day trial from Scribd

See all

How minimalloggingcanhelpme bartoszratajczyk_sql_sat534

  1. 1. How minimal logging can help me? Bartosz Ratajczyk #534 | KRAKÓW 2016
  2. 2. Our Sponsors 11/29/201 6 | Footer Goes Here2 | SQL SATURDAY | #534 | KRAKÓW 2016
  3. 3. Our Partners 11/29/201 6 | Footer Goes Here3 |
  4. 4. The plan • What is minimal logging? • How does it work? (and when?) • What are the profits? (and downsides) • What is efficient logging? • TRUNCATE TABLE logging? SQL SATURDAY | #534 | KRAKÓW 2016
  5. 5. Bartosz Ratajczyk SQL Server consultant Database programmer ETL programmer Database administrator MCSE: Data Platform, MCT, MCTS SQL Server 2008 http://bartekr.net | b.ratajczyk@gmail.com SQL SATURDAY | #534 | KRAKÓW 2016
  6. 6. Transaction log • Keeps track of every data modification in a database • Quantity of information saved in a transaction log may depend on recovery model SQL SATURDAY | #534 | KRAKÓW 2016
  7. 7. Recovery models • FULL • allows point-in-time recovery • requires log management • BULK LOGGED • point-in-time recovery not possible • requires log management • SIMPLE • point-in-time recovery not possible • takes care of log management
  8. 8. Minimal logging „At a minimum, enough information has to be logged when minimally logged operation is performed to allow SQL Server to rollback a transaction that has failed.” Kalen Delaney, SQL Server Internals 2012 „Minimal logging involves logging only the information that is required to recover the transaction without supporting point-in- time recovery.” BOL: https://msdn.microsoft.com/en-us/library/ms191244.aspx SQL SATURDAY | #534 | KRAKÓW 2016
  9. 9. Minimal logging (simplified) • Contains only data alocation information *) • So we save on I/O operations BUT: • Log does not contain all information required to recover lost data • Log backup will contain pages that changed *) well, not exactly SQL SATURDAY | #534 | KRAKÓW 2016
  10. 10. Logging types (simplified) • Full – the operation has its own log record • Efficient – the changed page has its own log record • Minimal – we log only page allocation operations *) *) well, not exactly SQL SATURDAY | #534 | KRAKÓW 2016
  11. 11. Log investigation SELECT * FROM fn_dblog(NULL, NULL) SELECT * FROM fn_dblog(@StartLSN, @EndLSN) SQL SATURDAY | #534 | KRAKÓW 2016
  12. 12. DEMO Minimal logging
  13. 13. What can be minimally logged? • BULK INSERT • bcp • SELECT INTO • INSERT INTO .. SELECT • CREATE INDEX • ALTER INDEX REBUILD, DBCC DBREINDEX • REORGANIZE always fully logged • .WRITE • WRITETEXT, UPDATETEXT DEPRECATED SQL SATURDAY | #534 | KRAKÓW 2016
  14. 14. Requirements summary non-FULL recovery model AND NOT replicated AND ( (Heap AND TABLOCK) OR (B-tree AND empty AND TABLOCK) OR (B-tree AND empty AND TF-610) OR (B-tree AND nonempty AND TF-610 AND NEW key-range) ) Source: Itzik Ben-Gan, http://sqlmag.com/t-sql/minimally-logged-inserts SQL SATURDAY | #534 | KRAKÓW 2016
  15. 15. One more trick If you can’t use TABLOCK then use: EXEC sys.sp_tableoption @TableNamePattern = N’dbo.Table’, @OptionName = ’table lock on bulk load’, @OptionValue = ’ON’ SQL SATURDAY | #534 | KRAKÓW 2016
  16. 16. Pros • Faster transactions and log saving • Smaller I/O SQL SATURDAY | #534 | KRAKÓW 2016
  17. 17. And not pros • Sensitive for data file errors • Requires SIMPLE recovery model or switching between FULL and BULK LOGGED • So we won’t use Mirroring and Availability Groups • But Log Shipping still can work • May require TF 610 – sysadmin • All data pages have to be written to disk before transaction ends SQL SATURDAY | #534 | KRAKÓW 2016
  18. 18. TRUNCATE TABLE • Lightning fast data deletion • Is it logged or not? • Why is it so fast? SQL SATURDAY | #534 | KRAKÓW 2016
  19. 19. DEMO TRUNCATE TABLE
  20. 20. What to remember • Minimal logging is just saving page allocation information in transaction log *) • It makes some operations quick, but is sensitive for data file errors • TRUNCATE is fully logged operation *) well, not exactly SQL SATURDAY | #534 | KRAKÓW 2016
  21. 21. Some things to read • Itzik Ben-Gan „Minimally logged inserts: http://sqlmag.com/t- sql/minimally-logged-inserts • Gail Shaw, Tony Davis „Managing the Log in BULK_LOGGED Recovery Model” http://www.sqlservercentral.com/articles/Stairway+Series/94552/ • Paul Randall „The Myth that DROP and TRUNCATE TABLE are Non-Logged” http://sqlperformance.com/2013/05/sql- performance/drop-truncate-log-myth • Remus Rusanu „How to read and interpret the SQL Server log” http://rusanu.com/2014/03/10/how-to-read-and-interpret-the-sql- server-log/ SQL SATURDAY | #534 | KRAKÓW 2016
  22. 22. Our Sponsors 11/29/201 6 | Footer Goes Here22 | SQL SATURDAY | #534 | KRAKÓW 2016
  23. 23. Our Partners 11/29/201 6 | Footer Goes Here23 |
  24. 24. Bartosz Ratajczyk #534 | KRAKÓW 2016

×