gpt4 book ai didi

c - Berkeley DB 的 db_stat 无法正常工作

转载 作者:行者123 更新时间:2023-12-05 07:07:14 27 4
gpt4 key购买 nike

我从 Oracle 下载了 Berkeley DB 5.3.2818.1.40,在 Ubuntu 18.04 上编译成功。一切都按预期工作,除了 db_stat 实用程序不想为我返回正确的数据库统计信息。特别是,没有唯一键,没有数据项等......都是错误的。

这是我的测试代码:

#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 页面,但其他方面相同。)

关于c - Berkeley DB 的 db_stat 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62254560/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com