Getting started with the BangDB for linux native


Please download the BangDB for linux native file. Please ensure that you pick the right binary for 32/64 bit as you may need.

Now we need to un compress the downloaded file.

	> tar -xzvf bangdb-linux-32-native-1.5.2.tar.gz
	# Or for 64 bits 
	> tar -xzvf bangdb-linux-64-native-1.5.2.tar.gz 
	# go to the newly created folder;
	> cd bangdb32bits
	# Or, for 64 bits 
	> cd bangdb64bits 

The download files are (if you run ls command)

  • include - directory, this contains all the headers and soruce files needed to build app
  • - The BangDB library
  • libbangdb.a - The static BangDB library
  • - The BangDB install file
  • - The BangDB uninstall file
  • bangdb.config - The config file for BangDB
  • README - General info for the db and the release
  • bangdb_bench - dir, contains test files ready to run


To install the db, just run file

	> sudo bash
	# It may ask for your password, please provide that. Next provide the user name;
	> Enter the user name (user who will use the db) :

After this the db will be installed. Basically it creates bangdb group, adds the user to the group, copies the bangdb lib to the /usr/local/lib dir and creates various soft links. Finally it creates a bangdb dir under /usr/local/include and copies all include files under it.

Note that this install is not required if you intend to include the db files providing the full path and also link to the bangdb by manually providing the path to it while compiling. But it's easier to install the bangdb this way for ease of operation in future. Since uninstall file is also included and if you care to unistall in future then running it cleans up completely

Running sample test file

To run the sample test or bench app provided along with the download, do following;

	> cd bangdb_bench
	> bash
	# to run the default test case, do
	> ./bench
	# to run with command arguments, do following 
	> ./bench 4 1000000 put
	# ----------------------------------------------------------------------------
	#	usage: bangdb_bench num_threads num_items put/get/all/overlap [factor(optional 
	#   define only with overlap)]
	#  	factor > 1; the factor defines how much read and write
	#  	1/factor part write and rest read. ex; factor = 3, 33 percent write and 67 percent read
	# ----------------------------------------------------------------------------

Sample Code

Below is sample code to do some simple operations using BangDB. The bangdb.config file defines many configurable parameters, but most importantly edit the following values based on your liking. For now just leave the config values as it is;

  • SERVER_DIR - This is basically the location where the db will keep its files. User can also provide the dir information while creating the databas object
  • KEY_SIZE - This is to denote the maximum length of key that you will be using to store values. The min value is 8 bytes, and maximum is dependent upon the PAGE_SIZE defined. however keep it small for better performance
  • BUFF_POOL_SIZE_HINT - The size of the buffer pool, default value is 1GB for 64 bit and 512MB for 32 bit, change as you wish

Please look at the document which describes meaning of various parameters in the config file at resources or go to the configuration section for detailed information and explanation


int main(int argc, char *argv[])
	bool flag = true;
	/* Create db, table and connection */
	database *db = new database("mydb");
	table *tbl = db->gettable("mytbl", OPENCREATE);
	if(tbl == NULL)
		bangdb_logger("Table is NULL, quitting");
		return -1;
	connection *conn = tbl->getconnection();
	if(conn == NULL)
		bangdb_logger("Connection is NULL, quitting");
		return -1;
	/* do some operations */
	const char *key = "key_1";
	const char *val = "This is the test value for key_1";
	/* put */
	if(conn->put(key, val, INSERT_UNIQUE) < 0)
		bangdb_logger("Put error");
		flag = false;
	/* get */
	char *out = conn->get(key);
	if(out == NULL)
		bangdb_logger("Get error");
		flag = false;
	/* update */
	val = "Update value for the test key";
	if(conn->put(key, val, UPDATE_EXISTING) < 0)
		bangdb_logger("Update error");
		flag = false;
	/* del */
	if(conn->del(key) < 0)
		bangdb_logger("Del error");
		flag = false;
	/* try to get the del key */
	if(conn->get(key) != NULL)
		bangdb_logger("Got the deleted value, error");
		flag = false;

	delete conn;
	delete tbl;
	delete db;
		bangdb_logger("Test pased!");
		bangdb_logger("Test failed");
	return 0;


Above char* is used for keys and values, however, you can use any arbitrary bytes for keys and values using FDT data type. Look at the general data types for information and usage example for FDT

More examples covering all other features would be there in "examples" section

Later in the section of developing using BangDB, more and advanced details are covered