Code

postgresql plugin: If a query fails, try to reconnect immediately.
authorSebastian Harl <sh@tokkee.org>
Thu, 8 Mar 2012 21:07:23 +0000 (22:07 +0100)
committerSebastian Harl <sh@tokkee.org>
Mon, 28 Jan 2013 21:10:06 +0000 (22:10 +0100)
Else, we would unnecessarily skip one iteration even when being able to
reconnect right away.

src/postgresql.c

index e3a66743464e46b917fe8e25c760c650a0037e27..0a646391fcc7acf8affe444bb50387926184ffd3 100644 (file)
@@ -511,6 +511,12 @@ static int c_psql_exec_query (c_psql_database_t *db, udb_query_t *q,
        if (PGRES_TUPLES_OK != PQresultStatus (res)) {
                pthread_mutex_lock (&db->db_lock);
 
+               if ((CONNECTION_OK != PQstatus (db->conn))
+                               && (0 == c_psql_check_connection (db))) {
+                       PQclear (res);
+                       return c_psql_exec_query (db, q, prep_area);
+               }
+
                log_err ("Failed to execute SQL query: %s",
                                PQerrorMessage (db->conn));
                log_info ("SQL query was: %s",