Databases for Linux Embedded Systems: Berkeley DB and SQLite
Embedded systems often need to use database to store contact information, EPG data and more. Many Linux systems use MySQL, however such a large database management system may not always be appropriate for embedded systems.
Hence, there are lightweight database management systems implementation that are especially suited to embedded systems by their binary footprint, memory footprint and CPU requirements.
If you want to develop in C in Linux and your requirement is to have no (or little) license to pay in your application, you could consider Oracle Berkeley DB or SQLite among others.
Oracle Berkeley DB (previously Sleepycat Berkeley DB) is described as follows:
Berkeley DB enables the development of custom data management solutions, without the overhead traditionally associated with such custom projects. Berkeley DB provides a collection of well-proven building-block technologies that can be configured to address any application need from the hand-held device to the datacenter, from a local storage solution to a world-wide distributed one, from kilobytes to petabytes.
Berkeley DB has the following characteristics:
- Written in C
- Software Library
- Key/value API
- SQL API by incorporating SQLite
- BTREE, HASH, QUEUE, RECNO storage
- C++, Java/JNI, C#, Python, Perl, …
- Java Direct Persistence Layer (DPL) API
- Java Collections API
- Replication for High Availability
The latest stable version is Berkeley DB 11gR2 (188.8.131.52.25).
SQLite is described as follows:
SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. SQLite is the most widely deployed SQL database engine in the world. The source code for SQLite is in the public domain.
SQLite has the following features:
- Transactions are atomic, consistent, isolated, and durable (ACID) even after system crashes and power failures.
- Zero-configuration – no setup or administration needed.
- Implements most of SQL92. (Features not supported)
- A complete database is stored in a single cross-platform disk file.
- Supports terabyte-sized databases and gigabyte-sized strings and blobs.
- Small code footprint: less than 325KiB fully configured or less than 190KiB with optional features omitted.
- Faster than popular client/server database engines for most common operations.
- Simple, easy to use API.
- Written in ANSI-C. TCL bindings included. Bindings for dozens of other languages available separately.
- Well-commented source code with 100% branch test coverage.
- Available as a single ANSI-C source-code file that you can easily drop into another project.
- Self-contained: no external dependencies.
- Cross-platform: Unix (Linux and Mac OS X), OS/2, and Windows (Win32 and WinCE) are supported out of the box. Easy to port to other systems.
- Sources are in the public domain. Use for any purpose.
- Comes with a standalone command-line interface (CLI) client that can be used to administer SQLite databases.
The latest version is SQLite 3.7.5.
Whether you choose one of the other you’ll have to consider:
- SQLite support SQL natively, has a low memory footprint (190KB minimal / 325 KB full features) and is open source (GPL License) . However, some extensions are not open source and require a license such as SQLite Encryption Extension. (2000 USD one-time fee payable to hwaci).
- Berkeley DB supports SQL thru SQLite, has a low memory footprint (350KB minimal config) a has a dual license GPL/Commercial. Berkeley also have a XML (C++) and Java Edition.
There are many parameters to consider, but generally, in most cases you would probably go with SQLite unless you need encryption, do not want to pay the 2000 USD license fee and your code can be open-sourced. In the later case, Berkeley DB is probably the best choice.