From d9bda915bbc2fb9ec39dcb88dd111ace140ca63d Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Thu, 4 Aug 2016 10:34:33 +0900 Subject: [PATCH] Update documentation and --help output for `witness register` This completes the implementation of GitHub #186 --- HISTORY | 6 +++--- README.md | 21 +++++++++++++++++++-- repmgr.c | 24 +++++++++++++++++------- 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/HISTORY b/HISTORY index 190459be..76f6d7b5 100644 --- a/HISTORY +++ b/HISTORY @@ -1,11 +1,11 @@ 3.2 2016- repmgr: suppress connection error display in `repmgr cluster show` unless `--verbose` supplied (Ian) + repmgr: add commands `witness register` and `witness unregister` (Ian) + repmgr: enable `standby unregister` / `witness unregister` to be + executed for a node which is not running (Ian) repmgr: remove deprecated command line options --initdb-no-pwprompt and -l/--local-port (Ian) - repmgr: add command `witness unregister` - repmgr: enable `standby unregister` / `witness unregister` to be - executed for a node which is not running 3.1.4 2016-07-12 repmgr: new configuration option for setting "restore_command" diff --git a/README.md b/README.md index 3d65c399..11a8e0bc 100644 --- a/README.md +++ b/README.md @@ -1170,6 +1170,8 @@ makes sense to create a witness server in conjunction with running `repmgrd`; the witness server will require its own `repmgrd` instance. + + repmgrd and cascading replication --------------------------------- @@ -1241,7 +1243,8 @@ The following event types are available: * `standby_follow` * `standby_switchover` * `witness_create` - * `witness_create` + * `witness_register` + * `witness_unregister` * `repmgrd_start` * `repmgrd_shutdown` * `repmgrd_failover_promote` @@ -1386,12 +1389,26 @@ which contains connection details for the local database. This command also requires the location of the witness server's data directory to be provided (`-D/--datadir`) as well as valid connection - parameters for the master server. + parameters for the master server. If not explicitly provided, + database and user names will be extracted from the `conninfo` string in + `repmgr.conf`. By default this command will create a superuser and a repmgr user. The `repmgr` user name will be extracted from the `conninfo` string in `repmgr.conf`. +* `witness register` + + This will set up the witness server configuration, including the witness + server's copy of the `repmgr` meta database, on a running PostgreSQL + instance and register the witness server with the master. It requires + the same command line options as `witness create`. + +* `witness unregister` + + Removes the entry for a witness server from the `repl_nodes` table. This + command will not shut down the witness server or remove its data directory. + * `cluster show` Displays information about each active node in the replication cluster. This diff --git a/repmgr.c b/repmgr.c index ed42fbf0..f3e052c4 100644 --- a/repmgr.c +++ b/repmgr.c @@ -4204,6 +4204,8 @@ do_witness_register(PGconn *masterconn) char repmgr_db[MAXLEN]; bool record_created; + bool event_is_register = true; + char event_type[MAXLEN]; /* * Extract the repmgr user and database names from the conninfo string @@ -4218,6 +4220,8 @@ do_witness_register(PGconn *masterconn) /* masterconn will only be set when called from do_witness_create() */ if (masterconn == NULL) { + event_is_register = false; + masterconn = establish_db_connection_by_params((const char**)param_keywords, (const char**)param_values, false); if (PQstatus(masterconn) != CONNECTION_OK) @@ -4228,6 +4232,12 @@ do_witness_register(PGconn *masterconn) } } + /* set the event type based on how we were called */ + if (event_is_register == true) + strcpy(event_type, "witness_register"); + else + strcpy(event_type, "witness_create"); + /* establish a connection to the witness, and create the schema */ witnessconn = establish_db_connection(options.conninfo, false); @@ -4236,7 +4246,7 @@ do_witness_register(PGconn *masterconn) create_event_record(masterconn, &options, options.node, - "witness_create", + event_type, false, _("Unable to connect to witness server")); PQfinish(masterconn); @@ -4253,7 +4263,7 @@ do_witness_register(PGconn *masterconn) create_event_record(masterconn, &options, options.node, - "witness_create", + event_type, false, _("Unable to create schema on witness")); PQfinish(masterconn); @@ -4299,7 +4309,7 @@ do_witness_register(PGconn *masterconn) create_event_record(masterconn, &options, options.node, - "witness_create", + event_type, false, "Unable to create witness node record on master"); @@ -4314,7 +4324,7 @@ do_witness_register(PGconn *masterconn) create_event_record(masterconn, &options, options.node, - "witness_create", + event_type, false, _("Unable to copy configuration from master")); @@ -4359,7 +4369,7 @@ do_witness_register(PGconn *masterconn) create_event_record(masterconn, &options, options.node, - "witness_create", + event_type, true, NULL); @@ -4467,7 +4477,7 @@ do_help(void) printf(_(" %s [OPTIONS] master register\n"), progname()); printf(_(" %s [OPTIONS] standby {register|unregister|clone|promote|follow|switchover}\n"), progname()); - printf(_(" %s [OPTIONS] witness {create|unregister}\n"), progname()); + printf(_(" %s [OPTIONS] witness {create|register|unregister}\n"), progname()); printf(_(" %s [OPTIONS] cluster {show|cleanup}\n"), progname()); printf(_("\n")); printf(_("General options:\n")); @@ -4514,7 +4524,6 @@ do_help(void) " optionally providing a path to the binary\n")); printf(_(" -k, --keep-history=VALUE (cluster cleanup) retain indicated number of days of history (default: 0)\n")); printf(_(" --csv (cluster show) output in CSV mode (0 = master, 1 = standby, -1 = down)\n")); -/* printf(_(" --initdb-no-pwprompt (witness server) no superuser password prompt during initdb\n"));*/ printf(_(" -P, --pwprompt (witness server) prompt for password when creating users\n")); printf(_(" -S, --superuser=USERNAME (witness server) superuser username for witness database\n" \ " (default: postgres)\n")); @@ -4530,6 +4539,7 @@ do_help(void) printf(_(" standby follow - makes standby follow a new master\n")); printf(_(" standby switchover - switch this standby with the current master\n")); printf(_(" witness create - creates a new witness server\n")); + printf(_(" witness register - registers a witness server\n")); printf(_(" witness unregister - unregisters a witness server\n")); printf(_(" cluster show - displays information about cluster nodes\n")); printf(_(" cluster cleanup - prunes or truncates monitoring history\n" \