Asterisk Internal Database

Asterisk Internal Database

Asterisk comes with a database that is used internally and made available for Asterisk programmers and administrators to use as they see fit.

Asterisk versions up to 1.8 used the Berkeley DB, and in version 10 the project moved to the SQLite3 database

What is the Purpose of the internal database in Asterisk

The database really has two purposes:

  1. Asterisk uses it to store information that needs to persist between reloads/restarts. Various modules use it for this purpose automatically.
  2. Users can use it to store arbitrary data. This is done using a variety of dialplan applications and functions such as:
    • Functions:
      • DB
      • DB_DELETE
      • DB_EXISTS
      • DB_KEYS
    • Application: DBdeltree

 

Functions

DB()

Usages: Read from or write to the Asterisk database.

Description :

This function will read from or write a value to the Asterisk database. On a read, this function returns the corresponding value from the database, or blank if it does not exist. Reading a database value will also set the variable DB_RESULT. If you wish to find out if an entry exists, use the DB_EXISTS function.

Syntax

DB(family/key)
Arguments
  • family
  • key

DB_DELETE()

Usages: Return a value from the database and delete it.

Description

This function will retrieve a value from the Asterisk database and then remove that key from the database. DB_RESULT will be set to the key’s value if it exists.

Syntax

DB_DELETE(family/key)
Arguments
  • family
  • key

Database commands on the CLI

*AsteirskCLI> core show help database

database del                   -- Removes database key/value
database deltree               -- Removes database keytree/values
database get                   -- Gets database value
database put                   -- Adds/updates database value
database query                 -- Run a user-specified query on the astdb
database show                  -- Shows database contents
database showkey               -- Shows database contents