From: Sebastian Harl Date: Tue, 14 Oct 2008 11:41:18 +0000 (+0200) Subject: postgresql plugin: Do not open new connections during reinitialization. X-Git-Tag: collectd-4.5.1~3 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=afca57287ae0c7b98e503be2a04270f06766c716;p=collectd.git postgresql plugin: Do not open new connections during reinitialization. When reinitializing the plugin a new connection to all databases has been opened. Now, we check if the connection already exists. In that case no new connection will be opened but the existing connection will be pinged instead. Thanks to Admin for finding and reporting this. Signed-off-by: Sebastian Harl Signed-off-by: Florian Forster --- diff --git a/src/postgresql.c b/src/postgresql.c index 9959690a..90e9f5db 100644 --- a/src/postgresql.c +++ b/src/postgresql.c @@ -244,6 +244,7 @@ static c_psql_database_t *c_psql_database_new (const char *name) static void c_psql_database_delete (c_psql_database_t *db) { PQfinish (db->conn); + db->conn = NULL; sfree (db->queries); db->queries_num = 0; @@ -549,6 +550,12 @@ static int c_psql_init (void) int j; + /* this will happen during reinitialization */ + if (NULL != db->conn) { + c_psql_check_connection (db); + continue; + } + status = ssnprintf (buf, buf_len, "dbname = '%s'", db->database); if (0 < status) { buf += status;