hsqldb v.1.61 Download Files
The Standalone and Client/Server version will in
most cases use files to store all data in a persistent
and save way to disk. This documentation describes
the meaning of the files and the mechanisms.
A database named 'test' is in used in this description.
The database files will be 'test.script', 'test.properties',
'test.data' and 'test.backup'.
Database Files
- test.properties
Contains the filenames and the entry 'modified'. If the entry
'modified' is set to 'yes' then the database is eighter running
or was the last time not closed correctly (because the close
algorithm sets 'modified' to 'no' at the end).
- test.script
This file contains the SQL statements that makes up the database so far
(something like the 'Redo-log' or 'Transaction-log', but just text)
- test.data
This file contains the (binary) data records (not memory tables)
- test.backup
This is compressed file that contains the backup of the old test.data file.
Mechanisms
Database is opened
- Check if test.properties file is in use (algorithm: try to delete and
re-create; if it works then the database it is not in use).
- Check in the test.properties file if 'modified=yes'.
This would mean last time it was not closed correctly, and thus
the test.data file may be corrupted. In this case the
'Repair' algorithm is executed (see below) otherwise
- If in the the test.properties file is 'modified=yes-new-files', then
the (old) test.backup and test.script files are deleted and the new test.backup.new
and test.script.new files are renamed.
- Open the test.script file and execute the commands
- Append commands to the test.script file
Database is aborted
This may happen by sudden power off, Ctrl+C in Windows, but may
be simulated using the command SHUTDOWN IMMEDIATELY.
- All files are closed; but the test.script file contains all
information to re-do all changes.
- The test.data file maybe corrupt because the cache in memory was not
written completely.
- The test.properties still containes 'modified=yes'
- All files are closed (maybe by the operating system)
Database is closed correctly
This may be done using the command SHUTDOWN, in the
Standalone version using Connection.close()
- The test.data file is written completely
- The test.backup.new is created (containing the compressed test.data file)
- The file test.script.new is created using the information in the database
(and thus shrinks because no 'update' and 'delete' statements; only simple 'inserts').
- The entry 'modified' is set to 'yes-new-files'
- The file test.script is deleted
- The file test.script.new is renamed to test.script
- The file test.backup is deleted
- The file test.backup.new is renamed to test.backup
- The entry 'modified' is set to 'no'
Repair
The current test.data file is corrupt, but with the old test.data (from the
test.backup file) and the current test.script, the database can be made up-to-date:
- Restore the old test.data file from the backup (uncompress the test.backup)
- Execute all commands in the test.script file.
- Close the database correctly (including a backup).