Installing Berkeley DB 11gR2 11.2.5.0.26 on Oracle Enterprise Linux

Berkeley DB is a general purpose embedded database engine that provides data management features found in enterprise class databases. Berkeley DB is used in various applications ranging from cell phones to e-commerce systems. Included in the 11gR2 version of Berkeley DB is a SQLite compatible SQL API.

Berkeley DB 11gR2 is a zero administration database engine. All administration duties are performed via API calls so no Database Administrator is required. API’s are available for many programming languages including C/C++, Java, Perl and Ruby.

This document will detail the build and installation of Berkeley DB 11gR2 11.2.5.0.26 on Oracle Enterprise Linux along with creation of a database using the Berkeley DB SQL Interface.

Download build and install Berkeley DB 11gR2

Berkeley DB 11gR2 can be downloaded from The Oracle Technology Network (OTN). Download Berkeley DB 5.0.26.tar.gz, with AES encryption.

Extract the archive db-5.0.26.tar.gz and switch to the directory db-5.0.26/build_unix.

There are more than 20 configuration options that can be passed to customize the build of Berkeley DB on your system. A complete list of the configuration options can be found in the installation documentation set located in db-5.0.25/docs/installation/build_unix_conf.html. For this document we will build the core Berkeley DB runtime including C/C++ development, C++ STL, Java and the Berkeley DB SQL Interface.

Note: In order to include Java support the Java SDK must be installed and javac must be in your path.

Run the configure

[root@ora2 build_unix]# export PATH=/opt/java/jdk1.6.0_21/bin/:$PATH 
[root@ora2 build_unix]$ ../dist/configure --enable-stl --enable-java --enable-sql
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking if building in the top-level or dist directories... no

< cut for clarity >

checking for 64-bit integral type support for sequences... yes
configure: creating ./config.status
config.status: creating Makefile
config.status: creating db_cxx.h
config.status: creating db_int.h
config.status: creating clib_port.h
config.status: creating include.tcl
config.status: creating db.h
config.status: creating db_config.h
config.status: executing libtool commands
[root@ora2 build_unix]$ 

Next we build Berkeley DB by issuing make.

[root@ora2 build_unix]# make
./libtool --mode=compile cc -c -I. -I../dist/..  -D_GNU_SOURCE -D_REENTRANT -I/opt/java/jdk1.6.0_21/include -I/opt/java/jdk1.6.0_21/include/linux -O3  ../dist/../mutex/mut_tas.c
libtool: compile:  cc -c -I. -I../dist/.. -D_GNU_SOURCE -D_REENTRANT -I/opt/java/jdk1.6.0_21/include -I/opt/java/jdk1.6.0_21/include/linux -O3 ../dist/../mutex/mut_tas.c  -fPIC -DPIC -o .libs/mut_tas.o
libtool: compile:  cc -c -I. -I../dist/.. -D_GNU_SOURCE -D_REENTRANT -I/opt/java/jdk1.6.0_21/include -I/opt/java/jdk1.6.0_21/include/linux -O3 ../dist/../mutex/mut_tas.c -o mut_tas.o >/dev/null 2>&1
./libtool --mode=compile cc -c -I. -I../dist/..  -D_GNU_SOURCE -D_REENTRANT -I/opt/java/jdk1.6.0_21/include -I/opt/java/jdk1.6.0_21/include/linux -O3  ../dist/../mutex/mut_pthread.c

< cut for clarity >

libtool: compile:  cc -c -I. -I../dist/.. -D_GNU_SOURCE -D_REENTRANT -I/opt/java/jdk1.6.0_21/include -I/opt/java/jdk1.6.0_21/include/linux -O3 ../dist/../db_verify/db_verify.c -o db_verify.o >/dev/null 2>&1
./libtool --mode=link cc -O3  -o db_verify  \
            db_verify.lo util_cache.lo util_sig.lo libdb-5.0.la -lpthread
libtool: link: cc -O3 -o .libs/db_verify .libs/db_verify.o .libs/util_cache.o .libs/util_sig.o  ./.libs/libdb-5.0.so -lpthread  -Wl,-rpath -Wl,/usr/local/BerkeleyDB.5.0/lib
./libtool --mode=execute true db_verify
[root@ora2 build_unix]# 

With the build complete we can now install Berkeley DB.

[root@ora2 build_unix]# make install
cp ../dist/../sql/generated/sqlite3.h dbsql.h
Installing DB include files: /usr/local/BerkeleyDB.5.0/include ...
Installing DB library: /usr/local/BerkeleyDB.5.0/lib ...
libtool: install: cp -p .libs/libdb-5.0.so /usr/local/BerkeleyDB.5.0/lib/libdb-5.0.so
libtool: install: cp -p .libs/libdb-5.0.lai /usr/local/BerkeleyDB.5.0/lib/libdb-5.0.la
libtool: install: cp -p .libs/libdb_cxx-5.0.so /usr/local/BerkeleyDB.5.0/lib/libdb_cxx-5.0.so
libtool: install: cp -p .libs/libdb_cxx-5.0.lai /usr/local/BerkeleyDB.5.0/lib/libdb_cxx-5.0.la

<  cut for clarity >

libtool: install: cp -p .libs/db_dump /usr/local/BerkeleyDB.5.0/bin/db_dump
libtool: install: cp -p .libs/db_hotbackup /usr/local/BerkeleyDB.5.0/bin/db_hotbackup
libtool: install: cp -p .libs/db_load /usr/local/BerkeleyDB.5.0/bin/db_load
libtool: install: cp -p .libs/db_log_verify /usr/local/BerkeleyDB.5.0/bin/db_log_verify
libtool: install: cp -p .libs/db_printlog /usr/local/BerkeleyDB.5.0/bin/db_printlog
libtool: install: cp -p .libs/db_recover /usr/local/BerkeleyDB.5.0/bin/db_recover
libtool: install: cp -p .libs/db_stat /usr/local/BerkeleyDB.5.0/bin/db_stat
libtool: install: cp -p .libs/db_upgrade /usr/local/BerkeleyDB.5.0/bin/db_upgrade
libtool: install: cp -p .libs/db_verify /usr/local/BerkeleyDB.5.0/bin/db_verify
Installing documentation: /usr/local/BerkeleyDB.5.0/docs ...
[root@ora2 build_unix]# 

The binaries were installed into /usr/local/BerkeleyDB.5.0. There you will find the executables, documentation, include files and libraries.

[root@ora2 build_unix]# ls /usr/local/BerkeleyDB.5.0/
bin  docs  include  lib
[root@ora2 build_unix]#

Creating a Database using Berkeley DB SQL interface

The Berkeley DB SQL Interface is a command line interface into Berkeley DB that is nearly identical to SQLite. When we built Berkeley DB we included –enable-sql to instruct the build process to build the Berkeley DB SQL Interface (dbsql)

Make sure that the BDB_HOME/bin directory is in your path or provide the full path dbsql. Below we start the Berkeley DB SQL Interface passing the database testdb.db. Since the database testdb.db does not exist a new database will be created.

[oracle@ora2 testdb]$ export PATH=/usr/local/BerkeleyDB.5.0/bin/:$PATH
[oracle@ora2 testdb]$ dbsql testdb.db
Berkeley DB 11g Release 2, library version 11.2.5.0.26: (June 25, 2010)
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
dbsql>

At this time if you were to look on the file system you would see that the directory is empty. A file will not be created until the database has been used to store data. Next we will create a simple table.

dbsql> create table t(
   ...> col1 int,
   ...> col2 varchar2(10));
dbsql>

As in Oracle SQL*Plus, SQL statements are terminated with a semi colon. Next we will insert some values into the table followed by retrieval.

dbsql> insert into t values(1, 'One');
dbsql> insert into t values(2, 'Two');
dbsql> insert into t values(3, 'Three');
dbsql> select * from t;
1|One
2|Two
3|Three
dbsql>

Now if you look at the file system you will see that the testdb.db file has been written along with a directory called testdb.db-journal.

[oracle@ora2 testdb]$ ls
testdb.db  testdb.db-journal
[oracle@ora2 testdb]$ ls testdb.db-journal/
__db.001  __db.003  __db.005  __db.register
__db.002  __db.004  __db.006  log.0000000001
[oracle@ora2 testdb]$

The testdb.db-journal directory contains Berkeley DB environment information that is intended to persist between transactions and process run times. You should not modify this directory or any files contained within it.

In order exit Berkeley DB SQL Interface enter .exit on the command line. More information about the Berkeley DB SQL Interface along with Berkeley DB in general can be found in the documentation located either online on locally in the BDB_HOME/doc directory.

8 thoughts on “Installing Berkeley DB 11gR2 11.2.5.0.26 on Oracle Enterprise Linux”

  1. Once again I am going to bother you.

    Now I have Unix environment and then I have BDB with C APIs

    I have run ‘MAKE’ to compile my dot C files to convert to Dot O

    Now, hHow do I create the database from ./dbms prompt. I do have dbms. c and dbms.o file but lost from here

    Please help

    your solution above recommad using sql but my concern is using these c APIs.
    Would you be able to help, please
    Regards,

  2. This is what have been provided to make it work such create.c. Please see below

    /*
    * create.c
    *
    * Computer Science 165/E-268, Harvard University
    * DBMS Implementation
    */

    #include
    #include
    #include

    #include “dbms.h”

    /*
    * Functions for handling CREATE TABLE
    */

    /**
    * Implementation of the stmt_t execute() method for stmt_t’s of
    * type COMMAND_CREATE_TABLE.
    * To invoke it, do: stmt->execute(stmt) on a stmt_t of that type.
    */
    void
    __stmt_execute_create(sql_stmt_t *stmt)
    {
    table_id_t *table_id;
    table_t* table = NULL;
    /* add additional variables as needed */

    /* Construct a table_t for the table. */
    table_id = stmt->get_table(stmt, 0);
    assert(table_id != NULL);
    table = table_construct(table_id);
    assert(table != NULL);

    /*
    * Replace the following line with your implementation of the
    * rest of the method.
    */
    goto error;

    fprintf(stdout, “Created table %.*s.\n”, table->name.len, table->name.ptr);
    goto done;

    error:
    fprintf(stderr, “Could not create table %.*s.\n”,
    table->name.len, table->name.ptr);

    done:
    /*
    * Because we could not use table_t->open() above, the table is not
    * in the table cache. Thus, we need to close its DB handle here,
    * or else it will never get closed!
    *
    * In the other commands, we will use table_t->open(), so this
    * step will not be necessary.
    */
    if (table->db != NULL)
    table->db->close(table->db, 0);

    /* Free allocated memory. */
    table_destroy(table);
    }

  3. Hello Zack,

    From looking at the code it appears that it is just one piece of a larger set code files. This one in particular appears to provide a function for creating a table. I cannot tell from the code if this if for a Berkeley Database as common includes (#include or #include ) are not present in the file.

    Are you sure that this code if for Berkeley Databases?

  4. Yes, Eric
    I have copied only one code out of 20 others. As you know from previous discusss I started with BDB with for windows and used SQL lite command.

    the next step was to use BDB under UNIX and by using C API, to create the DB, Tables and other related.

  5. Hello Zack,

    I do not know the source code you have, but I suspect it might not be using the C or C++ Berkeley Database APIs. I do not know what your time frame is for your project but I can probably post a simple program that utilizes the Berkeley DB C API sometime later this week or early next week. If it cannot wait that long you might consider looking at the Berkeley Docs and see if you can work one out yourself.

  6. Hi Eric,
    Thanks for your reply. Taht will be nice if you can post something simple to access the DB

Leave a Reply

Your email address will not be published. Required fields are marked *