Read-Only Databases - Firebird

By default, databases are in read-write mode when created. Read-write databases cannot be on a read-only filesystem, even if they are used only for SELECT, because Firebird writes information about transaction states to a data structure in the database file.

A Firebird database can be deployed as a read-only file, providing the ability to distribute catalogs, albums of files, and other non-maintained types of database on CDs and other read-only filesystems. Read-only databases can, of course, be accessed on read-write systems as well.

A read-only database is not the same thing as a database file that has its read-only attribute set on. File-copying a read-write database to a CD-ROM does not make it into a read-only database.

The application will need to be written so as to avoid requests that involve writing to the database or to trap the exceptions raised when they are attempted. The following will throw the error “Attempt to write to a read-only database”:

  • UPDATE, INSERT, or DELETE operations
  • Metadata changes
  • Operations that try to increment generators

External Files

Any accompanying files linked to the database by having been declared with CREATE TABLE tablename EXTERNAL FILE 'filename' will also be opened read-only, even if the file itself is not carrying the filesystem read-only attribute.

Making a Database Read-Only

Exclusive access is required to switch a database between read-write and read-only modes—see the section “Exclusive Access” in Chapter Housekeeping Tool (gfix) for instructions. The mode switch can be performed by the database owner or the SYSDBA.

Either fix or gbak can be used:

  • Using gbak, back up the database and restore it in read-only mode using the –c[reate] option, for example:

    gbak -create -mode read_only db1.fbk db1.fdb

  • Using gfix, issue a –m[ode] read_only command, for example:

    gfix -mode read_only db1.fdb


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Firebird Topics