Google

Berkeley DB Reference Guide:
Berkeley DB Transactional Data Store Applications

PrevRefNext

Log file removal

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 so 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.
  • a checkpoint has been written subsequent to the log file's creation.
  • 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:

  1. If you are concerned with catastrophic failure, first copy the log files to backup media as described in Archival for catastrophic recovery.

  2. Run db_archive without options to identify all the log files that are no longer in use (for example, are no longer involved in an active transaction.)

  3. 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 no longer needed by the database environment:

int
main(int argc, char *argv)
{
	/* Start a logfile removal thread. */
	if ((ret = pthread_create(
	    &ptid, NULL, logfile_thread, (void *)dbenv)) != 0) {
		fprintf(stderr,
		    "txnapp: failed spawning log file removal thread: %s\n",
		    strerror(ret));
		exit (1);
	}
}

void * logfile_thread(void *arg) { DB_ENV *dbenv; int ret; char **begin, **list;

dbenv = arg; dbenv->errx(dbenv, "Log file removal thread: %lu", (u_long)pthread_self());

/* Check once every 5 minutes. */ for (;; sleep(300)) { /* Get the list of log files. */ if ((ret = dbenv->log_archive(dbenv, &list, DB_ARCH_ABS)) != 0) { dbenv->err(dbenv, ret, "DB_ENV->log_archive"); exit (1); }

/* Remove the log files. */ if (list != NULL) { for (begin = list; *list != NULL; ++list) if ((ret = remove(*list)) != 0) { dbenv->err(dbenv, ret, "remove %s", *list); exit (1); } free (begin); } } /* NOTREACHED */ }


PrevRefNext

Copyright Sleepycat Software