[collectd] [PATCH] postgresql plugin: Do not open new connections during reinitialization.

Sebastian Harl sh at tokkee.org
Tue Oct 14 13:41:18 CEST 2008


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 <collectd-info at internode.com.au> for finding and reporting
this.

Signed-off-by: Sebastian Harl <sh at tokkee.org>
---
 src/postgresql.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/src/postgresql.c b/src/postgresql.c
index eecfa6b..feabf60 100644
--- a/src/postgresql.c
+++ b/src/postgresql.c
@@ -243,6 +243,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;
@@ -546,6 +548,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;
-- 
1.5.4

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mailman.verplant.org/pipermail/collectd/attachments/20081014/dd40d960/attachment.pgp 


More information about the collectd mailing list