X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fpostgresql.c;h=1eaf6bd3877570a56c0e50c045b7e90cc888cda2;hb=65121a18b0d01a120f0931776b1d552c9358f5c6;hp=98ceb6d3dc78cec10bd7ed4966ee5d50a7204567;hpb=21b429b6b5ecd2f9820d9a2516c12577a0e59d19;p=collectd.git diff --git a/src/postgresql.c b/src/postgresql.c index 98ceb6d3..1eaf6bd3 100644 --- a/src/postgresql.c +++ b/src/postgresql.c @@ -381,9 +381,6 @@ static int c_psql_check_connection (c_psql_database_t *db) c_psql_connect (db); } - /* "ping" */ - PQclear (PQexec (db->conn, "SELECT 42;")); - if (CONNECTION_OK != PQstatus (db->conn)) { PQreset (db->conn); @@ -524,6 +521,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",