X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=inline;f=src%2Fpostgresql.c;h=16e539a0244d442e5cc473837cf02da7e72b7925;hb=a321fd49b6e74ffddd67e9c5b44b4d6ce3a8bbe8;hp=e7b247e77e8fa983d131012d1149c869c24e5ff9;hpb=8291596f0172404039f0928bcaea4b1e4cafbc97;p=collectd.git diff --git a/src/postgresql.c b/src/postgresql.c index e7b247e7..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 @@ -971,7 +975,7 @@ static int c_psql_flush (cdtime_t timeout, size_t i; if ((ud != NULL) && (ud->data != NULL)) { - dbs = (c_psql_database_t **)&ud->data; + dbs = (void *)&ud->data; dbs_num = 1; }