Berkeley DB: Db.stat
Description: Berkeley DB: An embedded database programmatic toolkit.
Keywords: embedded,database,programmatic,toolkit,b+tree,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,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.

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 returned memory, free the returned memory reference, references inside the returned memory do not need to be individually freed.

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

Db.DB_RECORDCOUNT
  Return a count of the records in a Btree or Recno Access Method database. This flag makes it possible for applications to request a record count without incurring the performance penalty of traversing the entire database. The statistics information described for bt_nkeys below is filled in, but no other information is collected.

  This option is only available for Recno databases, or Btree databases where the underlying database was created with the Db.DB_RECNUM flag.

The Db.stat method may access all of the pages in the database, and so can incur a severe performance penalty as well as flush the underlying buffer pool.

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

The Db.stat method cannot be transaction protected. For this reason, it should be called in a thread of control that has no open cursors or active transactions.

The Db.stat method throws an exception that encapsulates a non-zero error value on failure.

### Hash Statistics

In the case of a Hash database, the statistics are returned in an instance of DbHashStat. The data fields are available from DbHashStat:

public int hash_magic;
  Magic number that identifies the file as a Hash file.
public int hash_version;
  The version of the Hash database.
public int hash_pagesize;
  The underlying Hash database page (and bucket) size.
public int hash_nrecs;
  The number of unique keys in the Hash database (since keys may have duplicates, this is not the total number of elements in the database).
public int hash_nelem;
  The estimated size of the hash table specified at database creation time.
public int hash_ffactor;
  The desired fill factor (number of items per bucket) specified at database creation time.
public int hash_buckets;
  The number of hash buckets.
public int hash_free;
  The number of pages on the free list.
public int hash_bfree;
  The number of bytes free on bucket pages.
public int hash_bigpages;
  The number of big key/data pages.
public int hash_big_bfree;
  The number of bytes free on big item pages.
public int hash_overflows;
  The number of overflow pages (overflow pages are pages that contain items that did not fit in the main bucket page).
public int hash_ovfl_free;
  The number of bytes free on overflow pages.
public int hash_dup;
  The number of duplicate pages.
public int hash_dup_free;
  The number of bytes free on duplicate pages.

### 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 database.
public int bt_version;
  The version of the Btree database.
public int bt_dup_pg;
  Number of database duplicate pages.
public int bt_dup_pgfree;
  Number of bytes free in database duplicate pages.
public int bt_free;
  Number of pages on the free list.
public int bt_int_pg;
  Number of database internal pages.
public int bt_int_pgfree;
  Number of bytes free in database internal pages.
public int bt_leaf_pg;
  Number of database leaf pages.
public int bt_leaf_pgfree;
  Number of bytes free in database leaf pages.
public int bt_levels;
  Number of levels in the database.
public int bt_minkey;
  The minimum keys per page.
public int bt_nkeys;
  For the Btree Access Method, the number of unique keys in the database.

  For the Recno Access Method, the number of records in the database. If the database has been configured to not re-number records during deletion, the number of records may include records that have been deleted.

public int bt_ndata;
  For the Btree Access Method, the number of key/data pairs in the database,

  For the Recno Access Method, the number of records in the database. If the database has been configured to not re-number records during deletion, the number of records may include records that have been deleted.

public int bt_over_pg;
  Number of database overflow pages.
public int bt_over_pgfree;
  Number of bytes free in database overflow pages.
public int bt_pagesize;
  Underlying database page size.
public int bt_re_len;
  The length of fixed-length records.
public int bt_re_pad;
  The padding byte value for fixed-length records.

### Queue Statistics

In the case of a Queue database, the statistics are returned in an instance of DbQueueStat. The data fields are available from DbQueueStat:

public int qs_magic;
  Magic number that identifies the file as a Queue file.
public int qs_version;
  The version of the Queue file type.
public int qs_nrecs;
  Number of records in the database.
public int qs_pages;
  Number of pages in the database.
public int qs_pagesize;
  Underlying database page size.
public int qs_pgfree;
  Number of bytes free in database pages.
public int qs_re_len;
  The length of the records.
public int qs_re_pad;
  The padding byte value for the records.
public int qs_start;
  Start offset.
public int qs_first_recno;
  First undeleted record in the database.
public int qs_cur_recno;
  Last allocated record number in the database.

The Db.stat method throws an exception that encapsulates a non-zero error value on failure.

# Errors

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

In addition, the Db.stat method may fail and throw an exception for errors specified for other Berkeley DB and C library or system methods.

### 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.remove, Db.set_bt_minkey, Db.set_cachesize, Db.set_errcall, Db.set_errpfx, Db.set_flags, Db.set_h_ffactor, Db.set_h_nelem, Db.set_lorder, Db.set_pagesize, Db.set_re_delim, Db.set_re_len, Db.set_re_pad, Db.set_re_source, Db.stat, Db.sync and Db.upgrade.`

Copyright Sleepycat Software