Berkeley DB: DB->stat
Google

ee,hash,hashing,transaction,transactions,locking,logging,access method,access me thods,java,C,C++">

DB->stat


#include <db.h>

int DB->stat(DB *db, void *sp, void *(*db_malloc)(size_t), u_int32_t flags);

Description

The DB->stat function creates a statistical structure and copies a pointer to it into user-specified memory locations. Specifically, if sp is non-NULL, a pointer to the statistics for the database are copied into the memory location it references.

Statistical structures are created in allocated memory. If db_malloc is non-NULL, it is called to allocate the memory, otherwise, the library function malloc(3)) is used. The function db_malloc must match the calling conventions of the malloc(3)) library routine. Regardless, the caller is responsible for deallocating the returned memory. To deallocate the returned memory, free each returned memory pointer; pointers inside the memory do not need to be individually freed.

The DB->stat function cannot be transaction protected, and, should be done outside of the scope of a transaction.

In the presence of multiple threads or processes accessing an active database, the returned information may be out-of-date.

This function may access all of the pages in the database, and therefore may incur a severe performance penalty and have obvious negative effects on the underlying buffer pool.

The flags parameter must be set to 0 or the following value:

DB_RECORDCOUNT
Fill in the bt_nrecs information of the statistics structure, but do not collect any other information. This flag makes it reasonable for applications to request a record count from a database without incurring a performance penalty. It is only available for Recno databases, or Btree databases where the underlying database was created with the DB_RECNUM flag.

The DB->stat function returns the value of errno on failure, and 0 on success.

Btree and Recno Statistics

In the case of a Btree or Recno database, the statistics are stored in a structure of type DB_BTREE_STAT. The following fields will be filled in:

u_int32_t bt_magic;
Magic number that identifies the file as a btree file.
u_int32_t bt_version;
The version of the btree file type.
u_int32_t bt_flags;
Permanent database flags, including DB_DUP, DB_FIXEDLEN, DB_RECNUM and DB_RENUMBER.
u_int32_t bt_minkey;
The bt_minkey value specified to db_open, if any.
u_int32_t bt_re_len;
The re_len value specified to db_open, if any.
u_int32_t bt_re_pad;
The re_pad value specified to db_open, if any.
u_int32_t bt_pagesize;
Underlying tree page size.
u_int32_t bt_levels;
Number of levels in the tree.
u_int32_t bt_nrecs;
Number of data items in the tree (since there may be multiple data items per key, this number may not be the same as the number of keys).
u_int32_t bt_int_pg;
Number of tree internal pages.
u_int32_t bt_leaf_pg;
Number of tree leaf pages.
u_int32_t bt_dup_pg;
Number of tree duplicate pages.
u_int32_t bt_over_pg;
Number of tree overflow pages.
u_int32_t bt_free;
Number of pages on the free list.
u_int32_t bt_int_pgfree;
Number of bytes free in tree internal pages.
u_int32_t bt_leaf_pgfree;
Number of bytes free in tree leaf pages.
u_int32_t bt_dup_pgfree;
Number of bytes free in tree duplicate pages.
u_int32_t bt_over_pgfree;
Number of bytes free in tree overflow pages.

The DB->stat function returns the value of errno on failure, and 0 on success.

Errors

If a fatal error occurs in Berkeley DB, the DB->stat function may fail and return DB_RUNRECOVERY, at which point all subsequent database calls will also return DB_RUNRECOVERY.

The DB->stat function may fail and return errno for any of the errors specified for the following Berkeley DB and C library functions: DB->cursor, DBcursor->c_close(3), dbenv->db_paniccall(3), fflush(3), fprintf(3), lock_get, lock_put, lock_vec, malloc(3), memp_fget, memp_fput, memset(3), strerror(3), vfprintf(3), and vsnprintf(3).

See Also

db_appexit, db_appinit, db_version, DB->close, DB->cursor, DB->del, DB->fd, DB->get, DB->join, db_open, DB->put, DB->stat, DB->sync, DBcursor->c_close, DBcursor->c_del, DBcursor->c_get and DBcursor->c_put.