summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2979ae0)
raw | patch | inline | side by side (parent: 2979ae0)
author | Sebastian Harl <sh@tokkee.org> | |
Thu, 18 Oct 2012 11:06:37 +0000 (13:06 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Thu, 18 Oct 2012 11:06:37 +0000 (13:06 +0200) |
This option may be used to specify the plugin instance that should be used
instead of the database name. This allows to query multiple databases of the
same name on the same host (e.g. when running multiple database server
versions in parallel).
This fixes GH #161 suggested by Bryan Varner.
instead of the database name. This allows to query multiple databases of the
same name on the same host (e.g. when running multiple database server
versions in parallel).
This fixes GH #161 suggested by Bryan Varner.
src/postgresql.c | patch | blob | history |
diff --git a/src/postgresql.c b/src/postgresql.c
index 0a5e66c25d934acd4de939cd049e6070a3121ca9..5f29becb2bba3d9893ac3c04de3c6cb8795daccf 100644 (file)
--- a/src/postgresql.c
+++ b/src/postgresql.c
char *user;
char *password;
+ char *instance;
+
char *sslmode;
char *krbsrvname;
db->user = NULL;
db->password = NULL;
+ db->instance = sstrdup (name);
+
db->sslmode = NULL;
db->krbsrvname = NULL;
sfree (db->user);
sfree (db->password);
+ sfree (db->instance);
+
sfree (db->sslmode);
sfree (db->krbsrvname);
if (CONNECTION_OK != PQstatus (db->conn)) {
c_complain (LOG_ERR, &db->conn_complaint,
- "Failed to connect to database %s: %s",
- db->database, PQerrorMessage (db->conn));
+ "Failed to connect to database %s (%s): %s",
+ db->database, db->instance,
+ PQerrorMessage (db->conn));
return -1;
}
else if ((NULL == data) || (0 == data->params_num))
res = c_psql_exec_query_noparams (db, q);
else {
- log_err ("Connection to database \"%s\" does not support parameters "
- "(protocol version %d) - cannot execute query \"%s\".",
- db->database, db->proto_version,
+ log_err ("Connection to database \"%s\" (%s) does not support "
+ "parameters (protocol version %d) - "
+ "cannot execute query \"%s\".",
+ db->database, db->instance, db->proto_version,
udb_query_get_name (q));
return -1;
}
host = db->host;
status = udb_query_prepare_result (q, prep_area, host, "postgresql",
- db->database, column_names, (size_t) column_num, db->interval);
+ db->instance, column_names, (size_t) column_num, db->interval);
if (0 != status) {
log_err ("udb_query_prepare_result failed with status %i.",
status);
db = ud->data;
assert (NULL != db->database);
+ assert (NULL != db->instance);
if (0 != c_psql_check_connection (db))
return -1;
cf_util_get_string (c, &db->user);
else if (0 == strcasecmp (c->key, "Password"))
cf_util_get_string (c, &db->password);
+ else if (0 == strcasecmp (c->key, "Instance"))
+ cf_util_get_string (c, &db->instance);
else if (0 == strcasecmp (c->key, "SSLMode"))
cf_util_get_string (c, &db->sslmode);
else if (0 == strcasecmp (c->key, "KRBSrvName"))
ud.data = db;
ud.free_func = c_psql_database_delete;
- ssnprintf (cb_name, sizeof (cb_name), "postgresql-%s", db->database);
+ ssnprintf (cb_name, sizeof (cb_name), "postgresql-%s", db->instance);
CDTIME_T_TO_TIMESPEC (db->interval, &cb_interval);