SQL Server Corruption, Page Restore and DBCC
SQL Server reports corruption down to individual pages, and under specific conditions it can restore isolated damaged pages from backups and then roll them forward with the log. Whether that, a full restore, extraction of readable data or a DBCC repair is the right path depends on prerequisites to confirm first. DBCC CHECKDB without a repair option is a consistency check; REPAIR_REBUILD and REPAIR_ALLOW_DATA_LOSS are different repairs, and both change the database.
- Page restore in practice needs full recovery model, a usable data backup and an unbroken log chain; online restore is Enterprise-only.
- The log, GAM, SGAM and PFS pages, boot pages and full-text catalogs cannot be page-restored; they need wider restore or extraction.
- DBCC CHECKDB checks consistency but uses resources, snapshots or locks; varying results point to investigating I/O and memory, not a diagnosis.
REPAIR_REBUILDis designed to avoid data loss,REPAIR_ALLOW_DATA_LOSScan deallocate data; any repair writes, so run it on a copy.- A database that starts again is not proof of completeness; check queries, constraints, business totals and record the accepted recovery point.
What to preserve and record before changing anything
A SQL Server database’s primary data file (.mdf), any secondary data files (.ndf) and the transaction log (.ldf) should be preserved together, alongside FILESTREAM directories, full-text data, memory-optimized containers where applicable, and SQL Server’s own error logs. Copying only the .mdf can remove exactly the context — log history above all — that a real recovery attempt would depend on. The inventory also needs:
- The backup chain. Which full, differential and log backups exist, whether they are readable, and whether the log sequence is unbroken from the last data backup to the present.
- Build, edition and configuration. The exact version and edition decide which restore options exist; recovery model, file layout and filegroups decide which ones apply.
- Encryption dependencies. With Transparent Data Encryption, data files, log and backups are encrypted with a database encryption key protected either by a certificate stored in the server’s
masterdatabase or by an asymmetric key on an extensible key management (EKM) provider (Transparent Data Encryption). With a certificate, opening, restoring or attaching the database on another server needs that certificate and its private key; with EKM, it needs access to the matching asymmetric key through a configured provider and the authorization that provider requires. Native backup encryption has its own certificate or EKM key, and without it the backup file cannot be restored (Backup encryption). Which protector applies has to be established per database; not every encrypted database uses the same workflow. - Error evidence. Error-log entries, consistency-check output and the file and page IDs they name, kept as they were reported.
Copying the files of a running instance is not the same as a backup: data and log files copied at different moments may never have existed together as one transactional state. A native backup or export needs an instance that can still read the database; acquiring the underlying storage fits when the instance or media cannot be trusted, and has its own preconditions (Recovery Copies, Database Page Corruption and Transaction Recovery). Which comes first depends on the state of the source, not on a fixed rule.
Page errors are evidence, not automatically a page-restore plan
SQL Server can detect checksum failures, torn writes and other I/O-related page corruption. Microsoft’s page-restore documentation notes that a checksum or torn-write error returns the page ID, and lists msdb..suspect_pages, the error log, event traces and DBCC output as places to identify damaged pages. That precision is what makes page-level recovery possible: the engine can name the page in question instead of treating the whole file as equally suspect.
A page ID is still not a guarantee that page restore is enough. Several reported pages may share a cause in the storage or memory path; the page may be one that page restore cannot cover; and Microsoft advises that when more than a few pages in a file need restoring, restoring the whole file is generally more efficient, and that many damaged pages on one device may indicate a pending device failure. A single error is a starting point for deciding scope, not proof that damage is limited to that page.
DBCC CHECKDB is a check, not a passive file viewer
Microsoft documents DBCC CHECKDB as checking allocation, structural and logical consistency of the database through the engine’s own understanding of its structures, and its report can point to a specific object and page rather than declaring the whole database corrupt. Running it is not a neutral look at the files. CHECKDB uses an internal database snapshot for transactional consistency; if a snapshot cannot be created, or locking is requested, it takes an exclusive database lock for allocation checks and shared table locks for table checks. It runs in parallel by default and needs tempdb space, and checking the database means reading its structures through the storage underneath — on storage that is already unstable, each run adds load.
Microsoft’s troubleshooting article lists file-system corruption, hardware, drivers, corrupted pages in memory or storage cache and SQL Server itself as possible causes, and says errors that appear on one run and disappear on the next may point to disk-cache or other I/O-path problems. That makes varying results a reason to investigate the I/O path, memory and environment — not a diagnosis of a specific fault. Preserve the first error report and the file and page IDs it names; a series of repeated checks run to “confirm” the result mainly adds load to the source.
Four paths and what each needs
- Restore from backup. Microsoft’s primary recommendation for CHECKDB errors. Needs readable backups and, for a recent recovery point, the log backups after them; it replaces the database state with the one they describe.
- Page restore. Needs the prerequisites below and a damaged page of a type that can be restored. It replaces only the named pages, then rolls them forward.
- Extraction. When no usable backup exists and the engine cannot safely open the database, readable rows and objects are exported to a new destination. The result is a partial set of records, not a repaired database, and the gaps have to be listed.
- Last-resort repair. When restore is not possible and the loss is accepted, a DBCC repair option is run on a copy. It writes to the database, and the result has to be validated as described below.
For every path, record what was used (which backups, which pages, which copy) and which recovery point the result represents.
Page restore rebuilds from backup and log, not from the damaged bytes
Microsoft documents page restore as a mechanism for isolated damaged pages: it restores the affected page from a backup and then applies transaction-log records to bring that page forward to a state consistent with the rest of the current database. This is recovery built from backup and log history, not a patch of the damaged bytes in the MDF, and the prerequisites follow from that:
- Version and edition. Page restore is documented for SQL Server. Offline page restore is supported in all editions; online page restore, where the database stays available, is an Enterprise edition feature, and some damaged critical pages still require offline restore. The Restore Pages article applies to SQL Server; Azure services with “SQL” in their name should not be assumed to offer the same procedure.
- Recovery model. Page restore applies to databases using the full or bulk-logged recovery model, and only to read/write filegroups. Under bulk-logged recovery, Microsoft says page restore generally does not work, and an offline page can prevent the log backup the sequence needs.
- Backups and log chain. A data backup that contains a good copy of the page, and an unbroken chain of log backups from that restore to the current log, including a final log backup taken after the damaged pages are restored.
- A reachable recovery point. If the needed log cannot be backed up or is missing, this page-restore sequence cannot reach the required point. The options then to assess are a wider restore to the latest consistent point the backups allow, extraction of readable data, and, only where restore is not possible, a last-resort repair. Extraction does not promise transactional consistency or the most recent changes.
Changing the recovery model now does not recreate history that was never captured. The simple recovery model does not support log backups, and Microsoft’s guidance on changing the recovery model says a switch to full or bulk-logged takes effect only after the next full or differential backup starts a log chain. Log records that were never backed up before the damage are not brought back by that switch.
Pages that page restore cannot cover
Only database pages can be restored this way. Microsoft’s Restore Pages article excludes the transaction log; the allocation pages GAM, SGAM and PFS; page 0 of every data file (the file boot page); page 1:9 (the database boot page); and full-text catalogs. Damage to any of these, or damage spread over many pages, needs a wider scope: a file, filegroup or full database restore where backups allow it, or extraction of what is readable where they do not. Restoring a single page cannot make up for damage in the structures that describe where pages and files are.
Rebuilding a secondary index is a write, not a diagnostic
Microsoft notes that some problems in derived data, such as a secondary index, can be resolved by recalculating it — dropping and rebuilding the index — instead of restoring pages. That route makes sense only once it is confirmed that the base data the index is derived from, the heap or clustered index, is intact and that the problem is confined to the index. A rebuild reads the base data and writes a new structure; on an unstable source, or when the base rows are themselves damaged, it is not a harmless test. Damage to heap or clustered base rows has no equivalent source to rebuild from and belongs to the restore, extraction or repair decision above.
REPAIR_REBUILD and REPAIR_ALLOW_DATA_LOSS are different repairs
DBCC CHECKDB without a repair option checks; its repair options are a separate mode that requires single-user access and that Microsoft says to use only as a last resort.
REPAIR_REBUILDperforms repairs that Microsoft describes as having no possibility of data loss, such as repairing missing rows in nonclustered indexes or rebuilding an index. It still changes the database, and it does not repair errors involving FILESTREAM data.REPAIR_ALLOW_DATA_LOSStries to repair all reported errors and can deallocate rows, pages or series of pages. Deallocated data cannot be recovered or even identified afterwards, foreign keys are not checked during the repair, and it can lose more data than restoring the last known good backup.REPAIR_FASTis kept for backward compatibility only and performs no repair actions.
A message reporting successful repair means the structure is consistent again, not that every original record survived. Microsoft recommends copying the database files before repair and checking constraints afterwards. The general distinction between check and repair modes is covered in Repair vs. Recovery.
Validate the data, not just the startup
A database that starts and passes a subsequent CHECKDB run has cleared a structural bar, not a business one. After any restore, extraction or repair, validation should cover:
- a full structural check of the result, run on a copy where possible;
- the queries the application depends on most, and row counts against known references;
- constraints and referential integrity, which repair does not maintain;
- business reconciliation, such as totals, balances or sequence numbers compared with an independent record;
- attachments and FILESTREAM data where the database has them, since a
PHYSICAL_ONLYcheck skips FILESTREAM.
The report should state the recovery point that was accepted — the time or log position the data reflects — and any known gaps, such as work after the last usable log backup or rows removed by repair. General methods for this are in How to Validate Recovered Data.
REPAIR_ALLOW_DATA_LOSS is explicitly a last resort in Microsoft’s own guidance. Confirm whether a backup restore or page restore is possible first, and run any repair option against a copy of the database, never the only surviving copy.
Technical references: Microsoft Learn: Restore Pages (SQL Server) — excluded pages, editions, recovery models, log chain · Microsoft Learn: DBCC CHECKDB — snapshot and locks, repair options · Microsoft Learn: Troubleshoot database consistency errors — causes, intermittent errors · Microsoft Learn: Transparent Data Encryption — certificate and key dependencies. Backup-encryption and recovery-model guidance are cited inline. Restore Pages was checked in its SQL Server 2019 (ver15) and current (ver17) views, the other articles in their current views; behaviour can differ by version and edition, and Azure SQL services are outside this scope.
Related: Database Page Corruption and Transaction Recovery · Database Corruption (SQL Server, MySQL, and Similar) · InnoDB Tablespaces, Redo Logs and Crash Recovery · Repair vs. Recovery · VM, Database and Application-Container Recovery Tools