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 11.2.5.0.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 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 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 testdb.db-journal
.
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>
The 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 BDB_HOME/doc
directory.
Hi Eric,
you have an excellent document above but I wonder how to create the Database?
I have installed my BDB for Windows as below
Berkeley DB 11g Release 2, library version 11.2.5.1.19: (August 27, 2010)
Enter “.help” for instructions
Enter SQL statements terminated with a “;”
dbsql>
my path is
C:\Program Files\Oracle\Berkeley DB 11gR2 5.1.19\bin
but don’t knwo how to move forward
Hello Zack,
When you start dbsql.exe you can pass the name of the database in which to connect. If the database does not exist the database will be created.
For example DBD_HOME\dbsql.exe newbdb.db will create a database called newbdb.db in the current directory if does not already exist. No files, newbdb.db or the journal directory, will be written to the file system until data is stored into the database.
Hi Eric,
It is still not letting me do any things. Please my path where I have installed BDB
C:\Program Files\Oracle\Berkeley DB 11gR2 5.1.19\bin
Now I created a bdb directory in bin and on root c: as wel.
I am double clicking on dbsql.exe which in my bin and then getting the follwoing prompt
Berkeley DB 11g Release 2, library version 11.2.5.1.19: (August 27, 2010)
Enter “.help” for instructions
Enter SQL statements terminated with a “;”
dbsql> dbdhome\dbsql.exe newbdb.db
…> ;
Error: near “dbdhome”: syntax error
dbsql> dbdhome\dbsql.exe newbdb.db
…> ;
Error: near “dbdhome”: syntax error
dbsql> “C:\Program Files\Oracle\Berkeley DB 11gR2 5.1.19\bin\dbsql.exe” testdb.d
b;
Error: near “”C:\Program Files\Oracle\Berkeley DB 11gR2 5.1.19\bin\dbsql.exe””:
syntax error
dbsql>
Hi Eric,
Once again. I got it working. Thanks for all your help
Actually I had to go to C:\ prompt and then to the Directory BIN and then type in quotes; the name of the new Database
Regards,
Once again,
I have created the table and inserted data into it. to save the data entered, do I have close the table and database as well?
because when I exited the data was gone which I recreated again. Would you please wirte me ” how to close the table, db and save the data inserted”?
Regards,
Hello Zack,
How did you exit the database and how did you reconnect?
Below is the output of creating a database named zack.db, creating a table and inserting some records. I then exit the dbsql and restart it connecting to the database zack.db. I then select * from the table again and finally exit the dbsql again and show a directory listing. To exit dbsql use the .exit command.
One thing to note about the example below. My databases are created in a directory called E:\source\berkleydbs and provide the full path to the dbsql executable along with the database name in the command prompt.
I did another test just like the output above except I closed the dos (cmd.exe) window instead of exiting dbsql using the .exit command. When I reconnected to the database the table and data were still present.
Make sure you know which directory you create your database in and besure to either be in that directory when starting dbsql or provide the full path and the name of the database on the command line.
Brilliant, it works
Thank you very much
lesson learned, when installing BDB on Windows; give a short part on root to make life easier.
That is great to hear. I am happy you got it worked out.
Hi Eric. I have one question. How BDB SQL interface is different from using just BDB C++ API in creating tables and inserting records and etc.? Will the tables and records created with both approaches be in the same format and have no difference? I am asked to convert some tables in Oracle to their equivilant variant in BDB. Which approach should I choose?
Thanks for your help
Hi Eric, I wanna evaluate the performances of some Native xml databases including BDB. I you have experiance in this field, could you please help me to know the way of creating the database for NXD and how can I import some XML dataset into the created database. how can I uses some queries against data imported to the tabels. I wanna measure the response time for these processes?
Thanks,
Mohsen
An innlielgett point of view, well expressed! Thanks!