1<!--$Id: db_stat.so,v 10.95 2007/10/24 16:06:06 bostic Exp $-->
2<!--Copyright (c) 1997,2008 Oracle.  All rights reserved.-->
3<!--See the file LICENSE for redistribution information.-->
4<html>
5<head>
6<title>Berkeley DB: Db::stat</title>
7<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
8<meta name="keywords" content="embedded,database,programmatic,toolkit,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++">
9</head>
10<body bgcolor=white>
11<table width="100%"><tr valign=top>
12<td>
13<b>Db::stat</b>
14</td>
15<td align=right>
16<a href="../api_cxx/api_core.html"><img src="../images/api.gif" alt="API"></a>
17<a href="../ref/toc.html"><img src="../images/ref.gif" alt="Ref"></a></td>
18</tr></table>
19<hr size=1 noshade>
20<tt>
21<b><pre>
22#include &lt;db_cxx.h&gt;
23<p>
24int
25Db::stat(DbTxn *txnid, void *sp, u_int32_t flags);
26<p>
27int
28Db::stat_print(u_int32_t flags);
29</pre></b>
30<hr size=1 noshade>
31<b>Description: Db::stat</b>
32<p>The Db::stat method creates a statistical structure and copies a
33pointer to it into user-specified memory locations.  Specifically, if
34<b>sp</b> is non-NULL, a pointer to the statistics for the database are
35copied into the memory location to which it refers.</p>
36<b>Parameters</b> <br>
37 <b>flags</b><ul compact><li>The <b>flags</b> parameter must be set to 0 or
38one of the following values:
39<br>
40<b><a name="DB_FAST_STAT">DB_FAST_STAT</a></b><ul compact><li>Return only the values which do not require traversal of the database.
41Among other things, this flag makes it possible for applications to
42request key and record counts without incurring the performance penalty
43of traversing the entire database.</ul>
44<b><a name="DB_READ_COMMITTED">DB_READ_COMMITTED</a></b><ul compact><li>Database items read during a transactional call will have degree 2
45isolation.  This ensures the stability of the data items read during the
46stat operation but permits that data to be modified or deleted by other
47transactions prior to the commit of the specified transaction.</ul>
48<b><a name="DB_READ_UNCOMMITTED">DB_READ_UNCOMMITTED</a></b><ul compact><li>Database items read during a transactional call will have degree 1
49isolation, including modified but not yet committed data.  Silently
50ignored if the <a href="../api_cxx/db_open.html#DB_READ_UNCOMMITTED">DB_READ_UNCOMMITTED</a> flag was not specified when
51the underlying database was opened.</ul> <br></ul>
52 <b>txnid</b><ul compact><li>If the operation is part of an application-specified transaction, the
53<b>txnid</b> parameter is a transaction handle returned from
54<a href="../api_cxx/txn_begin.html">DbEnv::txn_begin</a>; if the operation is part of a Berkeley DB Concurrent Data Store group, the
55<b>txnid</b> parameter is a handle returned from
56<a href="../api_cxx/env_cdsgroup_begin.html">DbEnv::cdsgroup_begin</a>; otherwise NULL.
57If no transaction handle is
58specified, but the
59operation occurs in a transactional
60database,
61the operation will be implicitly transaction protected.
62</ul>
63<br>
64<p>Statistical structures are stored in allocated memory.  If application-specific allocation
65routines have been declared (see <a href="../api_cxx/env_set_alloc.html">DbEnv::set_alloc</a> for more
66information), they are used to allocate the memory; otherwise, the
67standard C library <b>malloc</b>(3) is used.  The caller is
68responsible for deallocating the memory.  To deallocate the memory, free
69the memory reference; references inside the returned memory need not be
70individually freed.</p>
71<p>If the DB_FAST_STAT flag has not been specified, the
72Db::stat method will access some of or all the pages in the database,
73incurring a severe performance penalty as well as possibly flushing the
74underlying buffer pool.</p>
75<p>In the presence of multiple threads or processes accessing an active
76database, the information returned by Db::stat may be out-of-date.</p>
77<p>If the database was not opened read-only and the DB_FAST_STAT
78flag was not specified, the cached key and record numbers will be
79updated after the statistical information has been gathered.</p>
80<p>The Db::stat method may not be called before the <a href="../api_cxx/db_open.html">Db::open</a> method is called.</p>
81<p>The Db::stat method
82either returns a non-zero error value
83or throws an exception that encapsulates a non-zero error value on
84failure, and returns 0 on success.
85</p>
86<b>Hash Statistics</b>
87<p>In the case of a Hash database, the statistics are stored in a structure
88of type DB_HASH_STAT.  The following fields will be filled in:</p>
89<br>
90<b>u_int32_t hash_magic;</b><ul compact><li>Magic number that identifies the file as a Hash file.  Returned if
91DB_FAST_STAT is set.</ul>
92<b>u_int32_t hash_version;</b><ul compact><li>The version of the Hash database.  Returned if DB_FAST_STAT is
93set.</ul>
94<b>u_int32_t hash_nkeys;</b><ul compact><li>The number of unique keys in the database.  If DB_FAST_STAT was
95specified the count will be the last saved value unless it has never
96been calculated, in which case it will be 0. Returned if
97DB_FAST_STAT is set.</ul>
98<b>u_int32_t hash_ndata;</b><ul compact><li>The number of key/data pairs in the database.  If DB_FAST_STAT
99was specified the count will be the last saved value unless it has never
100been calculated, in which case it will be 0. Returned if
101DB_FAST_STAT is set.</ul>
102<b>u_int32_t hash_pagecnt;</b><ul compact><li>The number of pages in the database.  Returned if DB_FAST_STAT
103is set.</ul>
104<b>u_int32_t hash_pagesize;</b><ul compact><li>The underlying database page (and bucket) size, in bytes.  Returned if
105DB_FAST_STAT is set.</ul>
106<b>u_int32_t hash_ffactor;</b><ul compact><li>The desired fill factor (number of items per bucket) specified at
107database-creation time.  Returned if DB_FAST_STAT is set.</ul>
108<b>u_int32_t hash_buckets;</b><ul compact><li>The number of hash buckets.  Returned if DB_FAST_STAT is set.</ul>
109<b>u_int32_t hash_free;</b><ul compact><li>The number of pages on the free list.</ul>
110<b>u_int32_t hash_bfree;</b><ul compact><li>The number of bytes free on bucket pages.</ul>
111<b>u_int32_t hash_bigpages;</b><ul compact><li>The number of big key/data pages.</ul>
112<b>u_int32_t hash_big_bfree;</b><ul compact><li>The number of bytes free on big item pages.</ul>
113<b>u_int32_t hash_overflows;</b><ul compact><li>The number of overflow pages (overflow pages are pages that contain items
114that did not fit in the main bucket page).</ul>
115<b>u_int32_t hash_ovfl_free;</b><ul compact><li>The number of bytes free on overflow pages.</ul>
116<b>u_int32_t hash_dup;</b><ul compact><li>The number of duplicate pages.</ul>
117<b>u_int32_t hash_dup_free;</b><ul compact><li>The number of bytes free on duplicate pages.</ul>
118<br>
119<b>Btree and Recno Statistics</b>
120<p>In the case of a Btree or Recno database, the statistics are stored in
121a structure of type DB_BTREE_STAT.  The following fields will be filled
122in:</p>
123<br>
124<b>u_int32_t bt_magic;</b><ul compact><li>Magic number that identifies the file as a Btree database.  Returned
125if DB_FAST_STAT is set.</ul>
126<b>u_int32_t bt_version;</b><ul compact><li>The version of the Btree database.  Returned if DB_FAST_STAT
127is set.</ul>
128<b>u_int32_t bt_nkeys;</b><ul compact><li>For the Btree Access Method, the number of keys in the database.  If
129the DB_FAST_STAT flag is not specified or the database was
130configured to support record numbers (see <a href="../api_cxx/db_set_flags.html#DB_RECNUM">DB_RECNUM</a>), the count
131will be exact.  Otherwise, the count will be the last saved value unless
132it has never been calculated, in which case it will be 0.
133<p>For the Recno Access Method, the number of records in the database.  If
134the database was configured with mutable record numbers (see
135<a href="../api_cxx/db_set_flags.html#DB_RENUMBER">DB_RENUMBER</a>), the count will be exact.  Otherwise, if the
136DB_FAST_STAT flag is specified the count will be exact but will
137include deleted and implicitly created records; if the
138DB_FAST_STAT flag is not specified, the count will be exact and
139will not include deleted or implicitly created records.</p>
140<p>Returned if DB_FAST_STAT is set.</p></ul>
141<b>u_int32_t bt_ndata;</b><ul compact><li>For the Btree Access Method, the number of key/data pairs in the
142database.  If the DB_FAST_STAT flag is not specified, the count
143will be exact.  Otherwise, the count will be the last saved value unless
144it has never been calculated, in which case it will be 0.
145<p>For the Recno Access Method, the number of records in the database.  If
146the database was configured with mutable record numbers (see
147<a href="../api_cxx/db_set_flags.html#DB_RENUMBER">DB_RENUMBER</a>), the count will be exact.  Otherwise, if the
148DB_FAST_STAT flag is specified the count will be exact but will
149include deleted and implicitly created records; if the
150DB_FAST_STAT flag is not specified, the count will be exact and
151will not include deleted or implicitly created records.</p>
152<p>Returned if DB_FAST_STAT is set.</p></ul>
153<b>u_int32_t bt_pagecnt;</b><ul compact><li>The number of pages in the database.  Returned if DB_FAST_STAT
154is set.</ul>
155<b>u_int32_t bt_pagesize;</b><ul compact><li>The underlying database page size, in bytes.  Returned if
156DB_FAST_STAT is set.</ul>
157<b>u_int32_t bt_minkey;</b><ul compact><li>The minimum keys per page.  Returned if DB_FAST_STAT is set.</ul>
158<b>u_int32_t bt_re_len;</b><ul compact><li>The length of fixed-length records.  Returned if DB_FAST_STAT
159is set.</ul>
160<b>u_int32_t bt_re_pad;</b><ul compact><li>The padding byte value for fixed-length records.  Returned if
161DB_FAST_STAT is set.</ul>
162<b>u_int32_t bt_levels;</b><ul compact><li>Number of levels in the database.</ul>
163<b>u_int32_t bt_int_pg;</b><ul compact><li>Number of database internal pages.</ul>
164<b>u_int32_t bt_leaf_pg;</b><ul compact><li>Number of database leaf pages.</ul>
165<b>u_int32_t bt_dup_pg;</b><ul compact><li>Number of database duplicate pages.</ul>
166<b>u_int32_t bt_over_pg;</b><ul compact><li>Number of database overflow pages.</ul>
167<b>u_int32_t bt_empty_pg;</b><ul compact><li>Number of empty database pages.</ul>
168<b>u_int32_t bt_free;</b><ul compact><li>Number of pages on the free list.</ul>
169<b>u_int32_t bt_int_pgfree;</b><ul compact><li>Number of bytes free in database internal pages.</ul>
170<b>u_int32_t bt_leaf_pgfree;</b><ul compact><li>Number of bytes free in database leaf pages.</ul>
171<b>u_int32_t bt_dup_pgfree;</b><ul compact><li>Number of bytes free in database duplicate pages.</ul>
172<b>u_int32_t bt_over_pgfree;</b><ul compact><li>Number of bytes free in database overflow pages.</ul>
173<br>
174<b>Queue Statistics</b>
175<p>In the case of a Queue database, the statistics are stored in a
176structure of type DB_QUEUE_STAT.  The following fields will be filled
177in:</p>
178<br>
179<b>u_int32_t qs_magic;</b><ul compact><li>Magic number that identifies the file as a Queue file.  Returned if
180DB_FAST_STAT is set.</ul>
181<b>u_int32_t qs_version;</b><ul compact><li>The version of the Queue file type.  Returned if DB_FAST_STAT
182is set.</ul>
183<b>u_int32_t qs_nkeys;</b><ul compact><li>The number of records in the database.  If DB_FAST_STAT was
184specified the count will be the last saved value unless it has never
185been calculated, in which case it will be 0.  Returned if
186DB_FAST_STAT is set.</ul>
187<b>u_int32_t qs_ndata;</b><ul compact><li>The number of records in the database.  If DB_FAST_STAT was
188specified the count will be the last saved value unless it has never
189been calculated, in which case it will be 0.  Returned if
190DB_FAST_STAT is set.</ul>
191<b>u_int32_t qs_pagesize;</b><ul compact><li>Underlying database page size, in bytes.  Returned if
192DB_FAST_STAT is set.</ul>
193<b>u_int32_t qs_extentsize;</b><ul compact><li>Underlying database extent size, in pages.  Returned if
194DB_FAST_STAT is set.</ul>
195<b>u_int32_t qs_pages;</b><ul compact><li>Number of pages in the database.</ul>
196<b>u_int32_t qs_re_len;</b><ul compact><li>The length of the records.  Returned if DB_FAST_STAT is set.</ul>
197<b>u_int32_t qs_re_pad;</b><ul compact><li>The padding byte value for the records.  Returned if
198DB_FAST_STAT is set.</ul>
199<b>u_int32_t qs_pgfree;</b><ul compact><li>Number of bytes free in database pages.</ul>
200<b>u_int32_t qs_first_recno;</b><ul compact><li>First undeleted record in the database.  Returned if
201DB_FAST_STAT is set.</ul>
202<b>u_int32_t qs_cur_recno;</b><ul compact><li>Next available record number.  Returned if DB_FAST_STAT is set.</ul>
203<br>
204<br><b>Errors</b>
205<p>The Db::stat method
206may fail and throw
207<a href="../api_cxx/except_class.html">DbException</a>,
208encapsulating one of the following non-zero errors, or return one of
209the following non-zero errors:</p>
210<br>
211<b>DB_REP_HANDLE_DEAD</b><ul compact><li>The database handle has been invalidated because a replication election
212unrolled a committed transaction.</ul>
213<br>
214<br>
215<b>DB_REP_LOCKOUT</b><ul compact><li>The operation was blocked by client/master synchronization.</ul>
216<br>
217<br>
218<b>EINVAL</b><ul compact><li>An
219invalid flag value or parameter was specified.</ul>
220<br>
221<hr size=1 noshade>
222<b>Description: Db::stat_print</b>
223<p>The Db::stat_print method displays the
224database statistical information, as described for the Db::stat method.
225The information is printed to a specified output channel (see the
226<a href="../api_cxx/env_set_msgfile.html">DbEnv::set_msgfile</a> method for more information), or passed to an
227application callback function (see the <a href="../api_cxx/env_set_msgcall.html">DbEnv::set_msgcall</a> method for
228more information).</p>
229<p>The Db::stat_print method may not be called before the <a href="../api_cxx/db_open.html">Db::open</a> method is called.</p>
230<p>The Db::stat_print method
231either returns a non-zero error value
232or throws an exception that encapsulates a non-zero error value on
233failure, and returns 0 on success.
234</p>
235<b>Parameters</b> <br>
236 <b>flags</b><ul compact><li>The <b>flags</b> parameter must be set to 0 or by bitwise inclusively <b>OR</b>'ing together one
237or more of the following values:
238<br>
239<b><a name="DB_FAST_STAT">DB_FAST_STAT</a></b><ul compact><li>Return only the values which do not require traversal of the database.
240Among other things, this flag makes it possible for applications to
241request key and record counts without incurring the performance penalty
242of traversing the entire database.</ul>
243<b><a name="DB_STAT_ALL">DB_STAT_ALL</a></b><ul compact><li>Display all available information.</ul>
244<br></ul>
245<br>
246<hr size=1 noshade>
247<br><b>Class</b>
248<a href="../api_cxx/db_class.html">Db</a>
249<br><b>See Also</b>
250<a href="../api_cxx/db_list.html">Databases and Related Methods</a>
251</tt>
252<table width="100%"><tr><td><br></td><td align=right>
253<a href="../api_cxx/api_core.html"><img src="../images/api.gif" alt="API"></a><a href="../ref/toc.html"><img src="../images/ref.gif" alt="Ref"></a>
254</td></tr></table>
255<p><font size=1>Copyright (c) 1996,2008 Oracle.  All rights reserved.</font>
256</body>
257</html>
258