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:
- Check your database at regular intervals if your data is particularly important.
- Plan to check your database after the occurrence of a potentially corrupting event (e.g., power failure).
- Check your database when you get an error message that indicates corruption could have occurred;
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.
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:
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.
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:
- Use the FIND command to retrieve all records of the appropriate entity set or relationship;
- Use the NEXT command to locate the damaged record;
- Use the LIST command to display the record on the screen (it will display an error message indicating the corruption);
- Use the CHANGE command to correct the wrong fields or use the DELETE command to delete the entire record (you can later manually ADD the same record again).
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).