- Unexpected system shutdown/crash or forced shutdown
- SQL administrator tries to query or modify SQL data
In both the circumstances, the Host instances on SQL server restart repeatedly or terminate the connection between SQL application and the database. The following error message is displayed in SQL Server error log:
SQL Server detected a logical consistency-based I/O error: incorrect pageid (expected 1:1848; actual 0:0). It occurred during a read of page (1:1848) in database ID 10 at offset 0x00000000e70000 in file ‘C:Program FilesMicrosoft SQL ServerMSSQL10.MSSQLSERVERMSSQLDATAABCDb.mdf’. Additional messages in the SQL Server error log or system event log may provide more detail. This is a severe error condition that threatens database integrity and must be corrected immediately. Complete a full database consistency check (DBCC CHECKDB). This error can be caused by many factors; for more information, see SQL Server Books Online.
When a SQL Server database experiences a logical consistency based error, the first step is to diagnose the cause of error. The following methods can help in detecting the error:
- Use Best Practice Analyzer (BPA) tool – BPA tool helps in detecting critical consistency error. This tool is specific to the SQL-version, meaning BPA 2008 is available with SQL 2008 and so on.
- Check Windows System at Event Log system level, driver or disk related errors
- Check file system integrity by running chkdsk command
- Run the diagnostics recommended by hardware manufacturers for the system or disk
- For SQL server 2008, run the utility SQLIOSim on the drive of the database that has reported I/O error.
- Contact hardware vendor or device manufacturer to verify that hardware requirements confirm with I/O requirements of SQL server.
- Check and run DBCC CHECKDB in SQL server database. DBCC CHECKDB command helps to check logical and physical consistency of SQL database pages, rows, system table referential integrity, index relationships and other structural checks. In case the check fails, error is reported as a part of CHECKDB command. The following DBCC CHECKDB command can be used:
DBCC CHECKDB (ABCD) WITH NO_INFOMSGS, ALL_ERRORMSGS
- You have a recent full backup
- Backup is updated, just prior to corruption, and not long ago so as to avoid critical data loss
- Corruption is at page level, as page level corruption issue can be resolved with the help of page-level restoration.
Note: Page-level restoration is valid when you are dealing with large database and corruption is in only in one-page of SQL database.
Step 1: Use the following command for restoring SQL database from full backup
Backup the transaction log
BACKUP LOG PageLevelRestores TO
DISK = 'g:PageLevelRestores_LOG1.bak'
WITH INIT
GO
Step 2: Perform the restoration change to reflect the changes online.
Backup the tail of the log...
BACKUP LOG PageLevelRestores TO
DISK = 'g:PageLevelRestores_LOG_TAIL.bak'
WITH INIT
GO
Note: There is no need to restore full SQL server database if corruption is confined to a single page. You can restore database from the available backup for that page which is corrupted. Performing the following commands will help in restoring backup for a single page:
Restore all available log backups in the correct order
RESTORE LOG PageLevelRestores FROM
DISK = 'g:PageLevelRestores_LOG1.bak'
WITH NORECOVERY
GO
-- Finally restore the tail log backup
RESTORE LOG PageLevelRestores FROM
DISK = 'g:PageLevelRestores_LOG_TAIL.bak'
WITH NORECOVERY
GO
-- Finally finish with the restore sequence
RESTORE DATABASE PageLevelRestores WITH RECOVERY
GO
Limitations of SQL database backup:
- It is not possible to restore from SQL database backup when the available backup is obsolete.
- If Logical consistency based I/O error is spread across the SQL server database, then this method will not be valid.
- For those cases where faulty page exists in a non-clustered index, the SQL database can be fixed by dropping and recreating the index of SQL database.
- Take a backup of SQL server database and save it with another name
- Set SQL database in Single user mode
- Get all Tables record count by using the following commands
- Run the command:
- Once SQL database is repaired, repeat the process of ‘Table Record Count’ and compare with old record count.