Berkeley DB Reference Guide: Transaction Protected Applications
Description: Berkeley DB: An embedded database programmatic toolkit.
Keywords: embedded,database,programmatic,toolkit,b+tree,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,java,C,C++

### Berkeley DB Reference Guide: Transaction Protected Applications |

# Recovery and filesystem operations

When running in a transaction-protected environment, database creation and deletion are logged as stand-alone transactions internal to Berkeley DB. That is, for each such operation a new transaction is begun and aborted or committed internally, so that they will be recovered during recovery.

While the Berkeley DB API supports explicit removal of a file via the DB->remove method, Berkeley DB does not support opening a file with DB_TRUNCATE in a transaction protected environment. This is an implicit file deletion, but one that does not always require the same operating system file permissions as does deleting and creating a file. Also, there is no support for renaming a database in the API, and so there is no way to log such an activity and therefore, no way to recover a filesystem rename operation.

If you have changed the name of a file or deleted it outside of the Berkeley DB library (e.g., you explicitly removed a file using your normal operating system utilities), then it is possible that recovery will not be able to find a database referenced in the log. In this case, db_recover will produce a warning message saying it was unable to locate a file it expected to find. This message is only a warning, as the file may have been subsequently deleted as part of normal database operations before the failure occurred, and so is not necessarily a problem.

Generally, any filesystem operations that are performed outside the Berkeley DB interface should be performed at the same time as making a snapshot of the database. To perform filesystem operations correctly:

1. Cleanly shutdown database operations.

   To shutdown database operations cleanly, all applications accessing the database environment must be shutdown and a transaction checkpoint must be taken. If the applications are not implemented such that they can be shutdown gracefully (i.e., closing all references to the database environment), recovery must be performed after all applications have been killed to ensure that the underlying databases are consistent on disk.

2. Perform the filesystem operations, e.g., rename one or more files.

3. Make an archival snapshot of the database.

4. Restart the database applications.

Copyright Sleepycat Software