X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fpostgresql.c;h=16e539a0244d442e5cc473837cf02da7e72b7925;hb=f2106c1e8c35c24e274f5ec08b70e967ade27ba4;hp=98ceb6d3dc78cec10bd7ed4966ee5d50a7204567;hpb=5efcb2fe5ca723225e4100314a8668d8abc9424a;p=collectd.git diff --git a/src/postgresql.c b/src/postgresql.c index 98ceb6d3..16e539a0 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", @@ -568,6 +571,7 @@ static int c_psql_exec_query (c_psql_database_t *db, udb_query_t *q, } if (C_PSQL_IS_UNIX_DOMAIN_SOCKET (db->host) + || (0 == strcmp (db->host, "127.0.0.1")) || (0 == strcmp (db->host, "localhost"))) host = hostname_g; else