Viewing Berkeley DB files

If you have .db files on a Linux system, they may be Berkeley DB (BDB) database files. Berkeley DB originated at the University of California, Berkeley as part of BSD, Berkeley's version of the Unix operating system. The initial release was in 1994. Berkely DB was futher developed by SleepyCat Software from 1996 to 2006. In February 2006, Oracle Corporation acquired SleepyCat and continued development of the software.

You can ascertain if a .db file is a BDB file using the file command. E.g., the Sendmail email software uses .db files stored in /etc/mail to control various aspects of the software's functionality. For instance, you can specify the domains for which Sendmail will accept email in the /etc/mail/local-host-names file or create "virtual users" using the /etc/mail/virtusertable file. But to alter Sendmail's behavior using these files, you need to generate .db files from the text files using the makemap command. E.g., makemap hash /etc/mail/virtusertable < /etc/mail/virtusertable. If you check the type of file for the .db file that will be created by the makemap utility with the file command, you will see the following information, if you check from the root account:

# file /etc/mail/virtusertable.db
/etc/mail/virtusertable.db: Berkeley DB (Hash, version 9, native byte-order)
#

Since a normal user account doesn't have read permission for that .db file, you will see the message below, if you check from a regular user account:

$ file /etc/mail/virtusertable.db
/etc/mail/virtusertable.db: regular file, no read permission
$ ls -l /etc/mail/virtusertable.db
-rw-r-----. 1 root root 12288 Aug 19 12:41 /etc/mail/virtusertable.db
$

Supposing you need to read the contents of a .db file, how do you do it? You can use the db_dump command, which is a command line interface (CLI) tool. You can determine if the utility is on the system using the which command.

$ which db_dump
/usr/bin/db_dump
$

On a CentOS 7 Linux system, the utility is provided with the libdb-utils package, which can be installed with yum install libdb-utils, if it is not present and you use yum for package management.

$ rpm -q --whatprovides /usr/bin/db_dump
libdb-utils-5.3.21-17.el7_0.1.x86_64

You may also find the utility in a db_utils or db4-utils package.

To view the records in a .db database with the db_dump command you can issue a command in the form db_dump -p db_file where db_file is the relevant .db file. E.g., suppose I have a virtusertable file with the following contents:

# cat /etc/mail/virtusertable
debbie@example.com	dsahlin
pam@example.com		pcullen
gdavis@example.com	gregg
jgarland@example.com	jan
#

If I view the contents of the .db file generated by makemap hash /etc/mail/virtusertable < /etc/mail/virtusertable using the db_dump command, I see the following. The database records start after the "HEADER=END" line.

# db_dump -p /etc/mail/virtusertable.db
VERSION=3
format=print
type=hash
h_nelem=4100
db_pagesize=4096
HEADER=END
 debbie@example.com
 dsahlin
 jgarland@example.com
 jan
 gdavis@example.com
 gregg
 pam@example.com
 pcullen
DATA=END
#

If you don't specify the -p option with the dp_dump command, you will see the data displayed in hexadecimal form, which for most people won't be easy to interpret. E.g., I would see the following, instead:

# db_dump /etc/mail/virtusertable.db
VERSION=3
format=bytevalue
type=hash
h_nelem=4100
db_pagesize=4096
HEADER=END
 646562626965406578616d706c652e636f6d
 647361686c696e
 6a6761726c616e64406578616d706c652e636f6d
 6a616e
 676461766973406578616d706c652e636f6d
 6772656767
 70616d406578616d706c652e636f6d
 7063756c6c656e
DATA=END
#

In the case of the Sendmail .db files, if you have the original text files, you can always regenerate the .db files, but if one of those files is accidentally deleted or corrupted, you can use the db_dump command to recreate it by viewing the records in the database using that command.

 

TechRabbit ad 300x250 newegg.com

Justdeals Daily Electronics Deals1x1 px