Summary:ASTERISK-05119: [patch] [post 1.2] PostgreSQL driver for Asterisk RealTime (res_config_pgsql)
Reporter:Daniel Swarbrick (pressureman)Labels:
Date Opened:2005-09-21 02:40:28Date Closed:2006-01-17 14:17:15.000-0600
Versions:Frequency of
Environment:Attachments:( 0) Makefile.patch
( 1) res_config_pgsq-0.40.c
( 2) res_config_pgsql.50.c
( 3) res_config_pgsql.51.c
( 4) res_config_pgsql.c
( 5) res_config_pgsql-0.39.c
( 6) res_config_pgsql-0.42.c
( 7) res_config_pgsql-new.c
( 8) res_pgsql.conf
( 9) res_pgsql.tar.gz
Description:Port of existing MySQL driver for Asterisk RealTime to PostgreSQL.


The makefile in /res will need tweaking to supply Postgres headers and libs to link against.

Quite a few ast_log() calls are with LOG_NOTICE - and should probably be changed to LOG_DEBUG once the code settles down a bit.
Comments:By: Daniel Swarbrick (pressureman) 2005-09-21 03:41:11

Updated version, includes connection re-establishment if DB connection is broken after Asterisk startup.

By: Daniel Swarbrick (pressureman) 2005-09-23 01:06:57

Simplified config file handling with removal of all parameters except a PostgreSQL-style DSN. Uploaded sample config file which documents this DSN format.

Commented out ast_mutex_locks since these seemed to be causing deadlocks.

Converted a number of ast_log() calls to LOG_DEBUG. If you want to see the queries being passed to the back end, you can enable this in PostgreSQL log configuration.

By: Russell Bryant (russell) 2005-09-23 11:44:11

Just a few preliminary comments:

1) Do you have a disclaimer on file?  If not, you will need to submit one for this to be reviewed.

2) This would most likely make it into the asterisk-addons tree.  If you go to make a patch to the Makefile to link with the Postgres libs, just go ahead and make those modifications to the asterisk-addons Makefile.


By: Daniel Swarbrick (pressureman) 2005-09-24 20:40:50

1) I'm not sure I fully understand the requirements of the disclaimer. At the top of the file I've inserted a copyright statement similar to the one found in res_config_mysql.c. I am releasing this code under the GPL, however the company who paid me for my time to write it wishes to at least retain some kudos for it, if the copyright clashes with the GPL. I'm more than happy for others to contribute to and/or improve the code, provided that my name and my company's name are retained in the file.

2) Can this not be bundled with the main Asterisk distribution? My understanding was that res_config_mysql was put in -addons because of the MySQL license incompatibility, and that this wasn't a problem with Postgres.

By: Denis Voitenko (denis) 2005-10-04 21:14:41

It would make sense it this made it to the main tree next to all the other Real Time stuff. PostgreSQL license definetly allows for it.

By: Russell Bryant (russell) 2005-10-04 22:01:52

Don't worry about where the module will end up.  It doesn't really matter right now.

However, the disclaimer is absolutely necessary for anyone to review your code and consider including it in the tree.  More information about the disclaimer can be found in the bug posting guidelines:


If you would like to read further discussion regarding the disclaimer, search the mailing list archives (google for "site:lists.digium.com disclaimer" or something like that).  It has been discussed at length, there multiple times.

By: Daniel Swarbrick (pressureman) 2005-10-04 22:14:37

Current code uploaded, have put the ast_mutex_lock calls back in and seems to be stable. Converted most (if not all) LOG_NOTICE that I was using to debug to LOG_DEBUG.

Am talking with my employer regarding signing the disclaimer that would release this code to CVS.

By: Daniel Swarbrick (pressureman) 2005-10-11 05:05:43

Made DB connection handle and DSN static so they don't clash with cdr_pgsql

By: Manuel Guesdon (mguesdon) 2005-11-07 09:50:20.000-0600

To pressureman:

I've submited a res_config_pgsql.c to day :-)

It is based on res_config_mysql.c

What do you think ? Should we merge the 2 or should I drop my version... ?

You can contact me directly at: mguesdon [AT] oxymium.net

By: Steven Sokol (ssokol) 2005-11-13 21:28:45.000-0600

Attached is new PostgreSQL Realtime Driver I created based on the MySQL driver.  I have a disclaimer on file (though its rather old - let me know if I need to re-submit or anything).  This file includes both the driver code (res_config_pgsql.c) and a patch to the Makefile that builds it.

This version uses the exact same syntax as the MySQL driver uses for its configuration file (res_pgsql.conf).  Example:

dbhost =
dbname = asterisk_db
dbuser = rtconfig
dbpass = r3alt1me
dbport = 5432
dbsocket =

I think this may be the third version of this to show up.  This version has had very _very_ little testing, so don't plan on running it in production.


By: Daniel Swarbrick (pressureman) 2005-11-13 21:45:56.000-0600

to mguesdeon:

Be careful with your declaration of PGconn - you are not declaring it static, therefore it will be globally visible to all module. The cdr_pgsql module in Asterisk also declares a PGconn var non static, so you will clash with this. I discovered this bug a couple of months ago, and since fixing it locally, I have been running my own version of res_config_pgsql flawlessly on a production system.

My version is availble under GPL in OpenPBX (www.openpbx.org), or attached with this bug. Since I have not signed the Digium disclaimer, nor do I intend to, my version Asterisk version of res_config_pgsql will have to live in asterisk-adddons.

By: Manuel Guesdon (mguesdon) 2005-11-14 02:08:45.000-0600

Thank you pressureman for the 'static' tip advice !

About res_config_pgsql, I suggest we take one we can be integrated directly in asterisk.
ssokol version and mne seems similar.

I hope one can be integrated quickly before we have a 4th or 5th version :-)

By: Steven Sokol (ssokol) 2005-12-20 09:08:31.000-0600

Uploaded version 0.50 which corrects a few fatal flaws in the version included in the tar.  Specifically:

12/12/05 - Corrected datatype in several sprintf statements.  They still had the MySQL-specific datatypes declared.

12/15/05 - Updated/corrected some of the error messages.

By: Jared Smith (jsmith) 2005-12-22 14:56:23.000-0600

I've fixed up the patch for the Makefile so that it applies cleanly to the 1.2 branch makefile.  (I'll test it on the trunk shortly.)

I've also uploaded res_config_pgsql.51.c, which removes an unneeded MySQL header file.

Disclaimer on file.

By: Matt O'Gorman (mogorman) 2006-01-17 14:16:47.000-0600

So because pressureman has no intention of submitting a disclaimer, and there is work being done on the other bug note 5637 I suggest steven and others move over there so that when we do have an implemntation that is trunk ready we can commit it.