From 0330fa6e62853d5678fce91f93f825175cf23204 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Thu, 28 Feb 2019 11:51:47 +0900 Subject: [PATCH] daemon status: with csv output, show repmgrd status as unknown where appropriate Previously, if PostgreSQL was not running on the node, repmgrd and pause status were shown as "0", implying their status was known. This brings the csv output in line with the human-readable output, which displays "n/a" in this case. --- doc/repmgr-daemon-status.sgml | 101 +++++++++++++++++----------------- repmgr-action-daemon.c | 14 ++++- 2 files changed, 64 insertions(+), 51 deletions(-) diff --git a/doc/repmgr-daemon-status.sgml b/doc/repmgr-daemon-status.sgml index febd8c47..1d91a374 100644 --- a/doc/repmgr-daemon-status.sgml +++ b/doc/repmgr-daemon-status.sgml @@ -33,7 +33,10 @@ repmgr daemon status can be executed on any active node in the replication cluster. A valid repmgr.conf file is required. - + + If PostgreSQL is not running on a node, &repmgr; will not be able to determine the + status of that node's repmgrd instance. + After restarting PostgreSQL on any node, the repmgrd instance @@ -87,60 +90,60 @@ - - repmgr daemon status accepts an optional parameter --csv, which - outputs the replication cluster's status in a simple CSV format, suitable for - parsing by scripts, e.g.: - + + repmgr daemon status accepts an optional parameter --csv, which + outputs the replication cluster's status in a simple CSV format, suitable for + parsing by scripts, e.g.: + $ repmgr -f /etc/repmgr.conf daemon status --csv 1,node1,primary,1,1,5722,1,100,-1 2,node2,standby,1,0,-1,1,100,1 3,node3,standby,1,1,5779,1,100,1 - - - The columns have following meanings: - - - - node ID - - + + + The columns have following meanings: + + + + node ID + + - - + + node name - - + + - - + + node type (primary or standby) - - + + - - + + PostgreSQL server running (1 = running, 0 = not running) - - + + - - - repmgrd running (1 = running, 0 = not running) - - + + + repmgrd running (1 = running, 0 = not running, -1 = unknown) + + - - - repmgrd PID (-1 if not running) - - + + + repmgrd PID (-1 if not running or status unknown) + + - - - repmgrd paused (1 = paused, 0 = not paused) - - + + + repmgrd paused (1 = paused, 0 = not paused, -1 = unknown) + + @@ -150,25 +153,25 @@ - interval in seconds since the node's upstream was last seen + interval in seconds since the node's upstream was last seen (this will be -1 if the value could not be retrieved, or the node is primary) - - - - + + + + - Display the full text of any database connection error messages + Display the full text of any database connection error messages - + diff --git a/repmgr-action-daemon.c b/repmgr-action-daemon.c index fddfa59c..2562315f 100644 --- a/repmgr-action-daemon.c +++ b/repmgr-action-daemon.c @@ -260,14 +260,24 @@ do_daemon_status(void) { if (runtime_options.output_mode == OM_CSV) { + int running = repmgrd_info[i]->running ? 1 : 0; + int paused = repmgrd_info[i]->paused ? 1 : 0; + + /* If PostgreSQL is not running, repmgrd status is unknown */ + if (repmgrd_info[i]->pg_running == false) + { + running = -1; + paused = -1; + } + printf("%i,%s,%s,%i,%i,%i,%i,%i,%i\n", cell->node_info->node_id, cell->node_info->node_name, get_node_type_string(cell->node_info->type), repmgrd_info[i]->pg_running ? 1 : 0, - repmgrd_info[i]->running ? 1 : 0, + running, repmgrd_info[i]->pid, - repmgrd_info[i]->paused ? 1 : 0, + paused, cell->node_info->priority, repmgrd_info[i]->pid == UNKNOWN_PID ? -1