mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-26 16:46:28 +00:00
Add simple output for CLUSTER EVENT
This commit is contained in:
100
repmgr-client.c
100
repmgr-client.c
@@ -505,6 +505,7 @@ check_cli_parameters(const int action)
|
||||
{
|
||||
case STANDBY_UNREGISTER:
|
||||
case WITNESS_UNREGISTER:
|
||||
case CLUSTER_EVENT:
|
||||
break;
|
||||
default:
|
||||
item_list_append_format(&cli_warnings,
|
||||
@@ -520,6 +521,7 @@ check_cli_parameters(const int action)
|
||||
{
|
||||
case STANDBY_UNREGISTER:
|
||||
case WITNESS_UNREGISTER:
|
||||
case CLUSTER_EVENT:
|
||||
if (runtime_options.node_id != UNKNOWN_NODE_ID)
|
||||
{
|
||||
item_list_append(&cli_warnings,
|
||||
@@ -842,15 +844,104 @@ do_standby_clone(void)
|
||||
static void
|
||||
do_cluster_event(void)
|
||||
{
|
||||
puts("cluster event");
|
||||
PGconn *conn;
|
||||
PQExpBufferData query;
|
||||
PQExpBufferData where_clause;
|
||||
PGresult *res;
|
||||
int i;
|
||||
|
||||
conn = establish_db_connection(config_file_options.conninfo, true);
|
||||
|
||||
initPQExpBuffer(&query);
|
||||
initPQExpBuffer(&where_clause);
|
||||
|
||||
appendPQExpBuffer(&query,
|
||||
" SELECT node_id, event, successful, \n"
|
||||
" TO_CHAR( event_timestamp, 'YYYY-MM-DD HH24:MI:SS') AS timestamp, \n"
|
||||
" details \n"
|
||||
" FROM repmgr.events");
|
||||
|
||||
if (runtime_options.node_id != UNKNOWN_NODE_ID)
|
||||
{
|
||||
append_where_clause(&where_clause,
|
||||
"node_id=%i", runtime_options.node_id);
|
||||
}
|
||||
|
||||
if (runtime_options.event[0] != '\0')
|
||||
{
|
||||
char *escaped = escape_string(conn, runtime_options.event);
|
||||
|
||||
if (escaped == NULL)
|
||||
{
|
||||
log_error(_("unable to escape value provided for event"));
|
||||
}
|
||||
else
|
||||
{
|
||||
append_where_clause(&where_clause,
|
||||
"event='%s'",
|
||||
escaped);
|
||||
pfree(escaped);
|
||||
}
|
||||
}
|
||||
|
||||
appendPQExpBuffer(&query, "\n%s\n",
|
||||
where_clause.data);
|
||||
|
||||
appendPQExpBuffer(&query,
|
||||
" ORDER BY timestamp DESC");
|
||||
|
||||
if (runtime_options.all == false && runtime_options.limit > 0)
|
||||
{
|
||||
appendPQExpBuffer(&query, " LIMIT %i",
|
||||
runtime_options.limit);
|
||||
}
|
||||
|
||||
log_debug("do_cluster_event():\n%s", query.data);
|
||||
res = PQexec(conn, query.data);
|
||||
|
||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||
{
|
||||
log_error(_("unable to execute event query:\n %s"),
|
||||
PQerrorMessage(conn));
|
||||
PQclear(res);
|
||||
PQfinish(conn);
|
||||
exit(ERR_DB_QUERY);
|
||||
}
|
||||
|
||||
if (PQntuples(res) == 0) {
|
||||
printf(_("no matching events found\n"));
|
||||
PQclear(res);
|
||||
PQfinish(conn);
|
||||
return;
|
||||
}
|
||||
|
||||
/* XXX improve formatting */
|
||||
puts("node_id,event,ok,timestamp,details");
|
||||
puts("----------------------------------");
|
||||
for(i = 0; i < PQntuples(res); i++)
|
||||
{
|
||||
printf("%s,%s,%s,%s,%s\n",
|
||||
PQgetvalue(res, i, 0),
|
||||
PQgetvalue(res, i, 1),
|
||||
PQgetvalue(res, i, 2),
|
||||
PQgetvalue(res, i, 3),
|
||||
PQgetvalue(res, i, 4));
|
||||
}
|
||||
|
||||
PQclear(res);
|
||||
|
||||
PQfinish(conn);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Create the repmgr extension, and grant access to the repmgr
|
||||
* Create the repmgr extension, and grant access for the repmgr
|
||||
* user if not a superuser.
|
||||
*
|
||||
* Note: this should be the only place where superuser rights are required
|
||||
* Note:
|
||||
* This should be the only place where superuser rights are required.
|
||||
* We should also consider possible scenarious where a non-superuser
|
||||
* has sufficient privileges to install the extension.
|
||||
*/
|
||||
static
|
||||
bool create_repmgr_extension(PGconn *conn)
|
||||
@@ -899,8 +990,6 @@ bool create_repmgr_extension(PGconn *conn)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
PQclear(res);
|
||||
termPQExpBuffer(&query);
|
||||
|
||||
@@ -932,6 +1021,7 @@ bool create_repmgr_extension(PGconn *conn)
|
||||
return false;
|
||||
}
|
||||
|
||||
/* check provided superuser really is superuser */
|
||||
superuser_status = PQparameterStatus(superuser_conn, "is_superuser");
|
||||
if (strcmp(superuser_status, "off") == 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user