Want to connect to postgresql for asterisk realtime

Hi,

I am new to the asterisk world. I have installed asterisk now in one of my pc. after that i have connected it with a postgresql database. It worked fine.

In another pc i installed asterisk from source code of 1.4 with libpri, and asterisk-addons. I want to connect to postgresql database from this asterisk. but i am lost. i have found out it can be done through unixodbc. so i was thinking does asterisknow use unixodbc to connect to pgsql. if not how do i do it without odbc? is it possible? please help.

thank you.

tareq

you don’t have to use odbc anymore there is a native postgres module of asterisk. you need to have postgresql development libraries installed. run ‘make menuselect’ and select res_config_pgsql in Resource modules section.
Then make and make install.


Godson Gera
Asterisk Consultant India

[quote=“godson”]you don’t have to use odbc anymore there is a native postgres module of asterisk. you need to have postgresql development libraries installed. run ‘make menuselect’ and select res_config_pgsql in Resource modules section.
Then make and make install.


Godson Gera
Asterisk Consultant India[/quote]

Hi,
Once included into asterisk, how do I use this module? I am wrestling with the odbc-connector, so if there is another solution, I would gladly give it a shot. For I am at a loss at the moment.
I would be grateful for some more info, or for some tips on where to find more info… As long as I can finally approach the problem from another angle…

thanks in advance
Toni

The example configuration file for postgres is missing from default asterisk installation. However it is identical to res_mysql.conf.

You need to create a res_pgsql.conf file in /etc/asterisk/ with the following parameters

[general]
dbhost = 127.0.0.1
dbname = asterisk
dbuser = root
dbpass = root
dbport = 3304
dbsock = /tmp/postgres.sock

your parameter values will vary. Put load=>res_pgsql.so in modules.conf Once this is created you restart asterisk.


Godson Gera
Asterisk Consultancy Support Service India

thanks for the quick reply! I’ll check it out as soon as possible.

Toni

Hi,

I changed modules.conf and added
preload => res_config_pgsql.so

I modified also res_pgsql.conf to let it point to the asterisk-database I created.

When I restart asterisk, I do “module show like res_config_pgsql.so”: it shows as not being loaded.

Next I try to load it manually with “module load res_config_pgsql.so”, but I get following error:

[…]
Unable to load module res_config_pgsql.so
Command 'module load res_config_pgsql.so ’ failed.
[Jan 11 09:01:48] WARNING[2349]: loader.c:371 load_dynamic_module: Error loading module ‘res_config_pgsql.so’: libpq.so.5: cannot open shared object file: No such file or directory
[Jan 11 09:01:48] WARNING[2349]: loader.c:662 load_resource: Module ‘res_config_pgsql.so’ could not be loaded.
[…]

I am running asterisk as non-root, everything else works ok.

Do you have any other pointers as to where I might have missed anything?

Thanks
Toni

Problem solved,

The error was caused by “limit => 0” in res_odbc.conf
This option is apparently not needed for postgresql.
When omitting it everything works fine.

Toni

[quote=“godson”]The example configuration file for postgres is missing from default asterisk installation. However it is identical to res_mysql.conf.

You need to create a res_pgsql.conf file in /etc/asterisk/ with the following parameters

[general]
dbhost = 127.0.0.1
dbname = asterisk
dbuser = root
dbpass = root
dbport = 3304
dbsock = /tmp/postgres.sock

your parameter values will vary. Put load=>res_pgsql.so in modules.conf Once this is created you restart asterisk.


Godson Gera
Asterisk Consultancy Support Service India[/quote]

Hi Godson,

I didn’t manage at first to get pgsql to work directly with asterisk, so I reverted to odbc. But eventually I got stuck there, because cdr wouldn’t work.
So I thought giving your solution another try, but this time I put into modules.conf the following statement: load=>res_config_pgsql.so and now magically everything works, even cdr. So thanks at least for the good lead.

Toni