aboutsummaryrefslogtreecommitdiffstats
path: root/cdr/cdr_pgsql.c
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2005-02-26 18:57:14 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2005-02-26 18:57:14 +0000
commit87d9ffaec30fd815949bae0ddd6ad0e0658b3b81 (patch)
tree039331012ebde1c69971ad90e0392ad3cd9b043d /cdr/cdr_pgsql.c
parentcbcd01d4142480b61654cacd2b7f8ef1406308a0 (diff)
attempt a restart on a connection error (bug #3628)
git-svn-id: http://svn.digium.com/svn/asterisk/branches/v1-0@5090 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'cdr/cdr_pgsql.c')
-rwxr-xr-xcdr/cdr_pgsql.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/cdr/cdr_pgsql.c b/cdr/cdr_pgsql.c
index f6af7ff58..90d386fdc 100755
--- a/cdr/cdr_pgsql.c
+++ b/cdr/cdr_pgsql.c
@@ -127,6 +127,19 @@ static int pgsql_log(struct ast_cdr *cdr)
pgerror = PQresultErrorMessage(result);
ast_log(LOG_ERROR,"cdr_pgsql: Failed to insert call detail record into database!\n");
ast_log(LOG_ERROR,"cdr_pgsql: Reason: %s\n", pgerror);
+ ast_log(LOG_ERROR,"cdr_pgsql: Connection may have been lost... attempting to reconnect.\n");
+ PQreset(conn);
+ if (PQstatus(conn) == CONNECTION_OK) {
+ ast_log(LOG_ERROR, "cdr_pgsql: Connection reestablished.\n");
+ connected = 1;
+ result = PQexec(conn, sqlcmd);
+ if ( PQresultStatus(result) != PGRES_COMMAND_OK)
+ {
+ pgerror = PQresultErrorMessage(result);
+ ast_log(LOG_ERROR,"cdr_pgsql: HARD ERROR! Attempted reconnection failed. DROPPING CALL RECORD!\n");
+ ast_log(LOG_ERROR,"cdr_pgsql: Reason: %s\n", pgerror);
+ }
+ }
ast_mutex_unlock(&pgsql_lock);
return -1;
}
@@ -287,7 +300,7 @@ static int process_my_load_module(struct ast_config *cfg)
connected = 1;
} else {
pgerror = PQerrorMessage(conn);
- ast_log(LOG_ERROR, "cdr_pgsql: Unable to connect to database server %s. Calls will not be logged!\n", pghostname);
+ ast_log(LOG_ERROR, "cdr_pgsql: Unable to connect to database server %s. CALLS WILL NOT BE LOGGED!!\n", pghostname);
ast_log(LOG_ERROR, "cdr_pgsql: Reason: %s\n", pgerror);
connected = 0;
}