开源中文网

您的位置: 首页 > 数据库应用 > Berkeley DB > 正文

Berkeley DB入门

来源:  作者:

Berkeley DB是一款开源软件,现在在Oracle旗下。本文是我初步阅读DB相关文档的笔记。以后会涉及更多细节。
Berkeley DB是由美国Sleepycat Software公司开发的一套开放源码的嵌入式数据库的程序库(database library),它为应用程序提供可伸缩的、高性能的、有事务保护功能的数据管理服务。
Berkeley DB不是关系型数据库,不是面向对象数据库,不是网络数据库,不是数据库服务器。
1.Secondary DB
相对Primary DB,用处是当想通过一些非key的Item进行检索时,激活。

2.Access Method
(1)Balanced Tree
(2)Hash
(3)Queue
(4)Recno

3.选择
(1)BTree和Hash是类关联式容器,Queue和Recno是类序列式容器。
(2)对关联式来说,如果存在复杂数据集或者Disk I/O,请选择Hash;否则选择Btree.
(3)对自己不生成Key的Record来说,序列式更加适合。Queue适合定长记录,并发性更好(Record级 Locking);Recno适合变长Record.

4.限制
总容量256TB,单条容量4GB;对网络支持能力不佳。

5.Environment
(1)Multi-databases files
在一个物理文件中,支持多个数据库
(2)多线程和多进程
(3)Transactional processing
(4)High availability (replication) support
(5)Logging subsystem

6.Exception
DB_CXX_NO_EXCEPTIONS 取消DB Exception
DbException非std::exception子类

7.Open DB
// Open the database
db.open(
NULL, // Transaction pointer
"my_db.db", // Database file name
NULL, // Optional logical database name
DB_BTREE, // Database access method
oFlags, // Open flags
0); // File mode (using defaults)

8.Close DB
// Close the database
db.close(0);

9.DB Open Flag
• DB_CREATE
If the database does not currently exist, create it. By default, the database open fails if the database does not already exist.
• DB_EXCL
Exclusive database creation. Causes the database open to fail if the database already exists. This flag is only meaningful when used with DB_CREATE.和DB_CREATE并用。
• DB_RDONLY
Open the database for read operations only. Causes any subsequent database write operations to fail.
• DB_TRUNCATE
Physically truncate (empty) the on-disk file that contains the database. Causes DB to delete all databases physically contained in that file.

10.Administrative Method
(1)Db::get_open_flags()
(2)Db::remove()
不要remove已经打开的数据库,不要remove包含打开数据库的文件。
// Database open and subsequent operations omitted for clarity
db.remove(
"mydb.db", // Database file to remove
NULL, // Database to remove. This is NULL so the entire file is removed.
0); // Flags. None used.
(3)Db::rename()
db.rename(
"mydb.db", // Database file to rename
NULL, // Database to rename. This is NULL so the entire file is renamed.
"newdb.db", // New database file name
0); // Flags. None used.

11.Error Reporting Functions
(1) set_error_stream()
(2) set_errcall()
(3) set_errfile()
(4) set_errpfx()
(5) err()
(6) errx()

Tags:Berkeley DB
关于开源中文网 - 联系我们 - 广告服务 - 网站地图 - 版权声明