O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Berkeley DB

Book Description

Small, special-purpose computing devices and high-end core Internet servers need fast, reliable database management. Berkeley DB is an embedded database that provides high-performance, scalable, transaction-protected and recoverable data management services to applications. Extremely portable, this library runs under almost all UNIX and Windows variants, as well as a number of embedded, real-time operating systems.

Berkeley DB is the ultimate resource for the world's most widely deployed embedded database engine. This book will aid software architects and engineers, product managers, and systems and network administrators without the overhead imposed by other database products.

Designed by programmers for programmers, this classic library style toolkit provides a broad base of functionality to application writers. This book will help you to make intelligent choices about when and how to use Berkeley DB to meet your needs.

You can visit the Sleepycat website to get the latest errata for this book.

NOTE: The first printing of this book contained an error in the table of contents that caused the page numbers to be off. This will be corrected in the second printing. If you have an earlier edition, you can download a pdf of the correct table of contents that you can print out and use with your book. If you have any questions, please feel free to contact the editor of this book at stephanie.wall@newriders.com.

Table of Contents

  1. Copyright
  2. About the Author
  3. About the Technical Reviewer
  4. Acknowledgments
  5. Tell Us What You Think
  6. Introduction
  7. Reference Guide
    1. Introduction
      1. Mapping the Terrain: Theory and Practice
      2. What is Berkeley DB?
      3. What is Berkeley DB Not?
      4. Do You Need Berkeley DB?
      5. What Other Services Does Berkeley DB Provide?
      6. What Does the Berkeley DB Distribution Include?
      7. Where Does Berkeley DB Run?
      8. Sleepycat Software’s Berkeley DB Products
    2. Getting Started: A Simple Tutorial
      1. Key/Data Pairs
      2. Object Handles
      3. Error Returns
      4. Opening a Database
      5. Adding Elements to a Database
      6. Retrieving Elements from a Database
      7. Removing Elements from a Database
      8. Closing a Database
    3. Access Method Configuration
      1. Btree
      2. Selecting an Access Method
      3. Logical Record Numbers
      4. Selecting a Page Size
      5. Selecting a Cache Size
      6. Selecting a Byte Order
      7. Non-Local Memory Allocation
      8. Btree Comparison
      9. Minimum Keys Per Page
      10. Retrieving Btree Records by Number
      11. Page Fill Factor
      12. Specifying a Database Hash
      13. Hash Table Size
      14. Managing Record-Based Databases
      15. Selecting a Queue Extent Size
      16. Flat-Text Backing Files
      17. Logically Renumbering Records
    4. Access Method Operations
      1. Opening a Database
      2. Opening Multiple Databases in a Single File
      3. Upgrading Databases
      4. Retrieving Records
      5. Storing Records
      6. Deleting Records
      7. Flushing the Database Cache
      8. Database Statistics
      9. Closing a Database
      10. Database Cursors
      11. Retrieving Records with a Cursor
      12. Storing Records with a Cursor
      13. Deleting Records with a Cursor
      14. Duplicating a Cursor
      15. Logical Join
      16. Data Item Count
      17. Closing a Cursor
      18. Cursor Stability
      19. Database Verification and Salvage
    5. Access Method Wrap-Up
      1. Retrieved Key/Data Permanence for C/C++
      2. Database Limits
      3. Disk Space Requirements
      4. Partial Record Storage and Retrieval
      5. Error Support
    6. Berkeley DB Architecture
      1. Programming Model
      2. Programmatic APIs
      3. Scripting Languages
      4. Supporting Utilities
    7. Berkeley DB Environment
      1. Creating a Database Environment
      2. File Naming
      3. Filename Resolution in Berkeley DB
      4. Security
      5. Shared Memory Regions
      6. Remote Filesystems
      7. Opening Databases Within the Environment
      8. Error Support
    8. Berkeley DB Concurrent Data Store Applications
    9. Berkeley DB Transactional Data Store Applications
      1. Why Transactions?
      2. Terminology
      3. Application Structure
      4. Opening the Environment
      5. Opening the Databases
      6. Recoverability and Deadlock Avoidance
      7. Atomicity
      8. Repeatable Reads
      9. Transactional Cursors
      10. Nested Transactions
      11. Environment Infrastructure
      12. Deadlock Detection
      13. Performing Checkpoints
      14. Database and Log File Archival Procedures
      15. Log File Removal
      16. Recovery Procedures
      17. Recovery and Filesystem Operations
      18. Berkeley DB Recoverability
      19. Transaction Throughput
    10. XA Resource Manager
      1. Configuring Berkeley DB with the Tuxedo System
      2. Frequently Asked Questions
    11. Programmer Notes
      1. Error Returns to Applications
      2. Environmental Variables
      3. Building Multithreaded Applications
      4. Berkeley DB Handles
      5. Name Spaces
      6. Library Version Information
      7. Compatibility with Historic UNIX Interfaces
      8. Recovery Implementation
      9. Application-Specific Logging and Recovery
      10. Run-Time Configuration
    12. The Locking Subsystem
      1. Page Locks
      2. Standard Lock Modes
      3. Locking Without Transactions
      4. Locking with Transactions: Two-Phase Locking
      5. Access Method Locking Conventions
      6. Berkeley DB Concurrent Data Store Locking Conventions
      7. Deadlocks and Deadlock Avoidance
      8. Configuring Locking
      9. Locking and Non-Berkeley DB Applications
    13. The Logging Subsystem
      1. Configuring Logging
      2. Log File Limits
    14. The Memory Pool Subsystem
      1. Configuring the Memory Pool
    15. The Transaction Subsystem
      1. Transaction Limits
      2. Configuring Transactions
      3. Transactions and Non-Berkeley DB Applications
    16. RPC/Client Server
      1. Client Program
      2. Server Program
    17. Java API
      1. Compatibility
      2. Java Programming Notes
      3. Java FAQ
    18. Tcl API
      1. Loading Berkeley DB with Tcl
      2. Using Berkeley DB with Tcl
      3. Tcl API Programming Notes
      4. Tcl Error Handling
      5. Tcl FAQ
    19. Dumping and Reloading Databases
      1. The db_dump and db_load Utilities
      2. Dump Output Formats
      3. Loading Text into Databases
    20. Debugging Applications
      1. Compile-time Configuration
      2. Run-time Error Information
      3. Reviewing Berkeley DB Log Files
      4. Common Errors
    21. Building Berkeley DB for UNIX and QNX Systems
      1. Building for UNIX
      2. Configuring Berkeley DB
      3. Changing Compile or Load Options
      4. Installing Berkeley DB
      5. Dynamic Shared Libraries
      6. Running the Test Suite Under UNIX
      7. Architecture-Independent FAQs
      8. AIX
      9. FreeBSD
      10. HP-UX
      11. IRIX
      12. Linux
      13. OSF/1
      14. SCO
      15. Solaris
      16. SunOS
      17. Ultrix
    22. Building Berkeley DB for Win32 Platforms
      1. Building for Win32
      2. Running the Test Suite Under Windows
      3. Windows Notes
      4. Windows FAQ
    23. Building Berkeley DB for VxWorks Systems
      1. Building with Tornado 2.0
      2. VxWorks Notes
      3. VxWorks FAQ
    24. Upgrading Berkeley DB Applications
      1. Upgrading Berkeley DB Installations
    25. Test Suite
      1. Running the Test Suite
      2. Test Suite FAQ
    26. Distribution
    27. Additional References
      1. Technical Papers on Berkeley DB
      2. Background on Berkeley DB Features
      3. Database Systems Theory
  8. API Manual
    1. C API
      1. DB→close
      2. DB→cursor
      3. DB→del
      4. DB→fd
      5. DB→get
      6. DB→get_byteswapped
      7. DB→get_type
      8. DB→join
      9. DB→key_range
      10. DB→open
      11. DB→put
      12. DB→remove
      13. DB→rename
      14. DB→set_append_recno
      15. DB→set_bt_compare
      16. DB→set_bt_minkey
      17. DB→set_bt_prefix
      18. DB→set_cachesize
      19. DB→set_dup_compare
      20. DB→set_errcall
      21. DB→set_errfile
      22. DB→set_errpfx
      23. DBset_feedback
      24. DB→set_flags
      25. DB→set_h_ffactor
      26. DB→set_h_hash
      27. DB→set_h_nelem
      28. DB→set_lorder
      29. DB→set_malloc
      30. DB→set_pagesize
      31. DB→set_paniccall
      32. DB→set_q_extentsize
      33. DB→set_re_delim
      34. DB→set_re_len
      35. DB→set_re_pad
      36. DB→set_re_source
      37. DB→set_realloc
      38. DB→stat
      39. DB→sync
      40. DB→upgrade
      41. DB→verify
      42. DBENV→close
      43. DBENV→err
      44. DBENV→open
      45. DBENV→remove
      46. DBENV→set_cachesize
      47. DBENV→set_data_dir
      48. DBENVset_errcall
      49. DBENV→set_errfile
      50. DBENV→set_errpfx
      51. DBENV→set_feedback
      52. DBENV→set_flags
      53. DBENV→set_lg_bsize
      54. DBENV→set_lg_dir
      55. DBENV→set_lg_max
      56. DBENV→set_lk_conflicts
      57. DBENV→set_lk_detect
      58. DBENV→set_lk_max
      59. DBENVset_lk_max_lockers
      60. DBENV→set_lk_max_locks
      61. DBENV→set_lk_max_objects
      62. DBENV→set_mp_mmapsize
      63. DBENV→set_paniccall
      64. DBENV→set_recovery_init
      65. DBENV→set_server
      66. DBENV→set_shm_key
      67. DBENV→set_tmp_dir
      68. DBENV→set_tx_max
      69. DBENV→set_tx_recover
      70. DBENV→set_tx_timestamp
      71. DBENV→set_verbose
      72. DBT
      73. DB_LSN
      74. DBcursor→c_close
      75. DBcursor→c_count
      76. DBcursor→c_del
      77. DBcursor→c_dup
      78. DBcursor→c_get
      79. DBcursor→c_put
      80. db_create
      81. db_env_create
      82. db_env_set_func_close
      83. db_env_set_func_dirfree
      84. db_env_set_func_dirlist
      85. db_env_set_func_exists
      86. db_env_set_func_free
      87. db_env_set_func_fsync
      88. db_env_set_func_ioinfo
      89. db_env_set_func_malloc
      90. db_env_set_func_map
      91. db_env_set_func_open
      92. db_env_set_func_read
      93. db_env_set_func_realloc
      94. db_env_set_func_rename
      95. db_env_set_func_seek
      96. db_env_set_func_sleep
      97. db_env_set_func_unlink
      98. db_env_set_func_unmap
      99. db_env_set_func_write
      100. db_env_set_func_yield
      101. DBENV→set_mutexlocks
      102. db_env_set_pageyield
      103. db_env_set_panicstate
      104. db_env_set_region_init
      105. db_env_set_tas_spins
      106. db_strerror
      107. db_version
      108. dbm/ndbm
      109. hsearch
      110. lock_detect
      111. lock_get
      112. lock_id
      113. lock_put
      114. lock_stat
      115. lock_vec
      116. log_archive
      117. log_compare
      118. log_file
      119. log_flush
      120. log_get
      121. log_put
      122. log_register
      123. log_stat
      124. log_unregister
      125. memp_fclose
      126. memp_fget
      127. memp_fopen
      128. memp_fput
      129. memp_fset
      130. memp_fsync
      131. memp_register
      132. memp_stat
      133. memp_sync
      134. memp_trickle
      135. txn_abort
      136. txn_begin
      137. txn_checkpoint
      138. txn_commit
      139. txn_id
      140. txn_prepare
      141. txn_stat
    2. C++ API
      1. Db
      2. Db::close
      3. Db::cursor
      4. Db::del
      5. Db::fd
      6. Db::get
      7. Db::get_byteswapped
      8. Db::get_type
      9. Db::join
      10. Db::key_range
      11. Db::open
      12. Db::put
      13. Db::remove
      14. Db::rename
      15. b::set_append_recno
      16. Db::set_bt_compare
      17. Db::set_bt_minkey
      18. Db::set_bt_prefix
      19. Db::set_cachesize
      20. Db::set_dup_compare
      21. Db::set_errcall
      22. Db::set_errfile
      23. Db::set_errpfx
      24. Db::set_feedback
      25. Db::set_flags
      26. Db::set_h_ffactor
      27. Db::set_h_hash
      28. Db::set_h_nelem
      29. Db::set_lorder
      30. Db::set_malloc
      31. Db::set_pagesize
      32. Db::set_paniccall
      33. Db::set_q_extentsize
      34. Db::set_re_delim
      35. Db::set_re_len
      36. Db::set_re_pad
      37. Db::set_re_source
      38. Db::set_realloc
      39. Db::stat
      40. Db::sync
      41. Db::upgrade
      42. Db::verify
      43. DbEnv
      44. DbEnv::close
      45. DbEnv::err
      46. DbEnv::lock_detect
      47. DbEnv::lock_get
      48. DbEnv::lock_id
      49. DbEnv::lock_stat
      50. DbEnv::lock_vec
      51. DbEnv::log_archive
      52. DbEnv::log_compare
      53. DbEnv::log_file
      54. DbEnv::log_flush
      55. DbEnv::log_get
      56. DbEnv::log_put
      57. DbEnv::log_register
      58. DbEnv::log_stat
      59. DbEnv::log_unregister
      60. DbEnv::memp_register
      61. DbEnv::memp_stat
      62. DbEnv::memp_sync
      63. DbEnv::memp_trickle
      64. DbEnv::open
      65. DbEnv::remove
      66. DbEnv::set_cachesize
      67. DbEnv::set_data_dir
      68. DbEnv::set_errcall
      69. DbEnv::set_errfile
      70. DbEnv::set_error_stream
      71. DbEnv::set_errpfx
      72. DbEnv::set_feedback
      73. DbEnv::set_flags
      74. DbEnv::set_lg_bsize
      75. DbEnv::set_lg_dir
      76. DbEnv::set_lg_max
      77. DbEnv::set_lk_conflicts
      78. DbEnv::set_lk_detect
      79. DbEnv::set_lk_max
      80. DbEnv::set_lk_max_lockers
      81. DbEnv::set_lk_max_locks
      82. DbEnv::set_lk_max_objects
      83. DbEnv::set_mp_mmapsize
      84. DbEnv::set_mutexlocks
      85. DbEnv::set_pageyield
      86. DbEnv::set_paniccall
      87. DbEnv::set_panicstate
      88. DbEnv::set_recovery_init
      89. DbEnv::set_region_init
      90. DbEnv::set_server
      91. DbEnv::set_shm_key
      92. DbEnv::set_tas_spins
      93. DbEnv::set_tmp_dir
      94. DbEnv::set_tx_max
      95. DbEnv::set_tx_recover
      96. DbEnv::set_tx_timestamp
      97. DbEnv::set_verbose
      98. DbEnv::strerror
      99. DbEnv::txn_begin
      100. DbEnv::txn_checkpoint
      101. DbEnv::txn_stat
      102. DbEnv::version
      103. DbException
      104. DbException::get_errno
      105. DbException::what
      106. DbLock
      107. DbLock::put
      108. DbLsn
      109. DbMpoolFile
      110. DbMpoolFile::close
      111. DbMpoolFile::get
      112. DbMpoolFile::open
      113. DbMpoolFile::put
      114. DbMpoolFile::set
      115. DbMpoolFile::sync
      116. DbTxn
      117. DbTxn::abort
      118. DbTxn::commit
      119. DbTxn::id
      120. DbTxn::prepare
      121. Dbc
      122. Dbc::close
      123. Dbc::count
      124. Dbc::del
      125. Dbc::dup
      126. Dbc::get
      127. Dbc::put
      128. Dbt
    3. Java API
      1. Db
      2. Db.close
      3. Db.cursor
      4. Db.del
      5. Db.fd
      6. Db.get
      7. Db.get_byteswapped
      8. Db.get_type
      9. Db.join
      10. Db.key_range
      11. Db.open
      12. Db.put
      13. Db.remove
      14. Db.rename
      15. Db.set_append_recno
      16. Db.set_bt_compare
      17. Db.set_bt_minkey
      18. Db.set_bt_prefix
      19. Db.set_cachesize
      20. Db.set_dup_compare
      21. Db.set_errcall
      22. Db.set_errpfx
      23. Db.set_feedback
      24. Db.set_flags
      25. Db.set_h_ffactor
      26. Db.set_h_hash
      27. Db.set_h_nelem
      28. Db.set_lorder
      29. Db.set_pagesize
      30. Db.set_q_extentsize
      31. Db.set_re_delim
      32. Db.set_re_len
      33. Db.set_re_pad
      34. Db.set_re_source
      35. Db.stat
      36. Db.sync
      37. Db.upgrade
      38. Db.verify
      39. DbDeadlockException
      40. DbEnv
      41. DbEnv.close
      42. DbEnv.get_version_major
      43. DbEnv.lock_detect
      44. DbEnv.lock_get
      45. DbEnv.lock_id
      46. DbEnv.lock_stat
      47. DbEnv.lock_vec
      48. DbEnv.log_archive
      49. DbEnv.log_compare
      50. DbEnv.log_file
      51. DbEnv.log_flush
      52. DbEnv.log_get
      53. DbEnv.log_put
      54. DbEnv.log_register
      55. DbEnv.log_stat
      56. DbEnv.log_unregister
      57. DbEnv.memp_register
      58. DbEnv.memp_stat
      59. DbEnv.memp_sync
      60. DbEnv.memp_trickle
      61. DbEnv.open
      62. DbEnv.remove
      63. DbEnv.set_cachesize
      64. DbEnv.set_data_dir
      65. DbEnv.set_errcall
      66. DbEnv.set_error_stream
      67. DbEnv.set_errpfx
      68. DbEnv.set_feedback
      69. DbEnv.set_flags
      70. DbEnv.set_lg_bsize
      71. DbEnv.set_lg_dir
      72. DbEnv.set_lg_max
      73. DbEnv.set_lk_conflicts
      74. DbEnv.set_lk_detect
      75. DbEnv.set_lk_max
      76. DbEnv.set_lk_max_lockers
      77. DbEnv.set_lk_max_locks
      78. DbEnv.set_lk_max_objects
      79. DbEnv.set_mp_mmapsize
      80. DbEnv.set_mutexlocks
      81. DbEnv.set_pageyield
      82. DbEnv.set_panicstate
      83. DbEnv.set_recovery_init
      84. DbEnv.set_region_init
      85. DbEnv.set_server
      86. DbEnv.set_shm_key
      87. DbEnv.set_tas_spins
      88. DbEnv.set_tmp_dir
      89. DbEnv.set_tx_max
      90. DbEnv.set_tx_recover
      91. DbEnv.set_tx_timestamp
      92. DbEnv.set_verbose
      93. DbEnv.strerror
      94. DbEnv.txn_begin
      95. DbEnv.txn_checkpoint
      96. DbEnv.txn_stat
      97. DbException
      98. DbException.get_errno
      99. DbLock
      100. DbLock.put
      101. DbLsn
      102. DbMemoryException
      103. DbMpoolFile.close
      104. DbMpoolFile.get
      105. DbMpoolFile.open
      106. DbMpoolFile.put
      107. DbMpoolFile.set
      108. DbMpoolFile.sync
      109. DbRunRecoveryException
      110. DbTxn
      111. DbTxn.abort
      112. DbTxn.commit
      113. DbTxn.id
      114. DbTxn.prepare
      115. Dbc
      116. Dbc.close
      117. Dbc.count
      118. Dbc.del
      119. Dbc.dup
      120. Dbc.get
      121. Dbc.put
      122. Dbt
    4. Tcl APIs
      1. berkdb dbremove
      2. berkdb dbrename
      3. berkdb env
      4. berkdb envremove
      5. berkdb open
      6. berkdb version
      7. db close
      8. dbc close
      9. db count
      10. db cursor
      11. db del
      12. dbc del
      13. dbc dup
      14. db get
      15. dbc get
      16. db get_join
      17. db get_type
      18. db is_byteswapped
      19. db join
      20. db put
      21. db stat
      22. db sync
      23. dbc put
      24. env close
      25. env txn
      26. txn abort
      27. txn commit
    5. Supporting Utilities
      1. berkeley_db_svc
      2. db_archive
      3. db_checkpoint
      4. db_deadlock
      5. db_dump
      6. db_load
      7. db_printlog
      8. db_recover
      9. db_stat
      10. db_upgrade
      11. db_verify