SlideShare a Scribd company logo
1 of 24
How minimal logging
can help me?
Bartosz Ratajczyk
#534 | KRAKÓW 2016
Our Sponsors
11/29/201
6 |
Footer Goes Here2 |
SQL SATURDAY | #534 | KRAKÓW 2016
Our Partners
11/29/201
6 |
Footer Goes Here3 |
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
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
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
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
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
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
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
Log investigation
SELECT *
FROM fn_dblog(NULL, NULL)
SELECT *
FROM fn_dblog(@StartLSN, @EndLSN)
SQL SATURDAY | #534 | KRAKÓW 2016
DEMO
Minimal logging
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
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
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
Pros
• Faster transactions and log saving
• Smaller I/O
SQL SATURDAY | #534 | KRAKÓW 2016
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
TRUNCATE TABLE
• Lightning fast data deletion
• Is it logged or not?
• Why is it so fast?
SQL SATURDAY | #534 | KRAKÓW 2016
DEMO
TRUNCATE TABLE
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
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
Our Sponsors
11/29/201
6 |
Footer Goes Here22 |
SQL SATURDAY | #534 | KRAKÓW 2016
Our Partners
11/29/201
6 |
Footer Goes Here23 |
Bartosz Ratajczyk
#534 | KRAKÓW 2016

More Related Content

What's hot

Icinga Camp San Francisco 2017 - Icinga Director - Managing your configuration
Icinga Camp San Francisco 2017 - Icinga Director - Managing your configurationIcinga Camp San Francisco 2017 - Icinga Director - Managing your configuration
Icinga Camp San Francisco 2017 - Icinga Director - Managing your configuration
Icinga
 

What's hot (20)

Icinga Camp Bangalore - Icinga and Icinga Director
Icinga Camp Bangalore - Icinga and Icinga Director Icinga Camp Bangalore - Icinga and Icinga Director
Icinga Camp Bangalore - Icinga and Icinga Director
 
Icinga Camp Belgrade - Icinga Web 2
Icinga Camp Belgrade - Icinga Web 2Icinga Camp Belgrade - Icinga Web 2
Icinga Camp Belgrade - Icinga Web 2
 
Loadays 2015 - Enterprise Monitoring with Icinga
Loadays 2015 - Enterprise Monitoring with IcingaLoadays 2015 - Enterprise Monitoring with Icinga
Loadays 2015 - Enterprise Monitoring with Icinga
 
Introduction into Icinga Web 2
Introduction into Icinga Web 2Introduction into Icinga Web 2
Introduction into Icinga Web 2
 
The journey of Moving from AWS ELK to GCP Data Pipeline
The journey of Moving from AWS ELK to GCP Data PipelineThe journey of Moving from AWS ELK to GCP Data Pipeline
The journey of Moving from AWS ELK to GCP Data Pipeline
 
WEBridge 4 SAP ( Windchill and SAP Integration)
WEBridge 4 SAP ( Windchill and SAP Integration)WEBridge 4 SAP ( Windchill and SAP Integration)
WEBridge 4 SAP ( Windchill and SAP Integration)
 
Customizing Online Services for a Better Experience
Customizing Online Services for a Better ExperienceCustomizing Online Services for a Better Experience
Customizing Online Services for a Better Experience
 
Sqlwatch presentation 2018-11
Sqlwatch presentation 2018-11Sqlwatch presentation 2018-11
Sqlwatch presentation 2018-11
 
Icinga Web 2 is more
Icinga Web 2 is moreIcinga Web 2 is more
Icinga Web 2 is more
 
IcingaCamp Stockholm - Graphing with Graphite und Grafana
IcingaCamp Stockholm - Graphing with Graphite und GrafanaIcingaCamp Stockholm - Graphing with Graphite und Grafana
IcingaCamp Stockholm - Graphing with Graphite und Grafana
 
Saluki - do it like a user
Saluki - do it like a userSaluki - do it like a user
Saluki - do it like a user
 
Icinga Camp Berlin 2018 - Dev and Ops Stories - Integrations++
Icinga Camp Berlin 2018 - Dev and Ops Stories - Integrations++Icinga Camp Berlin 2018 - Dev and Ops Stories - Integrations++
Icinga Camp Berlin 2018 - Dev and Ops Stories - Integrations++
 
WEBridge 4 EBS ( Windchill and Oracle EBS Integration )
WEBridge 4 EBS ( Windchill and Oracle EBS Integration )WEBridge 4 EBS ( Windchill and Oracle EBS Integration )
WEBridge 4 EBS ( Windchill and Oracle EBS Integration )
 
informatica Online Training Institute in India,USA,UK,Canada.
informatica Online Training Institute in India,USA,UK,Canada.informatica Online Training Institute in India,USA,UK,Canada.
informatica Online Training Institute in India,USA,UK,Canada.
 
Icinga Camp San Francisco 2017 - Icinga Director - Managing your configuration
Icinga Camp San Francisco 2017 - Icinga Director - Managing your configurationIcinga Camp San Francisco 2017 - Icinga Director - Managing your configuration
Icinga Camp San Francisco 2017 - Icinga Director - Managing your configuration
 
Icinga Camp Amsterdam - Icinga Director
Icinga Camp Amsterdam - Icinga DirectorIcinga Camp Amsterdam - Icinga Director
Icinga Camp Amsterdam - Icinga Director
 
Icinga Camp Bangalore - Welcome
Icinga Camp Bangalore - WelcomeIcinga Camp Bangalore - Welcome
Icinga Camp Bangalore - Welcome
 
Icinga Camp San Diego: Apify them all
Icinga Camp San Diego: Apify them allIcinga Camp San Diego: Apify them all
Icinga Camp San Diego: Apify them all
 
June 2018 spc recap visual
June 2018 spc recap visualJune 2018 spc recap visual
June 2018 spc recap visual
 
Core FP Concepts
Core FP ConceptsCore FP Concepts
Core FP Concepts
 

Viewers also liked

Agile Data Warehousing
Agile Data WarehousingAgile Data Warehousing
Agile Data Warehousing
Davide Mauri
 

Viewers also liked (20)

Podstawy ETL z SSIS
Podstawy ETL z SSISPodstawy ETL z SSIS
Podstawy ETL z SSIS
 
Szkolenia i certyfikacjesqlserver2016_plssug99
Szkolenia i certyfikacjesqlserver2016_plssug99Szkolenia i certyfikacjesqlserver2016_plssug99
Szkolenia i certyfikacjesqlserver2016_plssug99
 
SQL Server 2016 JSON
SQL Server 2016 JSONSQL Server 2016 JSON
SQL Server 2016 JSON
 
Azure Machine Learning
Azure Machine LearningAzure Machine Learning
Azure Machine Learning
 
Back to the roots - SQL Server Indexing
Back to the roots - SQL Server IndexingBack to the roots - SQL Server Indexing
Back to the roots - SQL Server Indexing
 
BIML: BI to the next level
BIML: BI to the next levelBIML: BI to the next level
BIML: BI to the next level
 
Azure ML: from basic to integration with custom applications
Azure ML: from basic to integration with custom applicationsAzure ML: from basic to integration with custom applications
Azure ML: from basic to integration with custom applications
 
SSIS Monitoring Deep Dive
SSIS Monitoring Deep DiveSSIS Monitoring Deep Dive
SSIS Monitoring Deep Dive
 
Azure Stream Analytics
Azure Stream AnalyticsAzure Stream Analytics
Azure Stream Analytics
 
Event Hub & Azure Stream Analytics
Event Hub & Azure Stream AnalyticsEvent Hub & Azure Stream Analytics
Event Hub & Azure Stream Analytics
 
SQL Server 2016 What's New For Developers
SQL Server 2016  What's New For DevelopersSQL Server 2016  What's New For Developers
SQL Server 2016 What's New For Developers
 
Datarace: IoT e Big Data (Italian)
Datarace: IoT e Big Data (Italian)Datarace: IoT e Big Data (Italian)
Datarace: IoT e Big Data (Italian)
 
Data juice
Data juiceData juice
Data juice
 
Real Time Power BI
Real Time Power BIReal Time Power BI
Real Time Power BI
 
AzureML - Creating and Using Machine Learning Solutions (Italian)
AzureML - Creating and Using Machine Learning Solutions (Italian)AzureML - Creating and Using Machine Learning Solutions (Italian)
AzureML - Creating and Using Machine Learning Solutions (Italian)
 
Agile Data Warehousing
Agile Data WarehousingAgile Data Warehousing
Agile Data Warehousing
 
Azure Machine Learning (Italian)
Azure Machine Learning (Italian)Azure Machine Learning (Italian)
Azure Machine Learning (Italian)
 
Iris Multi-Class Classifier with Azure ML
Iris Multi-Class Classifier with Azure MLIris Multi-Class Classifier with Azure ML
Iris Multi-Class Classifier with Azure ML
 
Dashboarding with Microsoft: Datazen & Power BI
Dashboarding with Microsoft: Datazen & Power BIDashboarding with Microsoft: Datazen & Power BI
Dashboarding with Microsoft: Datazen & Power BI
 
SQL Server 2016 Temporal Tables
SQL Server 2016 Temporal TablesSQL Server 2016 Temporal Tables
SQL Server 2016 Temporal Tables
 

Similar to How minimalloggingcanhelpme bartoszratajczyk_sql_sat534

COUG_AAbate_Oracle_Database_12c_New_Features
COUG_AAbate_Oracle_Database_12c_New_FeaturesCOUG_AAbate_Oracle_Database_12c_New_Features
COUG_AAbate_Oracle_Database_12c_New_Features
Alfredo Abate
 
Exploring plsql new features best practices september 2013
Exploring plsql new features best practices   september 2013Exploring plsql new features best practices   september 2013
Exploring plsql new features best practices september 2013
Andrejs Vorobjovs
 
Recovery, logging and the transaction log
Recovery, logging and the transaction logRecovery, logging and the transaction log
Recovery, logging and the transaction log
Miroslav Dimitrov
 

Similar to How minimalloggingcanhelpme bartoszratajczyk_sql_sat534 (20)

2016 04 sqlsaturday_transaction_log
2016 04 sqlsaturday_transaction_log2016 04 sqlsaturday_transaction_log
2016 04 sqlsaturday_transaction_log
 
Le novità di sql server 2019
Le novità di sql server 2019Le novità di sql server 2019
Le novità di sql server 2019
 
SQL Server 2022 Programmability & Performance
SQL Server 2022 Programmability & PerformanceSQL Server 2022 Programmability & Performance
SQL Server 2022 Programmability & Performance
 
Fun Things to do with Logical Decoding
Fun Things to do with Logical DecodingFun Things to do with Logical Decoding
Fun Things to do with Logical Decoding
 
MariaDB 10.4 New Features
MariaDB 10.4 New FeaturesMariaDB 10.4 New Features
MariaDB 10.4 New Features
 
Writing Futuristic Workflows in Office 365 SharePoint 2013 2016 on premise
Writing Futuristic Workflows in Office 365 SharePoint 2013 2016 on premiseWriting Futuristic Workflows in Office 365 SharePoint 2013 2016 on premise
Writing Futuristic Workflows in Office 365 SharePoint 2013 2016 on premise
 
COUG_AAbate_Oracle_Database_12c_New_Features
COUG_AAbate_Oracle_Database_12c_New_FeaturesCOUG_AAbate_Oracle_Database_12c_New_Features
COUG_AAbate_Oracle_Database_12c_New_Features
 
KoprowskiT_SQLRelay2014#4_Caerdydd_MaintenancePlansForBeginners
KoprowskiT_SQLRelay2014#4_Caerdydd_MaintenancePlansForBeginnersKoprowskiT_SQLRelay2014#4_Caerdydd_MaintenancePlansForBeginners
KoprowskiT_SQLRelay2014#4_Caerdydd_MaintenancePlansForBeginners
 
Exploring plsql new features best practices september 2013
Exploring plsql new features best practices   september 2013Exploring plsql new features best practices   september 2013
Exploring plsql new features best practices september 2013
 
Recovery, logging and the transaction log
Recovery, logging and the transaction logRecovery, logging and the transaction log
Recovery, logging and the transaction log
 
[JSS2015] AlwaysOn 2016
[JSS2015] AlwaysOn 2016[JSS2015] AlwaysOn 2016
[JSS2015] AlwaysOn 2016
 
Tailor azure log analytics with kusto queries
Tailor azure log analytics with kusto queriesTailor azure log analytics with kusto queries
Tailor azure log analytics with kusto queries
 
Ten query tuning techniques every SQL Server programmer should know
Ten query tuning techniques every SQL Server programmer should knowTen query tuning techniques every SQL Server programmer should know
Ten query tuning techniques every SQL Server programmer should know
 
MySQL 5.6 Replication Webinar
MySQL 5.6 Replication WebinarMySQL 5.6 Replication Webinar
MySQL 5.6 Replication Webinar
 
How to Develop Maintainable Custom Workflows in Office 365 Share Point Online?
How to Develop Maintainable Custom Workflows in Office 365 Share Point Online?How to Develop Maintainable Custom Workflows in Office 365 Share Point Online?
How to Develop Maintainable Custom Workflows in Office 365 Share Point Online?
 
Monitoring sql server
Monitoring sql serverMonitoring sql server
Monitoring sql server
 
M|18 Migrating from Oracle and Handling PL/SQL Stored Procedures
M|18 Migrating from Oracle and Handling PL/SQL Stored ProceduresM|18 Migrating from Oracle and Handling PL/SQL Stored Procedures
M|18 Migrating from Oracle and Handling PL/SQL Stored Procedures
 
Migrations from PLSQL and Transact-SQL - m18
Migrations from PLSQL and Transact-SQL - m18Migrations from PLSQL and Transact-SQL - m18
Migrations from PLSQL and Transact-SQL - m18
 
Wtu 2014 ibm web sphere mq for zos - performance and accounting
Wtu 2014   ibm web sphere mq for zos - performance and accountingWtu 2014   ibm web sphere mq for zos - performance and accounting
Wtu 2014 ibm web sphere mq for zos - performance and accounting
 
Advanced Office365 Sharepoint online Workflows
Advanced Office365 Sharepoint online WorkflowsAdvanced Office365 Sharepoint online Workflows
Advanced Office365 Sharepoint online Workflows
 

More from Bartosz Ratajczyk

More from Bartosz Ratajczyk (14)

SQL Server + docker - pierwsze kroki
SQL Server + docker - pierwsze krokiSQL Server + docker - pierwsze kroki
SQL Server + docker - pierwsze kroki
 
OLE DB - kiedy FastLoad nie jest takie fast
OLE DB - kiedy FastLoad nie jest takie fastOLE DB - kiedy FastLoad nie jest takie fast
OLE DB - kiedy FastLoad nie jest takie fast
 
Jak działa rekurencyjne CTE?
Jak działa rekurencyjne CTE?Jak działa rekurencyjne CTE?
Jak działa rekurencyjne CTE?
 
SqlSaturday Denmark 2017 - Automate your SSIS deployment process
SqlSaturday Denmark 2017 - Automate your SSIS deployment processSqlSaturday Denmark 2017 - Automate your SSIS deployment process
SqlSaturday Denmark 2017 - Automate your SSIS deployment process
 
"Administrator z przypadku" - Jak działa SQL Server i jak o niego dbać
"Administrator z przypadku" - Jak działa SQL Server i jak o niego dbać"Administrator z przypadku" - Jak działa SQL Server i jak o niego dbać
"Administrator z przypadku" - Jak działa SQL Server i jak o niego dbać
 
Zautomatyzuj swój proces wdrażania projektów SSIS
Zautomatyzuj swój proces wdrażania projektów SSISZautomatyzuj swój proces wdrażania projektów SSIS
Zautomatyzuj swój proces wdrażania projektów SSIS
 
XML w SQL Server w praktyce
XML w SQL Server w praktyceXML w SQL Server w praktyce
XML w SQL Server w praktyce
 
Jak szybko przetwarzasz hurtowe ilości XML?
Jak szybko przetwarzasz hurtowe ilości XML?Jak szybko przetwarzasz hurtowe ilości XML?
Jak szybko przetwarzasz hurtowe ilości XML?
 
Operacje minimalnie logowane
Operacje minimalnie logowaneOperacje minimalnie logowane
Operacje minimalnie logowane
 
Po co mi Temporal Tables?
Po co mi Temporal Tables?Po co mi Temporal Tables?
Po co mi Temporal Tables?
 
Co to te CTE?
Co to te CTE?Co to te CTE?
Co to te CTE?
 
O co chodzi z FILESTREAM?
O co chodzi z FILESTREAM?O co chodzi z FILESTREAM?
O co chodzi z FILESTREAM?
 
Alerty WMI
Alerty WMIAlerty WMI
Alerty WMI
 
Czy mi się przyda hierarchyid?
Czy mi się przyda hierarchyid?Czy mi się przyda hierarchyid?
Czy mi się przyda hierarchyid?
 

Recently uploaded

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
MateoGardella
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
MateoGardella
 

Recently uploaded (20)

Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 

How minimalloggingcanhelpme bartoszratajczyk_sql_sat534

  • 1. How minimal logging can help me? Bartosz Ratajczyk #534 | KRAKÓW 2016
  • 2. Our Sponsors 11/29/201 6 | Footer Goes Here2 | SQL SATURDAY | #534 | KRAKÓW 2016
  • 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. 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. 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. 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. 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. 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. 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. Log investigation SELECT * FROM fn_dblog(NULL, NULL) SELECT * FROM fn_dblog(@StartLSN, @EndLSN) SQL SATURDAY | #534 | KRAKÓW 2016
  • 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. 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. 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. Pros • Faster transactions and log saving • Smaller I/O SQL SATURDAY | #534 | KRAKÓW 2016
  • 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. TRUNCATE TABLE • Lightning fast data deletion • Is it logged or not? • Why is it so fast? SQL SATURDAY | #534 | KRAKÓW 2016
  • 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. 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. Our Sponsors 11/29/201 6 | Footer Goes Here22 | SQL SATURDAY | #534 | KRAKÓW 2016
  • 24. Bartosz Ratajczyk #534 | KRAKÓW 2016