DB->compact(DB *db, DB_TXN *txnid,
DBT *start, DBT *stop, DB_COMPACT *c_data, u_int32_t flags, DBT *end);
The DB->compact method compacts Btree and Recno access method
databases, and optionally returns unused Btree, Hash or Recno database
pages to the underlying filesystem.
The DB->compact method
returns a non-zero error value on failure
and 0 on success.
- If the operation is part of an application-specified
transaction, the txnid parameter is a transaction handle
returned from DB_ENV->txn_begin; otherwise NULL. If no transaction
handle is specified, but the
operation occurs in a transactional
the operation will be implicitly transaction protected.
- If non-NULL, the start parameter is the starting point for
compaction in a Btree or Recno database. Compaction will start at the
smallest key greater than or equal to the specified key. If NULL,
compaction will start at the beginning of the database.
- If non-NULL, the stop parameter is the stopping point for
compaction in a Btree or Recno database. Compaction will stop at the
page with the smallest key greater than the specified key. If NULL,
compaction will stop at the end of the database.
If non-NULL, the c_data parameter contains additional compaction
configuration parameters, and returns compaction operation statistics,
in a structure of type DB_COMPACT.
The following input configuration fields are available from the
- int compact_fillpercent;
- If non-zero, the goal for filling pages, specified as a percentage
between 1 and 100. Any page in a Btree or Recno databases not at or
above this percentage full will be considered for compaction. The
default behavior is to consider every page for compaction, regardless
of its page fill percentage.
- db_timeout_t compact_timeout;
- If non-zero, and no txnid parameter was specified, the lock
timeout set for implicit transactions, in microseconds.
The following output statistics fields are available from the
- u_int32_t compact_deadlock;
- An output statistics parameter: if no txnid parameter was
specified, the number of deadlocks which occurred.
- u_int32_t compact_levels;
- An output statistics parameter: the number of levels removed from the
Btree or Recno database during the compaction phase.
- u_int32_t compact_pages_free;
- An output statistics parameter: the number of database pages free during
the compaction phase.
- u_int32_t compact_pages_examine;
- An output statistics parameter: the number of database pages reviewed
during the compaction phase.
- u_int32_t compact_pages_truncated;
- An output statistics parameter: the number of database pages returned
to the filesystem.
- The flags parameter must be set to 0 or
one of the following values:
- Do no page compaction, only returning pages to the filesystem that are
already free and at the end of the file. This flag must be set if the
database is a Hash access method database.
- Return pages to the filesystem if possible. If this flag is not
specified, pages emptied as a result of compaction will be placed on the
free list for re-use, but not returned to the filesystem.
- If non-NULL, the end parameter will be filled in with the key
marking the end of the compaction operation in a Btree or Recno
The DB->compact method
may fail and return one of the following non-zero errors:
- A transactional database environment operation was selected to resolve
- A Berkeley DB Concurrent Data Store database environment configured for lock timeouts was unable
to grant a lock in the allowed time.
- The database handle has been invalidated because a replication election
unrolled a committed transaction.
- The operation was blocked by client/master synchronization.
- An attempt was made to modify a read-only database.
invalid flag value or parameter was specified.
Databases and Related Methods
Copyright (c) 1996-2005 Sleepycat Software, Inc. - All rights reserved.