Berkeley DB: Db.stat
Description: Berkeley DB: An embedded database programmatic toolkit.
Keywords: embedded,database,programmatic,toolkit,b+tree,btr ee,hash,hashing,transaction,transactions,locking,logging,access method,access me thods,java,C,C++

# Db.stat

`

###

    import com.sleepycat.db.*;

    public Object Db.stat(int flags);

# Description

The Db.stat method creates a statistical structure and fills it with statistics for the database.

The Db.stat method 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 method 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.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 method throws an exception that encapsulates an errno on failure.

# Btree and Recno Statistics

In the case of a Btree or Recno database, the statistics are returned in an instance of DbBtreeStat. The data fields are available from DbBtreeStat:

public int bt_magic;
  Magic number that identifies the file as a btree file.
public int bt_version;
  The version of the btree file type.
public int bt_flags;
  Permanent database flags, including DB_DUP, DB_FIXEDLEN, DB_RECNUM and DB_RENUMBER.
public int bt_minkey;
  The bt_minkey value specified to Db.open, if any.
public int bt_re_len;
  The re_len value specified to Db.open, if any.
public int bt_re_pad;
  The re_pad value specified to Db.open, if any.
public int bt_pagesize;
  Underlying tree page size.
public int bt_levels;
  Number of levels in the tree.
public int 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).
public int bt_int_pg;
  Number of tree internal pages.
public int bt_leaf_pg;
  Number of tree leaf pages.
public int bt_dup_pg;
  Number of tree duplicate pages.
public int bt_over_pg;
  Number of tree overflow pages.
public int bt_free;
  Number of pages on the free list.
public int bt_int_pgfree;
  Number of bytes free in tree internal pages.
public int bt_leaf_pgfree;
  Number of bytes free in tree leaf pages.
public int bt_dup_pgfree;
  Number of bytes free in tree duplicate pages.
public int bt_over_pgfree;
  Number of bytes free in tree overflow pages.

The Db.stat method throws an exception that encapsulates an errno on failure.

# Errors

If a fatal error occurs in Berkeley DB, the Db.stat method may fail and throw a DbRunRecoveryException, at which point all subsequent database calls will also fail in the same way.

The Db.stat method may fail and throw an exception 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), DbLockTab.get, DbLock.put, DbLockTab.vec, malloc(3), DbMpoolFile.get, DbMpoolFile.put, memset(3), strerror(3), vfprintf(3), and vsnprintf(3).

# Class

Db

# See Also

Db.close, Db.cursor, Db.del, Db.fd, Db.get, Db.get_byteswapped, Db.get_type, Db.join, Db.open, Db.put, Db.stat and Db.sync.`