Asterisk res_config


A very flexible way of storing configuration information (e.g. users in sip.conf) in an ODBC database (e.g. MySQL).
It does, however, require the server to be reloaded to make changes appear.

As of 2004-Jun-10 res_config was available in what was at that point called CVS Head. You will need ODBC development packages installed for your distribution, e.g unixODBC-dev. Res_config is now part of the stable sourcetree e.g. definitely in 1.0.2 and later.


Create table

Using your normal database tool, create a table to hold the config info:

create table ast_config (
id bigint primary key not null auto_increment,
cat_metric int not null default 0,
var_metric int not null default 0,
commented int not null default 0,
filename varchar(128) not null,
category varchar(128) not null default 'default',
var_name varchar(128) not null,
var_val varchar(128) not null


Specify how to reach the tables

Create /etc/asterisk/configs/res_odbc.conf and specify how to reach the just-created table:

; /etc/asterisk/configs/res_odbc.conf
dsn = MySQL-asterisk
username = myuser
password = mypass
pre-connect = yes

dsn = MySQL2-asterisk
username = myuser2
password = mypass2
enabled = no


You can have several sections in this file, e.g. for a production and a staging asterisk. The [ENV] section sets environment variables. Some database drivers need them for their operation.

Therefore, we need a "glue" entry that tells asterisk which one to use.
Outdated! Put lines similar to these into /etc/asterisk/res_config_odbc.conf:

; /etc/asterisk/res_config_odbc.conf
table = ast_config
connection = mysql1

Specify what tables are now in the ODBC database

And finally we can re-route the config engine of Asterisk to not use the config file, but our table instead. This is done with /etc/asterisk/extconfig.conf:

; /etc/asterisk/extconfig.conf
queues.conf => odbc

CVS HEAD as of 2004-10-05 changes format to:

; /etc/asterisk/extconfig.conf
queues.conf => odbc,mysql1,ast_config

Also this change means, that res_config_odbc.conf is deprecated. At least in Asterisk v1.0.2 and later extconfig.conf is what you need to use.
Old remarks: For stable you will currently have to stick with the old format, though.

Create sample data

You can also put sample data into the database:

insert into ast_config (filename,category,var_name,var_val)

You still need to issue a "reload" command.

You can upload your current configuration data to mysql with this script: load_res_config.pl
Another script, that i found (for postgresql) is here. He also has some fixes for the postgresql odbc
driver on http://www.gofti.com/


  • Create records with "General" as category in order to define the typical General section in .conf files
  • True or not? You need to touch /etc/asterisk/sip.conf - the files still need to exist, but they can (and should) be empty.

Modules overview

  • res_config is the thing that allows you to hijack the configs
  • res_odbc is the resource to have reusable database handles, globally accessible across multiple apps. It's driven by res_odbc.conf
  • res_config_odbc is the part that access the database, driven by processes res_config_odbc.conf - as of 2004-10-05 this file is deprecated. It's functionality has moved to extconfig.conf. It's still needed in the stable tree.
  • the build-in config.c code processes the extconfig.conf file

See also

Asterisk | FAQ | Tips & Tricks

Created by: flavour, Last modification: Fri 09 of Oct, 2009 (19:22 UTC) by Nugget
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+