Installing And Configuring Asterisk 1.6 + PostgreSQL To Manage CDR & RealTime Config On Debian

In this tutorial, I will describe how to install and configure Asterisk 1.6 on a Debian system to work with PostgreSQL in order to manage CDR (Call Detail Records) and real-time configuration.

For this we will use a clean and up-to-date Debian Etch/Lenny system; the first step is to reconfigure the kernel with some new parameters so that it supports Asterisk optimally.

apt-get install kernel-package libncurses5-dev fakeroot wget bzip2 build-essential

cd /usr/src

Download the kernel source, I will use 2.6.26:


tar xfv linux-

ln -s /usr/src/linux- /usr/src/linux

cd /usr/src/linux

make clean && make mrproper

cp /boot/config-`uname -r` ./.config

make menuconfig

Now in the kernel configuration, we select this:

Processor type and features >> [*]IRQ balancing
Processor type and features >> Timer frequency = 1000 Hz.
Processor type and features >> [*]High Resolution Timer Option
Processor type and features >> [*]HPET Timer Support
Device Drivers >> Character Devices >> [*]Enchanced Real Time Clock Support
Library Routines >> [*]CONFIG_CRC_CCITT

Now compile and make a .deb package for the kernel:

make-kpkg clean

fakeroot make-kpkg --initrd --append-to-version=-custom kernel_image kernel_headers

We can now install the kernel as follows:

cd /usr/src

dpkg -i *.deb

Now we need to reboot:

reboot -t now!

Ok, now we have the system fully optimized for best performance with VoIP. Now we prepare the machine for compiling Asterisk from the sources:

apt-get install build-essential libcurl3-dev libvorbis-dev libspeex-dev unixodbc unixodbc-dev libiksemel-dev

apt-get install flex xsltproc odbc-postgresql libusb-dev libnewt-dev libxml2-dev bison

apt-get install linux-headers-`uname -r` g++ libncurses5-dev libnewt-dev libusb-dev subversion git-core

apt-get install postgresql-8.1 postgresql-contrib-8.1 postgresql-client-8.1 postgresql-dev

Our system is ready, now download the Asterisk sources from the svn repo. In Asterisk 1.6 Zaptel is renamed to DAHDI, and we add mISDN for ISDN trunks:

cd /usr/src

mkdir asterisk

cd asterisk

svn co asterisk

svn co asterisk-addons

svn co dahdi-linux

svn co dahdi-tools

svn co libpri

git-clone git://

git-clone git://

Now we start compiling the DAHDI modules, for managing and controlling Digium devices and others:

cd /usr/src/asterisk/dahdi-linux

make && make install

Now the DAHDI tools

cd /usr/src/asterisk/dahdi-tools


make menuselect


make install

make config

To optimize boot time, we unload unnecesary modules, therefore edit /etc/dahdi/modules and comment out all modules, except that one you will use, for example, I have a Digium TDM400P, so I uncomment wctdm.

Now we build libpri:

cd /usr/src/asterisk/libpri

make && make install

Now only if you have the ISDN trunk. This step is


cd /usr/src/asterisk/mISDN


make install

cd /usr/src/asterisk/mISDNuser

make && make install

mISDN scan

mISDN config

mISDN start


/usr/sbin/update-rc.d mISDN defaults 15 30


Now we compile Asterisk itself:

cd /usr/src/asterisk/asterisk


make menuconfig


make install

make samples

make config

asterisk -vvvc

Ctrl+C for exit

So, we have an ordinary Asterisk 1.6 just like any other, but now we make it unique and configure it to work in realtime.

First we need the DB schema, Asterisk has one, but it is bugged, so I use my own DB.

cd /usr/src/asterisk


su - postgres

createuser -s -D -R -l -P -e asterisk

createdb -O asterisk -e asteriskDB

pgsql -U asterisk -h localhost -d asteriskDB < /usr/src/asterisk/realtime_pgsql.sql

Allow asterisk to connect to PostgreSQL:

echo "local asteriskDB asterisk md5" >> /etc/postgresql/8.1/pg_hba.conf

Now we prepare the configuration files in Asterisk:

nano /etc/asterisk/cdr_pgsql.conf


nano /etc/asterisk/extconfig.conf

extensions => pgsql,asteriskDB,extensions_conf
sipuser => pgsql,asteriskDB,sip_conf
sippeers => pgsql,asteriskDB,sip_conf
sipregs => pgsql,asteriskDB,sip_conf
voicemail => pgsql,asteriskDB,voicemail_users
queues => pgsql,asteriskDB,queue_table
queue_members => pgsql,asteriskDB,queue_member_table 

nano /etc/asterisk/res_pgsql.conf


All set... we are ready, now just restart Asterisk. Congratulations!

/etc/init.d/asterisk restart

HOW-TO IS OUTDATED... UpGrade in progress in This is in Spanish, very soon English version, only here.. in HowToForge! Cheers, Coto Cisternas
Share this page:

5 Comment(s)

Add comment


From: Allan

The line:


pgsql -U asterisk -h localhost -d asteriskDB < /usr/src/asterisk/realtime_pgsql.sql



Should be:


psql -U asterisk -h localhost -d asteriskDB < /usr/src/asterisk/realtime_pgsql.sql



At least on my Debian Lenny installation.




From: Grayson Peddie

If this the one contained inside realtime_pgsql.sql file? The website with the file in the URL does not have it. Here's the one:


Upgraded... ty, i change my domain and my hosting... :P btw... this TUTO is very OutUpdate... but check out in

Im working in a Upgrade, but is in Spanish... very soon i will translate and republish right here.. in How To Forge!



Coto Cisternas

From: Anonymous

thank you for the tutorial !!

From: Maziar

sql file not found