Compacting Files
To optimize the use of storage and reduce internal file fragmentation, you should periodically compact your database files. Compacting a database file creates a copy of the file, rearranging how the file is stored on disk.
Compacted files are usually smaller than the original file but no smaller than configured in the
A file compaction is a reorganization of a single database file in which no structural changes to objects are applied. Compacting the entire database compacts each file serially, so calculate the amount of free disk space for a full database compaction if the backup file (.bak) is to be on the same volume by doubling the size of the largest file that needs to be compacted in the database and add a little more for a few records in the journal.
If the compaction is non-updating, the space required for the compaction is the same regardless of whether the compaction is run offline or online. The following is an example of a non-updating compaction carried out in the code of a JADE method.
dbFile.changeAccessMode(DbFile.Mode_ReadOnly); dbFile.compactFile; dbFile.changeAccessMode(DbFile.Mode_Update);
If the online compaction is updating, the space requirement is the same as an offline compaction plus the overheads of create operations, because during the operation, creates in the original database file (.dat) have to be allocated from new space at the end of the file, therefore extending it. This new space cannot be calculated.
The file compaction process has the secondary effect of bTree index blocks being loaded more efficiently. The more-efficient loading of bTree index blocks potentially reduces the file space occupied by index blocks.
File compaction is an atomic process, in the same way that a normal database transaction is atomic. The file compaction process compacts to a working copy of the original file. If a file compaction is interrupted by a system or program failure, the original file is left unchanged.
When file compaction is complete, the original file is replaced with the compacted version. If an interrupted file compaction is restarted, the previous work file is removed and compaction restarts from the beginning.
For details, see "Using the Compact Files Command", in Chapter 1.