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 ranging in size from a couple of megabytes to several terabytes. Included in the 11gR2 version of Berkeley DB is a SQLite compatible SQL API.
All administration is performed via API calls so no DBA is required. API’s are available for many programming languages including C/C++, Java and C#.
This document will detail the installation of Berkeley DB 11gR2 184.108.40.206.26 on Windows along with creation of a database using Berkeley DB SQL Interface.
Download and Installation
Berkeley DB 11gR2 can be downloaded from The Oracle Technology Network (OTN). An Oracle Technology Network account is required in order to download. Down load the Berkeley DB 5.0.26.msi Windows installer, with AES encryption
Double click the db-5.0.26.msi to start the installation.
Click the Run button on the Open File – Security Warning dialog.
Click the Next button on the Welcome screen.
Accept the License Agreement and click the Next button.
All features will be installed by default and will consume approximately 100MB of space. You can make changes to suite your environment. Note the default install location is C:\Program Files. If you do want to install in this path click the Browse button to select another location. After making your changes click the Next button to continue.
This is the last chance you will have to make changes prior to installing Berkeley DB. Click the Back button the make changes or click the Install button to start the installation.
Note: Depending on your version of Windows you might be required to approve installation.
A progress dialog details the installation process. Click the Next button once the installation is complete to continue.
Installation is complete. Click the Finish button to exit the setup wizard.
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. Berkeley DB SQL Interface (
dbsql) is automatically built and installed for Berkeley DB on Windows.
Make sure that the
BDB_HOME/bin directory is in your path or provide the full path
dbsql.exe. Note: If your path contains spaces you will need to wrap the path in double quotes. 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.
E:\source\berkeleydbs>"C:\app\oracle\product\BerkeleyDB11gR2 5.0.26\bin\dbsql" testdb.db Berkeley DB 11g Release 2, library version 220.127.116.11.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 like below.
E:\source\berkeleydbs>dir Volume in drive E is TOSHIBA EXT Volume Serial Number is 3685-FDB8 Directory of E:\source\berkeleydbs 07/20/2010 01:17 PM <DIR> . 07/20/2010 01:17 PM <DIR> .. 0 File(s) 0 bytes 2 Dir(s) 779,494,940,672 bytes free E:\source\berkeleydbs>
Nothing is wrong. At this time the database is empty so no file has been created. Back in DB SQL we 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
E:\source\berkeleydbs>dir Volume in drive E is TOSHIBA EXT Volume Serial Number is 3685-FDB8 Directory of E:\source\berkeleydbs 07/20/2010 01:29 PM <DIR> . 07/20/2010 01:29 PM <DIR> .. 07/20/2010 01:29 PM 32,768 testdb.db 07/20/2010 01:29 PM <DIR> testdb.db-journal 1 File(s) 32,768 bytes 3 Dir(s) 779,476,250,624 bytes free E:\source\berkeleydbs>dir testdb.db-journal Volume in drive E is TOSHIBA EXT Volume Serial Number is 3685-FDB8 Directory of E:\source\berkeleydbs\testdb.db-journal 07/20/2010 01:29 PM <DIR> . 07/20/2010 01:29 PM <DIR> .. 07/20/2010 01:41 PM 2,097,152 log.0000000001 07/20/2010 01:29 PM 24,576 __db.001 07/20/2010 01:29 PM 729,088 __db.002 07/20/2010 01:29 PM 10,248,192 __db.003 07/20/2010 01:29 PM 557,056 __db.004 07/20/2010 01:29 PM 4,956,160 __db.005 07/20/2010 01:29 PM 40,960 __db.006 07/20/2010 01:29 PM 0 __db.register 8 File(s) 18,653,184 bytes 2 Dir(s) 779,476,250,624 bytes free E:\source\berkeleydbs>
testdb.db-journal directory contains Berkeley DB environment information that is intended to persist between transactions and process runtimes. Do not delete 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