Before You Begin
This is the first tutorial in the Getting Started with the Graphical User Interface in Berkeley DB series. Perform both these tutorials sequentially as there is a dependency to complete one before starting the other.
- Creating a Transactional Environment in Berkeley DB
- Performing
Verification and Backup of a Transactional Environment in
Berkeley DB
In this first tutorial, you will create a transactional environment, create a database, create and manipulate data, and perform database transactions using the new Graphical User Interface in Berkeley DB 18.1.
This tutorial takes approximately 10 minutes to complete.
Background
Berkeley DB is a family of embedded key-value database libraries providing scalable high-performance data management services to applications. It enables the development of custom data management solutions, without any overhead. You can configure Berkeley DB to address any application need from the hand-held device to the data center, from a local storage solution to a world-wide distributed one, and from kilobytes to petabytes.
The Oracle Berkeley DB Graphical User Interface (BDB GUI) is introduced in Berkeley DB 18.1 and provides a simple interface for interacting with the Berkeley DB environment.
What Do You Need?
- Install JDK 8 or higher version in your machine. This is required to build and run Berkeley DB GUI.
- Install Oracle Berkeley DB 18.1 from the Oracle Technology Network.
- For Windows only: Install Oracle Berkeley DB 18.1 Windows binary installer from the Oracle Technology Network.
- For Linux only:
- After installing, enable GUI with the --enable-gui flag while building Berkeley DB 18.1.
- Set the following environment variables. Replace [bdb-install_directory]
with the path to the directory where you have Berkeley DB
18.1 installed:
export CLASSPATH=[bdb-install_directory]/lib/db.jar;[bdb-install_directory]/lib/db_gui.jar;$CLASSPATH
export LD_LIBRARY_PATH=[bdb-install_directory]/lib;$LD_LIBRARY_PATH
Start the Berkeley DB GUI
- Open a Command Prompt in your machine.
- Type java db_gui.db_gui and press Enter to start the Berkeley DB GUI.
- The Berkeley DB GUI opens up for you.
Create a Transactional Environment
A Berkeley DB environment is a container that holds and manages databases.The Create Environment page is the first page that appears when you start a Berkeley DB GUI and allows you perform the operations on an environment such as create, open, backup, recovery, remove old logs, upgrade, verify data, and verify logs.
In this section, you create a transactional environment.
- Select a environment home directory to store any future databases, logs, and other files belonging to the environment. Click the Browse button by Environment Home and select a directory in which you want to store the environment.
- Select the Transactional check box. This enables transactional data protection for the environment.
- Select a cache size of 25 megabytes. Enter 26214400 in the Cache Size box and click the Create button.This will move the GUI to the Database Page.
- You see a message "Environment successfully created." at the bottom of the screen. This confirms that the environment is created successfully.
- Open your environment home directory and you see files like __db.001 created in it.
Create a Database
The Database page allows you to perform operations on databases, such as create, open, compact, remove, and rename. In this section, you create a database by using the Berkeley DB GUI.
- In the Create Database page, enter a name for the database file. Enter test.db in the Database File text box.
- Ensure that btree is the type of database selected from the Database Type menu and select the page size as 4096 from the Page Size menu.
- Click the Create button to create the database.This will move the GUI to the Data Access Page.
- You see a message "Database successfully created." at the bottom of the screen. This confirms that the database is created successfully.
- Open your environment home directory. You see the database file test.db created in the directory.
Add, Browse, and Delete Data
The Data Access page allows you to browse and manipulate data in a database. In this section, you insert, browse, and delete data from the database.
- In the Data Access page, add data to the database by going
to the Put Data section at the top of the page and performing
the following steps:
- Enter hello in the Key text box
- Enter world in the Data text box
- Click the Put button.
- Next, insert another record. Enter foo in
the Key text box, bar
in the Data text box, and click the Put
button.
- To browse the data inserted into the database, click the Next button in the Browse Data section.The words "foo" and "bar" should appear in the Key and Data text boxes.
- Click Next again. The words "hello" and "world" will appear.
- Click Next again. The text boxes will be empty, and the message "End of the database has been reached, there is no next record." will appear at the bottom of the page.
- To fetch a specific record from the database, you use the Get button. In the Browse Data section, enter "hello" in the Key text box and click the Get button. The word "world" will appear in the Data text box.
- Delete the "hello world" record by clicking the Delete button.
- Try to get the "hello" record again by redoing step 6. The message "Database does not contain that key." will appear at the bottom of the page.
Begin, Commit, and Abort a Transaction
A transaction is a logical unit of work that contains one or more statements. The effects of all statements in a transaction can be either all committed (applied to the database) or all aborted (undone from the database). Perform the following steps to begin, commit, and abort a transaction:
Note: This section appears in the Berkeley DB GUI only if the environment is transactional.
- Click the Begin button in the Transaction section at the top of the page.
- In the Put Data section, enter "abc" for Key, and "def" for Data and click Put.
- In the Browse Data section, enter "abc" in the Key text box and click Get. This will retrieve the "abc def" record.
- Click the Abort button. This will undo all the operations performed from steps 1 to 3.
- Click the Clear button to clear all the text fields.
- Try to get the "abc" record again, it will fail indicating that the transaction is rolled back from the database.
Next Tutorial
Performing
Verification and Backup of a Transactional Environment in
Berkeley DB