[Home]

Summary:ASTERISK-15820: [patch] Insert fails when database initialized during connection outage to postgres server
Reporter:Peter Katzmann (pk16208)Labels:
Date Opened:2010-03-16 08:00:44Date Closed:2011-07-26 14:37:32
Priority:MinorRegression?No
Status:Closed/CompleteComponents:CDR/cdr_pgsql
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:( 0) cdr_pgsql.patch
Description:When asterisk starts up or reload the cdr_pgsql does not work properly when the database connection fails during startup.
These results in a empty server record list and no cdr's are logged and reconnect does not resolve the problem

In the case of AST_RWLIST_EMPTY(&psql_columns)
the databse connection has to be closed completely and a complete reinitialization is necessery.
The following patch will do the job:

<inline patch removed by lmadsen>


****** ADDITIONAL INFORMATION ******

Intial Error
[Jan  1 01:00:19] ERROR[497] cdr_pgsql.c: cdr_pgsql: Unable to connect to database server 130.10.10.217.  CALLS WILL NOT BE LOGGED!!
[Jan  1 01:00:19] ERROR[497] cdr_pgsql.c: cdr_pgsql: Reason: could not connect to server: No route to host
       Is the server running on host "130.10.10.217" and accepting
       TCP/IP connections on port 5432?

Resulting Problems:
[Jan  1 01:45:13] ERROR[770] cdr_pgsql.c: cdr_pgsql: Failed to insert call detail record into database!
[Jan  1 01:45:13] ERROR[770] cdr_pgsql.c: cdr_pgsql: Reason: ERROR:  syntax error at or near ")"
LINE 1: INSERT INTO cdr ) VALUES )
                       ^

[Jan  1 01:45:13] ERROR[770] cdr_pgsql.c: cdr_pgsql: Connection may have been lost... attempting to reconnect.
[Jan  1 01:45:13] ERROR[770] cdr_pgsql.c: cdr_pgsql: Connection reestablished.
[Jan  1 01:45:13] ERROR[770] cdr_pgsql.c: cdr_pgsql: HARD ERROR!  Attempted reconnection failed.  DROPPING CALL RECORD!
[Jan  1 01:45:13] ERROR[770] cdr_pgsql.c: cdr_pgsql: Reason: ERROR:  syntax error at or near ")"
LINE 1: INSERT INTO cdr ) VALUES )
                       ^

[Jan  1 01:49:40] ERROR[771] cdr_pgsql.c: cdr_pgsql: Failed to insert call detail record into database!
[Jan  1 01:49:40] ERROR[771] cdr_pgsql.c: cdr_pgsql: Reason: ERROR:  syntax error at or near ")"
LINE 1: INSERT INTO cdr ) VALUES )
                       ^

Comments:By: Leif Madsen (lmadsen) 2010-03-16 12:59:52

Inline patches can not be accepted on the issue tracker. Please attach your unified diff as an attachment to this issue for inclusion in Asterisk. If you have not already done so, please sign the electronic license agreement which would appear as a link at the top of the page.

When doing your diff, please use 'diff -u' for the proper patch format. Thanks!

By: Leif Madsen (lmadsen) 2010-03-16 13:06:02

Per russell on IRC, this issue is really an architectural deficiency in the way the code is written, and is thus expected behaviour.

However, there is an experimental branch (based off of trunk, which will eventually become Asterisk 1.8) that could potentially solve your issue.

The branch is available here:  http://svn.asterisk.org/svn/asterisk/team/russell/cdr-q/

It implements a CDR queue so that when the database goes offline, the CDRs will be queue'd, and then written when the database becomes available next.

The reviewboard link is available here:

https://reviewboard.asterisk.org/r/531/

By: Leif Madsen (lmadsen) 2010-03-17 10:04:57

Just waiting on license approval. Thanks!

By: Peter Katzmann (pk16208) 2010-03-17 10:07:24

The attached patch seems to work (at least the last days in our test configuration), but is not a really well designed solution.
More something to show the problem and what has to be done to resolve it

By: Leif Madsen (lmadsen) 2011-07-26 14:37:26.067-0500

Per the Asterisk maintenance timeline page at http://www.asterisk.org/asterisk-versions maintenance (bug) support for the 1.4 and 1.6.x branches has ended. For continued maintenance support please move to the 1.8 branch which is a long term support (LTS) branch. For more information about branch support, please see https://wiki.asterisk.org/wiki/display/AST/Asterisk+Versions

If this is still an issue, please open a new issue so it can be re-triaged appropriately. Thanks!