Today, I worked on a pretty simple SQL Server upgrade project. After finishing up, I did my usual quick briefing with the customer about the system and the work done.
As a consultant and professional, I believe this interaction is an important step for both sides. I’m using this conversation to give customers a few quick "candy-tips". Practical advice about best practices and small changes that can make performance difference.
This time, I did the same, but I stumbled upon something completely new to me!
I found some databases with PAGE_VERIFY database option was set TORN_PAGE_DETECTION. I was intrigued and decided to dig deeper.
So, today’s blog post will be a “something new I learned today” story. Let’s dive in!
What Is TORN_PAGE_DETECTION?
Let’s start with the basics. TORN_PAGE_DETECTION is an option in SQL Server that helps detect a specific type of data corruption called a torn page.
A torn page happens when a database page (8 KB) is only partly written to disk. This can happen due to power failures, hardware issues, or unexpected interruptions. As the result, only part of the data remains, and the rest is in an inconsistent state.
Hmm, something sounds familiar here. Right, this sounds like a corruption! Yep, torn page is a type of data corruption.
When TORN_PAGE_DETECTION is on, SQL Server writes specific bit patterns to the page. These act as markers. If the markers don’t match later, SQL Server identifies the problem.
Why Was It Introduced?
Back in the day, hardware wasn’t as reliable as it is now. Power outages and server crashes were common. Tools to handle corruption were limited. To tackle these issues, Microsoft introduced TORN_PAGE_DETECTION in SQL Server 7.0, released in 1998.
TORN_PAGE_DETECTION was the primary method for detecting data corruption in SQL Server before 2005.
It was a simple but effective way to detect torn pages. While it didn’t fix the corruption, it provided an early warning. This helped database admins act before things got worse.
In SQL Server 2005, Microsoft introduced the CHECKSUM option, which in days became the default method for page verification.
TORN_PAGE_DETECTION vs. CHECKSUM
Both options are used for data integrity. As SQL Server evolved, so did its data protection features evolve too. CHECKSUM, a is a newer and more powerful option.
Here’s comparison between them:
Feature | TORN_PAGE_DETECTION | CHECKSUM |
Introduced Date | SQL Server 7.0 (1998) | SQL Server 2005 (2005) |
Primary Purpose | Detect torn pages (partial writes) | Detect broader page corruption, including bit flips and torn pages |
Mechanism | Writes bit patterns as markers on pages | Calculates and stores a checksum value for each page |
Coverage | Detects torn pages only | Detects torn pages, bit flips, and other data corruption |
Performance Impact | Minimal | Slightly higher, but generally negligible |
Error Detection Method | Compares markers when the page is read | Recalculates checksum and compares with stored value |
Default Behavior | Must be explicitly enabled | Default page verification in modern SQL Server versions |
Usefulness Today | Outdated; rarely used in modern systems | Recommended for all modern SQL Server environments |
Compatibility | Supported in older versions, up to modern ones for legacy reasons | Supported and default in SQL Server 2005 and later |
Action on Detection | Raises an error; requires manual intervention | Raises an error; requires manual intervention |
Recommended Use Case | Legacy systems or backward compatibility | General use in modern systems for robust corruption detection |
Well, CHECKSUM is better in almost every way. It detects a wider range of corruption issues and is the default in newer SQL Server versions.
Performance Impact
You might wonder how these settings affect performance.
TORN_PAGE_DETECTION: Minimal performance impact. It’s lightweight because it only tracks specific things.
CHECKSUM: Slightly higher overhead, but the extra protection is worth it! For most systems, the impact is minor.
For modern workloads, the small performance trade-off with CHECKSUM is a no-deal breaker.
Should You Use TORN_PAGE_DETECTION?
Here’s my take:
New systems: Always use CHECKSUM. It’s more reliable and gives better protection.
Legacy systems. Stick with TORN_PAGE_DETECTION if you’re running older SQL Server versions that don’t support CHECKSUM. ... hope you didn't has such system.
BTW, some VMs tools, like VMware vSphere and Microsoft Hyper-V offer built-in features to monitor and verify data integrity. Consider using it too!
Summary
Finding TORN_PAGE_DETECTION was a fun learning moment for me. It’s not a setting we can see often today. Understanding its history and purpose, I got a better idea of how SQL Server evolved. It’s good to know about it.
While CHECKSUM has taken its place as the go-to option for modern systems, TORN_PAGE_DETECTION was a "must-have" tool in its time. If you’re working with legacy systems (hope you not), it’s good to know about it.
At the end of the day, protecting our data should always be a priority. Whether it’s better settings, strong hardware, or frequent backups, don’t leave it to chance.
Final words:
No matter what option you use, regular backups can be your safety net!
Before enabling any option, always test it in a non-production environment! Check it for performance impacts and any other effects.
You can use "Page Verification Checksum" script and test any of your environments.
Hope this helps!
Additional reading and sources:
Comentarios