Appendix C. Hsqldb Database Files and Recovery

This text is based on HypersonicSQL documentation, updated to reflect the latest version 1.7.2 of HSQLDB.

$Date: 2004/04/20 18:35:56 $

Table of Contents

Clean Shutdown

The Standalone and Client/Server modes will in most cases use files to store all data to disk in a persistent and safe way. This document describes the meaning of the files, the states and the procedures followed by the engine to recover the data.

A database named 'test' is used in this description. The database files will be test.script,, and test.backup.

Database Files

Contains the entry 'modified'. If the entry 'modified' is set to 'yes' then the database is either running or was not closed correctly (because the close algorithm sets 'modified' to 'no' at the end).


This file contains the SQL statements that makes up the database up to the last checkpoint - it is in synch with test.backup.

This file contains the (binary) data records for CACHED tables only.


This is compressed file that contains the complete backup of the old file at the time of last checkpoint.


This file contains the extra SQL statements that have modified the database since the last checkpoint (something like the 'Redo-log' or 'Transaction-log', but just text).

In the above list, a checkpoint results from both a CHECKPOINT command and a SHUTDOWN command.


Database is closed correctly

State after using the command SHUTDOWN

  • The file is fully updated.

  • The test.backup contains the compressed file.

  • The test.script contains the information in the database, excluding data for CACHED and TEXT tables.

  • The contains the entry 'modified' set to 'no'.

  • There is no test.log file.

Database is closed correctly with SHUTDOWN SCRIPT

State after using the command SHUTDOWN SCRIPT

  • The file does not exist; all CACHED table data is in the test.script file

  • The test.backup does not exist.

  • The test.script contains the information in the database, including data for CACHED and TEXT tables.

  • The contains the entry 'modified' set to 'no'.

  • There is no test.log file.

Database is aborted

This may happen by sudden power off, Ctrl+C in Windows, but may be simulated using the command SHUTDOWN IMMEDIATELY.

Aborted Database state

  • The still containes 'modified=yes'.

  • The test.script contains a snapshot of the database at the last checkpoint and is OK.

  • The file may be corrupt because the cache in memory was not written out completely.

  • The test.backup file contains a snapshot of that corresponds to test.script.

  • The test.log file contain all information to re-do all changes since the snanapshot. As a result of abnormal termination, this file may be partially corrupt.


The database engine performs the following procedures internally in different circumstances.

Clean Shutdown

Procedure C.1. Clean Hsqldb database shutdown

  1. The file is written completely (all the modified cached table rows are witten out) and closed.

  2. The is created (containing the compressed file)

  3. The file is created using the information in the database (and thus shrinks because no UPDATE and DELETE statements; only INSERT).

  4. The entry 'modified' in the properties file is set to 'yes-new-files'

  5. The file test.script is deleted

  6. The file is renamed to test.script

  7. The file test.backup is deleted

  8. The file is renamed to test.backup

  9. The entry 'modified' in the properties file is set to 'no'

  10. The file test.log is deleted


Procedure C.2. Database is opened

  1. Check if the database files are in use (by checking a special test.lck file).

  2. See if the file exists, otherwise create it.

  3. If the did not exist, then this is a new database. Create the empty test.log to append new commands.

  4. If it is an existing database, check in the file if 'modified=yes'. This would mean last time it was not closed correctly, and thus the file may be corrupted or incomplete. In this case the 'REPAIR' algorithm is executed (see below), before the database is opened normally.

  5. Otherwise, if in the file 'modified=yes-new-files', then the (old) test.backup and test.script files are deleted and the new file is renamed to test.script.

  6. Open the test.script file and execute the commands.

  7. Create the empty test.log to append new commands.


The current file is corrupt, but with the old (from the test.backup file and test.script) and the current test.log, the database is made up-to-date. The database engine takes these steps:

Procedure C.3. Database Repair

  1. Restore the old file from the backup (uncompress the test.backup and overwrite

  2. Execute all commands in the test.script file.

  3. Execute all commands in the test.log file. If due to corruption, an exception is thrown, the rest of the lines of command in the test.log file are ignored.

  4. Close the database correctly (including a backup).