Read-write and Read-only Databases

From InterBase

Go Up to Database Configuration and Maintenance

InterBase databases have two modes: read-only and read-write. At creation, all databases are both readable and writable: they are in read-write mode.

Read-write Databases

To function in read-write mode, databases must exist on writable media and the ibserver process must have write access to the database file. For databases that are in read-write mode, this is true even when they are used only for reading because the transaction states are kept in an internal inventory data structure within the database file. Therefore any transaction against the database requires the ability to write to the transaction inventory.

Under both Windows and UNIX, read-write database files must be writable by the user ID for the ibserver process. However, the operating environment or file system can be configured to create files that have limited file privileges by default. If you attempt to attach to a database and get an error of “unavailable database,” first check to see if the permissions of the database file are such that the user ID of the ibserver process does not have write privilege on the database file.

Read-only Databases

You can change InterBase databases to read-only mode. This provides enhanced security for databases by protecting them from accidental or malicious updates and enables distribution on read-only media such as CDROMs. Databases are always in read‑write mode at creation time. This feature is independent of dialect. Any ODS 10 or higher database can be set to read-only mode.

You can use gbak, gfix, or IBConsole to change a database to read-only mode. (See Making a Database Read-only below.)

Properties of Read-only Databases

  • In read-only mode, databases can be placed on CD-ROMs or in read-only file systems as well as on read-write file systems.
  • Attempted INSERT, UPDATE, and DELETE operations on a read-only database generate an error. See the “Error Codes and Messages” chapter of the Language Reference Guide.
  • No metadata changes are allowed in read-only databases.
  • Generators in a read-only database do not increment and are allowed only to return the current value. For example, in a read-only database, the following statement succeeds:
SELECT GEN_ID(generator_name, 0) FROM table_name;
The following statement fails with the error “attempted update on read-only database.”
SELECT GEN_ID(generator_name, 1) FROM table_name;
  • External files accessed through a read-only database open in read-only mode, regardless of the file’s permissions at the file system level.

Making a Database Read-only

To change the mode of a database between read-write and read-only, you must be either its owner or SYSDBA and you must have exclusive access to a database.

From within InterBase, you can change a read-write database to read-only mode in any of three ways:

  • In IBConsole, select the database, display its properties, and edit the mode. For more information, refer to Setting Database Properties.
  • Use gbak to back up the database and restore it in read-only mode:
gbak -create -mode read_only foo.ibk foo.ib
  • Use gfix to change the mode to read-only:
gfix -mode read_only foo.ib
To set a database to read-only mode from any application that uses BDE, ODBC, or JDBC, use the isc_action_svc_properties() function in the InterBase Services API.
To distribute a read-write database on a CD-ROM, back it up and put the database.ibk file on the CD-ROM. As part of the installation, restore the database to the user’s hard disk.

Read-only with Older InterBase Versions

  • A pre-6 InterBase client can access a read-only database to perform SELECT operations. No other operation succeeds.
  • If a current InterBase client tries to set a pre-6 database to read-only mode, the server silently ignores the request. There is no way to make older databases read-only. You must upgrade them.

See Also

Advance To: