I’m currently working on a project which uses Berkeley DB (BDB) as it’s data storage engine. I can’t say enough good things about BDB. It has proven to be a very fast and flexible way to store and retrieve data, it is very easy to use and the documentation is absolutely top notch.
One issue I ran into, though, is that there is no good way to examine the databases for debugging purposes. Initially, I used the provided db_dump command-line tool, which was fine for small databases. Db_dump dumps the entire contents of a database, which was OK when I was dealing with databases with only a few records. But now I am working with databases with thousands and soon millions of records. Db_dump just won’t do.
I did a bit of googling but there didn’t seem to be any viewers available for Berkeley DB, so I decided to write one. I was going to do it in C# and WPF because that’s what I’m currently using. But I decided that, since BDB is cross-platform, a viewer for it should also be cross-platform. So I decided to use Qt to build the viewer.
After a couple of nights of coding, here is the result:
The interface is pretty simple. There is a button for opening a BDB database file. Once a database is opened, the “Database” combo-box let’s you pick which sub-database to view (in BDB terms a database is a key/value table and a single file can contain multiple “databases”). The list view on the left shows all the keys in that database and the view on the right shows the contents at that key. Both keys and values are formatted the same as db_dump -p -k formats them.
I put the source code for Berkeley DB Viewer (bdbvu) on Google Code. You can grab it at: http://code.google.com/p/bdbvu/.
To build it you need two things:
- Berkeley DB, installed and built with C++ support.
- Qt4.
Once you have those set up and you’ve downloaded the code, you will probably need to change the Qt project file to reflect your environment. I may enventually provide binary downloads, but I don’t have the time for that right now.
Finally, a few things to keep in mind:
- I’ve only tested this with DB_RECNO and DB_BTREE databases, since that’s what I’m using at this time. But, there’s no reason it shouldn’t work with DB_HASH and DB_QUEUE databases as well. (Where have I heard that before?)
- I’ve only tested it with databases with embedded databases, not with stand-alone databases. I know it won’t work with stand-alone databases because the code for that is a no-op.
- I’ve only built and run this on OS X. Theoretically, it should work on Windows and Linux as well, but you never know until you try it.
- When you open a database, it will load all it’s keys into memory. This seems to be pretty quick (a couple of seconds for a 3000+ record database on my laptop) but I may have to change it to use a more scalable method in the future.
That’s it for now. I hope you find this useful.