How to Maintain the Integrity of a Database

A database is always considered integral unless it presents problems. This may sound a little bit funny, but the general approach, in real life, is to run an application over a database until something wrong happens.

To avoid surprises, certain procedures can be preventively taken to guarantee that the database is always available. These procedures include:

In any circumstances, you can check the integrity of a database by two methods:

If an error is detected, take corrective measures to recover data.

The ZimFix utility

If you suspect corruption of your database, or if you want to check the integrity of the database, run the Repair Facility (ZIMFIX) administrative utility against all database files. The Repair Facility checks the integrity of the database files associated with a specified entity set or relationship. In particular, it verifies that records are constructed properly and that indexes correspond properly to the data stored in the records.

Note: Before executing the Repair Facility (ZIMFIX) to detect corruption, run it with the EXTRACT FILE DEFINITIONS box checked (equivalent to ZIMDD).

For example, to check the integrity of the database files corresponding to EntitySets named Pollutants and WaterSamples, execute the following commands at the operating system level:

zimdd
zimfix WaterSamples
zimfix Pollutants

The Repair Facility can also perform structural integrity checks on application directory files, but it cannot check the integrity of the actual object definitions that those directories contain.

Note: The Repair Facility reports the records that fail the integrity checks, enabling recall and viewing of the damaged records.

Finding Data in your database

A fast way of detecting errors is to run a series of FIND commands over the entity set or relationship in question:

. A FIND command without using indexes to read all records;

. One FIND command per index to check the integrity of the indexes.

If there are no sparse indexes, the number of records found in each one of the FINDs must be exactly the same.

This method is faster than running ZimFix, but doesn't check the contents of records. It indicates if something is wrong or it can directly stop in a record that is corrupted. Later, you can run ZimFix.

How to Restore a Corrupted Database

There are two general ways to restore a corrupted database (jn particular, a Zim file):

1. Use ZimFix with the repair option;

2. If you have found a record that is corrupt (trying to LIST that record, there is an error message), you can do:

3. If the corruption was in an index, you can ERASE and CREATE that particular index again (always erase and create indexes in the same order they were originally created to avoid the need to recompile all programs).