The fourth component of the infrastructure, log file removal, concerns
the ongoing disk consumption of the database log files. Depending on
the rate at which the application writes to the databases and the
available disk space, the number of log files may increase quickly
enough that disk space will be a resource problem. For this reason,
you will periodically want to remove log files in order to conserve disk
space. This procedure is distinct from database and log file archival
for catastrophic recovery, and you cannot remove the current log files
simply because you have created a database snapshot or copied log files
to archival media.
Log files may be removed at any time, as long as:
the log file is not involved in an active transaction
at least two checkpoints have been written subsequent to the
log file's creation, and
the log file is not the only log file in the environment.
Obviously, if you are preparing for catastrophic failure, you will want
to copy the log files to archival media before you remove them.
To remove log files, take the following steps:
If you are concerned with catastrophic failure, first copy the log files
to backup media as described in Archival for
catastrophic recovery.
Run db_archive without options to identify all of the log files
that are no longer in use (e.g., no longer involved in an active
transaction).
Remove those log files from the system.
The functionality provided by the db_archive utility is also
available directly from the Berkeley DB library. The following code fragment
removes log files that are no longer needed by the database
environment.
/* Check once every 5 minutes. */
for (;; sleep(300)) {
/* Get the list of log files. */
if ((ret = log_archive(dbenv, &list, DB_ARCH_ABS, NULL)) != 0) {
dbenv->err(dbenv, ret, "log_archive");
exit (1);
}