Asterisk base knowledge


One stupid question from newbie guy.

When in Asterisk CLI interface i type command “database show” and the system provide me information from the DB, where can I get info about this DB (location, connection, user(s), password(s), port(s), etc)?

The reason I’m asking I’m not able to see some extensions into the DB which I can see in sip.conf file. I suspect there is some problem with the DB. How can I check and fix, please?

Thank you in advance,

The astdb is a sqlite3 database stored on disk. It does not contain a copy of your extensions, it’s merely for storing some things that should persist across restarts (like registrations).

Thank you jcolp!

But I’m still confused.

When I do CLI> database show

I see:
/DEVICE/107/dial :SIP/107
/DEVICE/107/type : fixed
/DEVICE/107/user : 107
/DEVICE/150/dial :SIP/150
/DEVICE/150/type : fixed
/DEVICE/150/user : 150

But between them I should have info about DEVICES 111 and 112 which I can see in my sip.conf file, but cannot see in the output of this command. Something definitely is not good. Could you give me an idea why do I have this and hoe can I fix it?

Thank you in advance,

Are you using FreePBX or a GUI? Those entries are not something Asterisk itself is putting in there, something else is.

FreePBX. So, when I type

CLI> database show

Is it going to some FreePBX stuff?

If they store some stuff in the Asterisk database, yes. We provide mechanisms to allow arbitrary information to be stored in it.

But it stores into Asterisk DB and you said it is sqlite3. Do you know how can I connect to the DB directly?

Thank you

You can use sqlite studio (or other sqlite manager) to conect to the sqlite3 database.
P.S: Sqlite Studio has an intuitive interface, is fast and easy to use, but you will need a system with a graphical interface, so you’ll need to copy the database to a PC and them open the database with sqlite studio.

Link: SqliteStudio

There are also Asterisk CLI commands which can be used to manipulate that database, they all begin with “database”.

Thank you guys for you answers!

Another question about basic understanding of Asterisk.

How can I see and set my destination extension for inbound calls coming from a trunk?

Thank you!

Asterisk doesn’t have a concept of a trunk, and destinations are devices, not extensions.

Incoming calls go to the context specified by the device technology file, e.g. sip.conf, for chan_sip. They select the extension in that context based on the digits provide when the call was made, e.g. the direct in dialling number (which is likely to be a sub-string of the the, so called, DID number). If there are no digits they go to extensions s.

The selected extension then decides how to deliver them. That can be a very simple Dial(technology/device) or hundreds of lines of user or third party provided dialplan.

Hi jcolp,

But when I type database I see not many options I can use. I see “put”, “get”, “show”, “showkeys” and something else. First of all, I don’t understand why do we need internal sqlite3 DB when we already have config files. Moreover, we have config files + mariaDB which also keeps some settings.
Secondly, I see info about my extensions/device into mariaDB as SIP, but Asterisk still treats them as PJSIP until I did “database put” command and change them manually. Why do we have mariaDB at this case?
Thirdly, recently I did test with incoming and outgoing calls with no lack. My system sends decline message with code 603. I believe it is simply because my system does not redirect the call to the receiving device. In my dual plan I see this redirection rule, but the system refuses to do so.SQLite3 again?
Fourthly, what config file sets connection to sqlite3 DB? Manager.conf? if so, I don’t understand why the third party software (FreePBX) is not able to connect to Asterisk in my case.

Thank you in advance for your answers,

I can’t speak on anything related to FreePBX but Asterisk itself does not require an external database such as MariaDB. The sqlite3 database exists for the storage of things that need to be persisted, the example I gave previously being registrations. If you register a SIP phone this information is, by default, stored in the sqlite3 database and if you restart Asterisk then it will still be registered. This requires no setup of another database (like MariaDB) and just works. There is no explicit configuration to point to the sqlite3 database. I would suggest taking any questions about that to the FreePBX forum instead as they are better equipped to answer.


Thanks a lot jcol!

But still don’t understand why sqlite3 if we have config files? This is quite annoying when you check config files, there are no errors/mistakes into them but the system does not work properly until you correct something into some sneaky DB with very limited tools you have to control the DB.
You wrote “there is no explicit configuration to the sqlite3 DB”, but you also admitted you allow to store some third party apps’ info. to do so, this app should connect to the DB somehow. And my question is “How?”. Username, password, IP address, port/socket. THis info should be stored to somewhere.

Asterisk will not update config files except on an explicit request, and if it does so, will destroy all the comments in them. ASTDB covers those cases where information needs to be retained across a restart without an explicit rewrite of the configuration files.

Sorry David, didn’t get you. If you don’t need to change anything you don’t do this and after restart Asterisk could easily picks up configuration from config files. If you need to do a change,you change config files and restart Asterisk which picks up all changes from config files again. I see no reason to have sqlite3, sorry for my misunderstanding…

There are things, like details of registrations, that can change as a result of input from peers and you can also create devices and extensions using AMI or CLI.

Some people want changes to global variables to persist.

Originally, Asterisk used a very simple database, included with Linux, so the need may not have been so obvious.

1 Like

Configuration files store configuration information. The sqlite3 database stores state information for Asterisk internals. Another example: Custom device state. You can use the DEVICE_STATE dialplan function to store custom device state. That doesn’t come from a configuration file, 'nor is it configuration. It’s state information that needs to exist across Asterisk restarts. It is stored in the sqlite3 database.

1 Like