Using checksums to detect corruption

Checksums are used to determine whether a database page has been modified on disk. When you create a database with checksums enabled, a checksum is calculated for each page just before it is written to disk. The next time the page is read from disk, the page's checksum is recalculated and compared to the checksum stored on the page. If the checksums are different, then the page has been modified on disk and an error occurs.

You can check whether a database was created with checksums enabled by executing the following statement:

SELECT DB_PROPERTY ( 'Checksum' );

This query returns ON if checksums are turned on; otherwise, it returns OFF.

Validating checksums

If you created your database with checksums enabled, you can check the validity of the disk pages. Checksum validation requires either DBA or VALIDATE authority.

For databases with checksums enabled, a checksum is calculated for each database page and this value is stored when the page is written to disk. You can use the Validation utility (dbvalid) or the Validate Database Wizard in Sybase Central to perform checksum validation, which consists of reading the database pages from disk and calculating the checksum for the page. If the calculated checksum does not match the stored checksum for a page, the page has been modified or corrupted while on disk or while writing to the page. If one or more pages has been corrupted, an error is returned and information about the invalid pages appears in the database server messages window.

For more information about checksum validation, see VALIDATE statement and Validation utility (dbvalid).

Automatic checksum creation

In the following situations, checksums are enabled for the database, regardless of the checksum setting that was specified when the database was created:

  • Critical pages   The database server calculates checksums for critical database pages in all databases, regardless of whether checksums are enabled. These checksums are used to detect offline corruption, which can help reduce the chances of other data being corrupted as the result of a bad critical page. Because the database server calculates these checksums, if a database becomes corrupt that does not have checksums enabled, the database server shuts down with a fatal error.

    As well, if you validate a database that does not have checksums enabled, but that has a bad critical page, dbvalid can still return warnings about checksum violations.

  • Windows Mobile databases   The database server automatically enables checksums for databases running on Windows Mobile to help provide early detection if the database file becomes corrupt.

  • Databases running on some storage media   When the database is running on storage media that may be less reliable, such as network or removable drives, the database server automatically enables checksums for the database. Checksums remain enabled as long as the database resides on such a device, and the pages are checksummed when they are written. If the database is moved to a more reliable storage device, the database server verifies the checksum for checksummed pages when they are brought into the database server cache.


Validate a database
Validate a table