mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-22 22:56:29 +00:00
Initial table definitions and coding for repmgr client utility
This commit is contained in:
@@ -26,7 +26,7 @@ include Makefile.global
|
||||
|
||||
$(info Building against PostgreSQL $(MAJORVERSION))
|
||||
|
||||
REPMGR_CLIENT_OBJS = repmgr-client.o
|
||||
REPMGR_CLIENT_OBJS = repmgr-client.o config.o
|
||||
REPMGRD_OBJS = repmgrd.o
|
||||
|
||||
repmgr4: $(REPMGR_CLIENT_OBJS)
|
||||
|
||||
24
config.c
Normal file
24
config.c
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* config.c - parse repmgr.conf and other configuration-related functionality
|
||||
*
|
||||
* Copyright (c) 2ndQuadrant, 2010-2017
|
||||
*/
|
||||
|
||||
#include <sys/stat.h> /* for stat() */
|
||||
|
||||
#include "repmgr.h"
|
||||
#include "config.h"
|
||||
|
||||
const static char *_progname = NULL;
|
||||
|
||||
void
|
||||
set_progname(const char *argv0)
|
||||
{
|
||||
_progname = get_progname(argv0);
|
||||
}
|
||||
|
||||
const char *
|
||||
progname(void)
|
||||
{
|
||||
return _progname;
|
||||
}
|
||||
14
config.h
Normal file
14
config.h
Normal file
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* config.h
|
||||
*
|
||||
* Copyright (c) 2ndQuadrant, 2010-2017
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _REPMGR_CONFIG_H_
|
||||
#define _REPMGR_CONFIG_H_
|
||||
|
||||
void set_progname(const char *argv0);
|
||||
const char * progname(void);
|
||||
|
||||
#endif
|
||||
@@ -3,5 +3,33 @@
|
||||
|
||||
CREATE TABLE nodes (
|
||||
node_id INTEGER PRIMARY KEY,
|
||||
type TEXT NOT NULL CHECK (type IN('master','standby','witness','bdr'))
|
||||
upstream_node_id INTEGER NULL REFERENCES nodes (node_id) DEFERRABLE,
|
||||
active BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
node_name TEXT NOT NULL,
|
||||
type TEXT NOT NULL CHECK (type IN('master','standby','witness','bdr')),
|
||||
|
||||
priority INT NOT NULL DEFAULT 100,
|
||||
conninfo TEXT NOT NULL,
|
||||
slot_name TEXT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE events (
|
||||
node_id INTEGER NOT NULL,
|
||||
event TEXT NOT NULL,
|
||||
successful BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
event_timestamp TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
details TEXT NULL
|
||||
);
|
||||
|
||||
|
||||
CREATE VIEW show_nodes AS
|
||||
SELECT n.node_id,
|
||||
n.node_name,
|
||||
un.node_name AS upstream_node_name,
|
||||
n.type,
|
||||
n.priority,
|
||||
n.conninfo
|
||||
FROM nodes n
|
||||
LEFT JOIN nodes un
|
||||
ON un.node_id = n.upstream_node_id;
|
||||
|
||||
|
||||
@@ -8,14 +8,54 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "repmgr.h"
|
||||
#include "repmgr-client.h"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
puts("repmgr");
|
||||
return 0;
|
||||
int optindex;
|
||||
int c, targ;
|
||||
int action = NO_ACTION;
|
||||
|
||||
set_progname(argv[0]);
|
||||
|
||||
while ((c = getopt_long(argc, argv, "?Vd:h:p:U:S:D:f:R:w:k:FWIvb:rcL:tm:C:", long_options,
|
||||
&optindex)) != -1)
|
||||
{
|
||||
/*
|
||||
* NOTE: some integer parameters (e.g. -p/--port) are stored internally
|
||||
* as strings. We use repmgr_atoi() to check these but discard the
|
||||
* returned integer; repmgr_atoi() will append the error message to the
|
||||
* provided list.
|
||||
*/
|
||||
switch (c)
|
||||
{
|
||||
case OPT_HELP:
|
||||
do_help();
|
||||
exit(SUCCESS);
|
||||
|
||||
case '?':
|
||||
/* Actual help option given */
|
||||
if (strcmp(argv[optind - 1], "-?") == 0)
|
||||
{
|
||||
do_help();
|
||||
exit(SUCCESS);
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
do_help(void)
|
||||
{
|
||||
printf(_("%s: replication management tool for PostgreSQL\n"), progname());
|
||||
printf(_("\n"));
|
||||
printf(_("Usage:\n"));
|
||||
|
||||
}
|
||||
|
||||
109
repmgr-client.h
Normal file
109
repmgr-client.h
Normal file
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* repmgr-client.h
|
||||
* Copyright (c) 2ndQuadrant, 2010-2017
|
||||
*/
|
||||
|
||||
#include <getopt_long.h>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#ifndef _REPMGR_CLIENT_H_
|
||||
#define _REPMGR_CLIENT_H_
|
||||
|
||||
#ifndef RECOVERY_COMMAND_FILE
|
||||
#define RECOVERY_COMMAND_FILE "recovery.conf"
|
||||
#endif
|
||||
|
||||
#ifndef TABLESPACE_MAP
|
||||
#define TABLESPACE_MAP "tablespace_map"
|
||||
#endif
|
||||
|
||||
#define WITNESS_DEFAULT_PORT "5499" /* If this value is ever changed, remember
|
||||
* to update comments and documentation */
|
||||
|
||||
#define NO_ACTION 0 /* Dummy default action */
|
||||
#define MASTER_REGISTER 1
|
||||
#define STANDBY_REGISTER 2
|
||||
#define STANDBY_UNREGISTER 3
|
||||
#define STANDBY_CLONE 4
|
||||
#define STANDBY_PROMOTE 5
|
||||
#define STANDBY_FOLLOW 6
|
||||
#define STANDBY_SWITCHOVER 7
|
||||
#define STANDBY_ARCHIVE_CONFIG 8
|
||||
#define STANDBY_RESTORE_CONFIG 9
|
||||
#define WITNESS_CREATE 10
|
||||
#define WITNESS_REGISTER 11
|
||||
#define WITNESS_UNREGISTER 12
|
||||
#define CLUSTER_SHOW 13
|
||||
#define CLUSTER_CLEANUP 14
|
||||
#define CLUSTER_MATRIX 15
|
||||
#define CLUSTER_CROSSCHECK 16
|
||||
#define BDR_REGISTER 17
|
||||
#define BDR_UNREGISTER 18
|
||||
|
||||
/* command line options without short versions */
|
||||
#define OPT_HELP 1
|
||||
#define OPT_CHECK_UPSTREAM_CONFIG 2
|
||||
#define OPT_RECOVERY_MIN_APPLY_DELAY 3
|
||||
#define OPT_COPY_EXTERNAL_CONFIG_FILES 4
|
||||
#define OPT_CONFIG_ARCHIVE_DIR 5
|
||||
#define OPT_PG_REWIND 6
|
||||
#define OPT_PWPROMPT 7
|
||||
#define OPT_CSV 8
|
||||
#define OPT_NODE 9
|
||||
#define OPT_WITHOUT_BARMAN 10
|
||||
#define OPT_NO_UPSTREAM_CONNECTION 11
|
||||
#define OPT_REGISTER_WAIT 12
|
||||
#define OPT_CLUSTER 13
|
||||
#define OPT_LOG_TO_FILE 14
|
||||
#define OPT_UPSTREAM_CONNINFO 15
|
||||
#define OPT_NO_CONNINFO_PASSWORD 16
|
||||
#define OPT_REPLICATION_USER 17
|
||||
|
||||
static struct option long_options[] =
|
||||
{
|
||||
{"version", no_argument, NULL, 'V'},
|
||||
{"help", no_argument, NULL, OPT_HELP},
|
||||
{"dbname", required_argument, NULL, 'd'},
|
||||
{"host", required_argument, NULL, 'h'},
|
||||
{"port", required_argument, NULL, 'p'},
|
||||
{"username", required_argument, NULL, 'U'},
|
||||
{"superuser", required_argument, NULL, 'S'},
|
||||
{"pgdata", required_argument, NULL, 'D'},
|
||||
{"config-file", required_argument, NULL, 'f'},
|
||||
{"remote-user", required_argument, NULL, 'R'},
|
||||
{"wal-keep-segments", required_argument, NULL, 'w'},
|
||||
{"keep-history", required_argument, NULL, 'k'},
|
||||
{"force", no_argument, NULL, 'F'},
|
||||
{"wait", no_argument, NULL, 'W'},
|
||||
{"verbose", no_argument, NULL, 'v'},
|
||||
{"pg_bindir", required_argument, NULL, 'b'},
|
||||
{"rsync-only", no_argument, NULL, 'r'},
|
||||
{"fast-checkpoint", no_argument, NULL, 'c'},
|
||||
{"log-level", required_argument, NULL, 'L'},
|
||||
{"terse", required_argument, NULL, 't'},
|
||||
{"mode", required_argument, NULL, 'm'},
|
||||
{"remote-config-file", required_argument, NULL, 'C'},
|
||||
{"check-upstream-config", no_argument, NULL, OPT_CHECK_UPSTREAM_CONFIG},
|
||||
{"recovery-min-apply-delay", required_argument, NULL, OPT_RECOVERY_MIN_APPLY_DELAY},
|
||||
{"pg_rewind", optional_argument, NULL, OPT_PG_REWIND},
|
||||
{"pwprompt", optional_argument, NULL, OPT_PWPROMPT},
|
||||
{"csv", no_argument, NULL, OPT_CSV},
|
||||
{"node", required_argument, NULL, OPT_NODE},
|
||||
{"without-barman", no_argument, NULL, OPT_WITHOUT_BARMAN},
|
||||
{"no-upstream-connection", no_argument, NULL, OPT_NO_UPSTREAM_CONNECTION},
|
||||
{"copy-external-config-files", optional_argument, NULL, OPT_COPY_EXTERNAL_CONFIG_FILES},
|
||||
{"wait-sync", optional_argument, NULL, OPT_REGISTER_WAIT},
|
||||
{"log-to-file", no_argument, NULL, OPT_LOG_TO_FILE},
|
||||
{"upstream-conninfo", required_argument, NULL, OPT_UPSTREAM_CONNINFO},
|
||||
{"replication-user", required_argument, NULL, OPT_REPLICATION_USER},
|
||||
{"no-conninfo-password", no_argument, NULL, OPT_NO_CONNINFO_PASSWORD},
|
||||
/* Following options for internal use */
|
||||
{"cluster", required_argument, NULL, OPT_CLUSTER},
|
||||
{"config-archive-dir", required_argument, NULL, OPT_CONFIG_ARCHIVE_DIR},
|
||||
{NULL, 0, NULL, 0}
|
||||
};
|
||||
|
||||
static void do_help(void);
|
||||
|
||||
#endif
|
||||
6
repmgr.h
6
repmgr.h
@@ -5,12 +5,16 @@
|
||||
#ifndef _REPMGR_H_
|
||||
#define _REPMGR_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <libpq-fe.h>
|
||||
#include <postgres_fe.h>
|
||||
#include <getopt_long.h>
|
||||
#include <pqexpbuffer.h>
|
||||
|
||||
#define MIN_SUPPORTED_VERSION "9.3"
|
||||
#define MIN_SUPPORTED_VERSION_NUM 90300
|
||||
|
||||
// to errcodes.h
|
||||
#define SUCCESS 0
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user