db_stat Berkeley DB 无法正常工作
db_stat not working correctly for Berkeley DB
我从 Oracle 下载了 Berkeley DB 5.3.28
和 18.1.40
,并在 Ubuntu 18.04 上成功编译。一切都按预期工作,除了 db_stat
实用程序不想 return 为我更正数据库统计信息。特别是没有唯一键,没有数据项等等都是错误的。
这是我的测试代码:
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <db.h>
int main() {
DB *dbp;
DBT key, data;
int ret, t_ret;
ret = db_create(&dbp, NULL, 0);
assert(ret == 0);
ret = dbp->open(dbp, NULL, "sample.db", "", DB_BTREE, DB_CREATE, 0664);
assert(ret == 0);
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
key.data = (char*)"fruit";
key.size = sizeof("fruit");
data.data = (char*)"apple";
data.size = sizeof("apple");
ret = dbp->put(dbp, NULL, &key, &data, 0);
assert(ret == 0);
key.data = (char*)"color";
key.size = sizeof("color");
data.data = (char*)"red";
data.size = sizeof("red");
ret = dbp->put(dbp, NULL, &key, &data, 0);
assert(ret == 0);
key.data = (char*)"language";
key.size = sizeof("language");
data.data = (char*)"c";
data.size = sizeof("c");
ret = dbp->put(dbp, NULL, &key, &data, 0);
assert(ret == 0);
dbp->close(dbp, 0);
}
db_stat 输出:
db_stat -d sample.db
Sun Jun 7 20:26:59 2020 Local time
53162 Btree magic number
9 Btree version number
Little-endian Byte order
multiple-databases Flags
2 Minimum keys per-page
4096 Underlying database page size
1007 Overflow key/data size
1 Number of levels in the tree
1 Number of unique keys in the tree
1 Number of data items in the tree
0 Number of tree internal pages
0 Number of bytes free in tree internal pages (0% ff)
1 Number of tree leaf pages
4054 Number of bytes free in tree leaf pages (1% ff)
0 Number of tree duplicate pages
0 Number of bytes free in tree duplicate pages (0% ff)
0 Number of tree overflow pages
0 Number of bytes free in tree overflow pages (0% ff)
0 Number of empty pages
0 Number of pages on the free list
您在 dbp->open
调用中将数据库命名为 ""
。因此,您也必须使用 -s
标志将其传递给 db_stat
:
$ db_stat -d sample.db -s ""
Wed Jun 10 03:16:43 2020 Local time
53162 Btree magic number
9 Btree version number
Little-endian Byte order
record-numbers, multiple-databases Flags
2 Minimum keys per-page
8192 Underlying database page size
2031 Overflow key/data size
1 Number of levels in the tree
3 Number of unique keys in the tree
3 Number of data items in the tree
0 Number of tree internal pages
0 Number of bytes free in tree internal pages (0% ff)
1 Number of tree leaf pages
8090 Number of bytes free in tree leaf pages (1% ff)
0 Number of tree duplicate pages
0 Number of bytes free in tree duplicate pages (0% ff)
0 Number of tree overflow pages
0 Number of bytes free in tree overflow pages (0% ff)
0 Number of empty pages
0 Number of pages on the free list
(我的 BDB 默认为 8K 页面,但其他方面相同。)
我从 Oracle 下载了 Berkeley DB 5.3.28
和 18.1.40
,并在 Ubuntu 18.04 上成功编译。一切都按预期工作,除了 db_stat
实用程序不想 return 为我更正数据库统计信息。特别是没有唯一键,没有数据项等等都是错误的。
这是我的测试代码:
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <db.h>
int main() {
DB *dbp;
DBT key, data;
int ret, t_ret;
ret = db_create(&dbp, NULL, 0);
assert(ret == 0);
ret = dbp->open(dbp, NULL, "sample.db", "", DB_BTREE, DB_CREATE, 0664);
assert(ret == 0);
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
key.data = (char*)"fruit";
key.size = sizeof("fruit");
data.data = (char*)"apple";
data.size = sizeof("apple");
ret = dbp->put(dbp, NULL, &key, &data, 0);
assert(ret == 0);
key.data = (char*)"color";
key.size = sizeof("color");
data.data = (char*)"red";
data.size = sizeof("red");
ret = dbp->put(dbp, NULL, &key, &data, 0);
assert(ret == 0);
key.data = (char*)"language";
key.size = sizeof("language");
data.data = (char*)"c";
data.size = sizeof("c");
ret = dbp->put(dbp, NULL, &key, &data, 0);
assert(ret == 0);
dbp->close(dbp, 0);
}
db_stat 输出:
db_stat -d sample.db
Sun Jun 7 20:26:59 2020 Local time
53162 Btree magic number
9 Btree version number
Little-endian Byte order
multiple-databases Flags
2 Minimum keys per-page
4096 Underlying database page size
1007 Overflow key/data size
1 Number of levels in the tree
1 Number of unique keys in the tree
1 Number of data items in the tree
0 Number of tree internal pages
0 Number of bytes free in tree internal pages (0% ff)
1 Number of tree leaf pages
4054 Number of bytes free in tree leaf pages (1% ff)
0 Number of tree duplicate pages
0 Number of bytes free in tree duplicate pages (0% ff)
0 Number of tree overflow pages
0 Number of bytes free in tree overflow pages (0% ff)
0 Number of empty pages
0 Number of pages on the free list
您在 dbp->open
调用中将数据库命名为 ""
。因此,您也必须使用 -s
标志将其传递给 db_stat
:
$ db_stat -d sample.db -s ""
Wed Jun 10 03:16:43 2020 Local time
53162 Btree magic number
9 Btree version number
Little-endian Byte order
record-numbers, multiple-databases Flags
2 Minimum keys per-page
8192 Underlying database page size
2031 Overflow key/data size
1 Number of levels in the tree
3 Number of unique keys in the tree
3 Number of data items in the tree
0 Number of tree internal pages
0 Number of bytes free in tree internal pages (0% ff)
1 Number of tree leaf pages
8090 Number of bytes free in tree leaf pages (1% ff)
0 Number of tree duplicate pages
0 Number of bytes free in tree duplicate pages (0% ff)
0 Number of tree overflow pages
0 Number of bytes free in tree overflow pages (0% ff)
0 Number of empty pages
0 Number of pages on the free list
(我的 BDB 默认为 8K 页面,但其他方面相同。)