mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-23 07:06:30 +00:00
Compare commits
46 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
51aa63c8f9 | ||
|
|
e53162deb8 | ||
|
|
6a8336b880 | ||
|
|
4a445e7f8a | ||
|
|
3c1d72a5ea | ||
|
|
d4b9a32a86 | ||
|
|
07a216ca25 | ||
|
|
d3c067f1bd | ||
|
|
e6caf11bf2 | ||
|
|
9909881d81 | ||
|
|
8073a294f0 | ||
|
|
bf5e0b9b48 | ||
|
|
2e9f4aa30f | ||
|
|
0dcacc3a70 | ||
|
|
65120c47cf | ||
|
|
f9397c0f06 | ||
|
|
af3c865b05 | ||
|
|
112a11a311 | ||
|
|
7b87b5eddd | ||
|
|
1aa36ca1c1 | ||
|
|
a7eff1f39e | ||
|
|
e64e230559 | ||
|
|
bba167db9e | ||
|
|
2676adcaed | ||
|
|
5a27d5e57b | ||
|
|
4071589ba5 | ||
|
|
6cb2376974 | ||
|
|
235c98a0b5 | ||
|
|
16da2f48c2 | ||
|
|
c23e5858f2 | ||
|
|
30ccee43d9 | ||
|
|
9357f89d12 | ||
|
|
48da11acfd | ||
|
|
07c54c296c | ||
|
|
8f0b9592e8 | ||
|
|
b35bf3f91d | ||
|
|
04c101c5f0 | ||
|
|
65989840d2 | ||
|
|
24bd4e7a3f | ||
|
|
1c67e105ff | ||
|
|
069f9ff2ed | ||
|
|
b8ade8e908 | ||
|
|
c0abb3be31 | ||
|
|
0a71123920 | ||
|
|
a72c2296e9 | ||
|
|
9c3d79147b |
23
HISTORY
23
HISTORY
@@ -1,10 +1,17 @@
|
||||
2.0.1 2014-07-16
|
||||
Documentation fixes and new QUICKSTART file (Ian)
|
||||
Explicitly specify directories to ignore when cloning (Ian)
|
||||
Fix log level for some log messages (Ian)
|
||||
RHEL/CentOS specfile, init script and Makefile fixes (Nathan Van Overloop)
|
||||
2.0.2 2015-02-17
|
||||
Add "--checksum" in rsync when using "--force" (Jaime)
|
||||
Use createdb/createuser instead of psql (Jaime)
|
||||
Fixes to witness creation and monitoring (wamonite)
|
||||
Use default master port if none supplied (Martín)
|
||||
Documentation fixes and improvements (Ian)
|
||||
|
||||
2.0.1 2014-07-16
|
||||
Documentation fixes and new QUICKSTART file (Ian)
|
||||
Explicitly specify directories to ignore when cloning (Ian)
|
||||
Fix log level for some log messages (Ian)
|
||||
RHEL/CentOS specfile, init script and Makefile fixes (Nathan Van Overloop)
|
||||
Debian init script and config file documentation fixes (József Kószó)
|
||||
Typo fixes (Riegie Godwin Jeyaranchen, PriceChild)
|
||||
Typo fixes (Riegie Godwin Jeyaranchen, PriceChild)
|
||||
|
||||
2.0stable 2014-01-30
|
||||
Documentation fixes (Christian)
|
||||
@@ -25,7 +32,7 @@
|
||||
Add a ssh_options parameter (Jay Taylor)
|
||||
|
||||
2.0beta1 2012-07-27
|
||||
Make CLONE command try to make an exact copy including $PGDATA location (Cedric)
|
||||
Make CLONE command try to make an exact copy including $PGDATA location (Cedric)
|
||||
Add detection of master failure (Jaime)
|
||||
Add the notion of a witness server (Jaime)
|
||||
Add autofailover capabilities (Jaime)
|
||||
@@ -52,7 +59,7 @@
|
||||
1.1.0 2011-03-09
|
||||
Make options -U, -R and -p not mandatory (Jaime)
|
||||
|
||||
1.1.0b1 2011-02-24
|
||||
1.1.0b1 2011-02-24
|
||||
Fix missing "--force" option in help (Greg Smith)
|
||||
Correct warning message for wal_keep_segments (Bas van Oostveen)
|
||||
Add Debian build/usage docs (Bas, Hannu Krosing, Cedric Villemain)
|
||||
|
||||
140
QUICKSTART.md
140
QUICKSTART.md
@@ -34,7 +34,7 @@ same PostgreSQL major version, and preferably should be running the same minor
|
||||
version.
|
||||
|
||||
repmgr will work on any Linux or UNIX-like environment capable of running
|
||||
PostgreSQL. `rsync` must also be installed.
|
||||
PostgreSQL. rsync must also be installed.
|
||||
|
||||
|
||||
Installation
|
||||
@@ -55,7 +55,7 @@ repmgr must be installed on each PostgreSQL server node.
|
||||
|
||||
repmgr can be built easily using PGXS:
|
||||
|
||||
sudo make USE_PGXS=1 install
|
||||
sudo make USE_PGXS=1 install
|
||||
|
||||
|
||||
Configuration
|
||||
@@ -71,20 +71,23 @@ between all server nodes to enable repmgr to copy required files.
|
||||
The master PostgreSQL node needs to be configured for replication with the
|
||||
following settings:
|
||||
|
||||
wal_level = 'hot_standby' # minimal, archive, hot_standby, or logical
|
||||
archive_mode = on # allows archiving to be done
|
||||
archive_command = 'cd .' # command to use to archive a logfile segment
|
||||
max_wal_senders = 10 # max number of walsender processes
|
||||
wal_keep_segments = 5000 # in logfile segments, 16MB each; 0 disables
|
||||
hot_standby = on # "on" allows queries during recovery
|
||||
wal_level = 'hot_standby' # minimal, archive, hot_standby, or logical
|
||||
archive_mode = on # allows archiving to be done
|
||||
archive_command = 'cd .' # command to use to archive a logfile segment
|
||||
max_wal_senders = 10 # max number of walsender processes
|
||||
wal_keep_segments = 5000 # in logfile segments, 16MB each; 0 disables
|
||||
hot_standby = on # "on" allows queries during recovery
|
||||
|
||||
Note that repmgr expects a default of 5000 wal_keep_segments, although this
|
||||
value can be overridden when executing the `repmgr` client.
|
||||
|
||||
Additionally, repmgr requires a dedicated PostgreSQL superuser account
|
||||
and a database in which to store monitoring and replication data. The
|
||||
database can in principle be any database, including the default postgres
|
||||
one, however it's probably advisable to create a dedicated repmgr database.
|
||||
and a database in which to store monitoring and replication data. The repmgr
|
||||
user account will also be used for replication connections from the standby,
|
||||
so a seperate replication user with the `REPLICATION` privilege is not required.
|
||||
The database can in principle be any database, including the default `postgres`
|
||||
one, however it's probably advisable to create a dedicated database for repmgr
|
||||
usage.
|
||||
|
||||
|
||||
### repmgr configuration
|
||||
@@ -92,11 +95,11 @@ one, however it's probably advisable to create a dedicated repmgr database.
|
||||
Each PostgreSQL node requires a repmgr configuration file containing
|
||||
identification and database connection information:
|
||||
|
||||
cluster=test
|
||||
node=1
|
||||
node_name=node1
|
||||
conninfo='host=repmgr_node1 user=repmgr_usr dbname=repmgr_db'
|
||||
pg_bindir=/path/to/postgres/bin
|
||||
cluster=test
|
||||
node=1
|
||||
node_name=node1
|
||||
conninfo='host=repmgr_node1 user=repmgr_usr dbname=repmgr_db'
|
||||
pg_bindir=/path/to/postgres/bin
|
||||
|
||||
* `cluster`: common name for the replication cluster; this must be the same on all nodes
|
||||
* `node`: a unique, abitrary integer identifier
|
||||
@@ -107,11 +110,11 @@ identification and database connection information:
|
||||
resolvable by all nodes on the cluster.
|
||||
* `pg_bindir`: (optional) location of PostgreSQL binaries, if not in the default $PATH
|
||||
|
||||
Note that the configuration file should *not* be stored inside the PostgreSQL
|
||||
Note that the configuration file should not be stored inside the PostgreSQL
|
||||
data directory.
|
||||
|
||||
Each node configuration needs to be registered with repmgr, either using the
|
||||
`repmgr` command line tool, or the `repmgrd` daemon; for details see below. Details
|
||||
repmgr command line tool, or the repmgrd daemon; for details see below. Details
|
||||
about each node are inserted into the repmgr database (for details see below).
|
||||
|
||||
|
||||
@@ -140,30 +143,31 @@ Master setup
|
||||
|
||||
- configure postgresql.conf for replication (see above)
|
||||
|
||||
- update pg_hba.conf:
|
||||
- update pg_hba.conf, e.g.:
|
||||
|
||||
```
|
||||
host repmgr_usr repmgr_db 192.168.1.0/24 trust
|
||||
host replication all 192.168.1.0/24 trust
|
||||
host repmgr_db repmgr_usr 192.168.1.0/24 trust
|
||||
host replication repmgr_usr 192.168.1.0/24 trust
|
||||
```
|
||||
|
||||
Restart the PostgreSQL server after making these changes.
|
||||
Restart the PostgreSQL server after making these changes.
|
||||
|
||||
2. Create the repmgr configuration file:
|
||||
|
||||
$ cat $HOME/repmgr/repmgr.conf
|
||||
cluster=test
|
||||
node=1
|
||||
node_name=node1
|
||||
conninfo='host=repmgr_node1 user=repmgr_usr dbname=repmgr_db'
|
||||
pg_bindir=/path/to/postgres/bin
|
||||
$ cat $HOME/repmgr/repmgr.conf
|
||||
cluster=test
|
||||
node=1
|
||||
node_name=node1
|
||||
conninfo='host=repmgr_node1 user=repmgr_usr dbname=repmgr_db'
|
||||
pg_bindir=/path/to/postgres/bin
|
||||
|
||||
3. Register the master node with repmgr:
|
||||
|
||||
$ repmgr -f $HOME/repmgr/repmgr.conf --verbose master register
|
||||
[2014-07-04 10:43:42] [INFO] repmgr mgr connecting to master database
|
||||
[2014-07-04 10:43:42] [INFO] repmgr connected to master, checking its state
|
||||
[2014-07-04 10:43:42] [INFO] master register: creating database objects inside the repmgr_test schema
|
||||
[2014-07-04 10:43:43] [NOTICE] Master node correctly registered for cluster test with id 1 (conninfo: host=localhost user=repmgr_usr dbname=repmgr_db)
|
||||
$ repmgr -f $HOME/repmgr/repmgr.conf --verbose master register
|
||||
[2014-07-04 10:43:42] [INFO] repmgr mgr connecting to master database
|
||||
[2014-07-04 10:43:42] [INFO] repmgr connected to master, checking its state
|
||||
[2014-07-04 10:43:42] [INFO] master register: creating database objects inside the repmgr_test schema
|
||||
[2014-07-04 10:43:43] [NOTICE] Master node correctly registered for cluster test with id 1 (conninfo: host=localhost user=repmgr_usr dbname=repmgr_db)
|
||||
|
||||
|
||||
Slave/standby setup
|
||||
@@ -171,52 +175,54 @@ Slave/standby setup
|
||||
|
||||
1. Use repmgr to clone the master:
|
||||
|
||||
$ repmgr -f $HOME/repmgr/repmgr.conf -D $PGDATA -d repmgr_db -U repmgr_usr -R postgres --verbose standby clone 192.168.1.2
|
||||
Opening configuration file: ./repmgr.conf
|
||||
[2014-07-04 10:49:00] [ERROR] Did not find the configuration file './repmgr.conf', continuing
|
||||
[2014-07-04 10:49:00] [INFO] repmgr connecting to master database
|
||||
[2014-07-04 10:49:00] [INFO] repmgr connected to master, checking its state
|
||||
[2014-07-04 10:49:00] [INFO] Successfully connected to primary. Current installation size is 1807 MB
|
||||
[2014-07-04 10:49:00] [NOTICE] Starting backup...
|
||||
[2014-07-04 10:49:00] [INFO] creating directory "/path/to/data/"...
|
||||
(...)
|
||||
[2014-07-04 10:53:19] [NOTICE] Finishing backup...
|
||||
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
|
||||
[2014-07-04 10:53:21] [INFO] repmgr requires primary to keep WAL files 0000000100000000000000AD until at least 0000000100000000000000AD
|
||||
[2014-07-04 10:53:21] [NOTICE] repmgr standby clone complete
|
||||
[2014-07-04 10:53:21] [NOTICE] HINT: You can now start your postgresql server
|
||||
[2014-07-04 10:53:21] [NOTICE] for example : /etc/init.d/postgresql start
|
||||
$ repmgr -f $HOME/repmgr/repmgr.conf -D $PGDATA -d repmgr_db -U repmgr_usr -R postgres --verbose standby clone 192.168.1.2
|
||||
Opening configuration file: ./repmgr.conf
|
||||
[2014-07-04 10:49:00] [ERROR] Did not find the configuration file './repmgr.conf', continuing
|
||||
[2014-07-04 10:49:00] [INFO] repmgr connecting to master database
|
||||
[2014-07-04 10:49:00] [INFO] repmgr connected to master, checking its state
|
||||
[2014-07-04 10:49:00] [INFO] Successfully connected to primary. Current installation size is 1807 MB
|
||||
[2014-07-04 10:49:00] [NOTICE] Starting backup...
|
||||
[2014-07-04 10:49:00] [INFO] creating directory "/path/to/data/"...
|
||||
(...)
|
||||
[2014-07-04 10:53:19] [NOTICE] Finishing backup...
|
||||
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
|
||||
[2014-07-04 10:53:21] [INFO] repmgr requires primary to keep WAL files 0000000100000000000000AD until at least 0000000100000000000000AD
|
||||
[2014-07-04 10:53:21] [NOTICE] repmgr standby clone complete
|
||||
[2014-07-04 10:53:21] [NOTICE] HINT: You can now start your postgresql server
|
||||
[2014-07-04 10:53:21] [NOTICE] for example : /etc/init.d/postgresql start
|
||||
|
||||
-R is the database system user on the master node. At this point it does not matter
|
||||
if the `repmgr.conf` file is not found.
|
||||
|
||||
This will clone the PostgreSQL database files from the master, and additionally
|
||||
create an appropriate `recovery.conf` file.
|
||||
This will clone the PostgreSQL database files from the master, including its
|
||||
`postgresql.conf` and `pg_hba.conf` files, and additionally automatically create
|
||||
the `recovery.conf` file containing the correct parameters to start streaming
|
||||
from the primary node.
|
||||
|
||||
2. Start the PostgreSQL server
|
||||
|
||||
3. Create the repmgr configuration file:
|
||||
|
||||
$ cat $HOME/repmgr/repmgr.conf
|
||||
cluster=test
|
||||
node=2
|
||||
node_name=node2
|
||||
conninfo='host=repmgr_node2 user=repmgr_usr dbname=repmgr_db'
|
||||
pg_bindir=/path/to/postgres/bin
|
||||
$ cat $HOME/repmgr/repmgr.conf
|
||||
cluster=test
|
||||
node=2
|
||||
node_name=node2
|
||||
conninfo='host=repmgr_node2 user=repmgr_usr dbname=repmgr_db'
|
||||
pg_bindir=/path/to/postgres/bin
|
||||
|
||||
4. Register the master node with repmgr:
|
||||
|
||||
$ repmgr -f $HOME/repmgr/repmgr.conf --verbose standby register
|
||||
Opening configuration file: /path/to/repmgr/repmgr.conf
|
||||
[2014-07-04 11:48:13] [INFO] repmgr connecting to standby database
|
||||
[2014-07-04 11:48:13] [INFO] repmgr connected to standby, checking its state
|
||||
[2014-07-04 11:48:13] [INFO] repmgr connecting to master database
|
||||
[2014-07-04 11:48:13] [INFO] finding node list for cluster 'test'
|
||||
[2014-07-04 11:48:13] [INFO] checking role of cluster node 'host=repmgr_node1 user=repmgr_usr dbname=repmgr_db'
|
||||
[2014-07-04 11:48:13] [INFO] repmgr connected to master, checking its state
|
||||
[2014-07-04 11:48:13] [INFO] repmgr registering the standby
|
||||
[2014-07-04 11:48:13] [INFO] repmgr registering the standby complete
|
||||
[2014-07-04 11:48:13] [NOTICE] Standby node correctly registered for cluster test with id 2 (conninfo: host=localhost user=repmgr_usr dbname=repmgr_db)
|
||||
$ repmgr -f $HOME/repmgr/repmgr.conf --verbose standby register
|
||||
Opening configuration file: /path/to/repmgr/repmgr.conf
|
||||
[2014-07-04 11:48:13] [INFO] repmgr connecting to standby database
|
||||
[2014-07-04 11:48:13] [INFO] repmgr connected to standby, checking its state
|
||||
[2014-07-04 11:48:13] [INFO] repmgr connecting to master database
|
||||
[2014-07-04 11:48:13] [INFO] finding node list for cluster 'test'
|
||||
[2014-07-04 11:48:13] [INFO] checking role of cluster node 'host=repmgr_node1 user=repmgr_usr dbname=repmgr_db'
|
||||
[2014-07-04 11:48:13] [INFO] repmgr connected to master, checking its state
|
||||
[2014-07-04 11:48:13] [INFO] repmgr registering the standby
|
||||
[2014-07-04 11:48:13] [INFO] repmgr registering the standby complete
|
||||
[2014-07-04 11:48:13] [NOTICE] Standby node correctly registered for cluster test with id 2 (conninfo: host=localhost user=repmgr_usr dbname=repmgr_db)
|
||||
|
||||
Monitoring
|
||||
----------
|
||||
|
||||
197
repmgr.c
197
repmgr.c
@@ -109,15 +109,13 @@ main(int argc, char **argv)
|
||||
{"force", no_argument, NULL, 'F'},
|
||||
{"wait", no_argument, NULL, 'W'},
|
||||
{"ignore-rsync-warning", no_argument, NULL, 'I'},
|
||||
{"min-recovery-apply-delay", required_argument, NULL, 'r'},
|
||||
{"verbose", no_argument, NULL, 'v'},
|
||||
{NULL, 0, NULL, 0}
|
||||
};
|
||||
|
||||
int optindex;
|
||||
int c, targ;
|
||||
int c;
|
||||
int action = NO_ACTION;
|
||||
char *ptr = NULL;
|
||||
|
||||
progname = get_progname(argv[0]);
|
||||
|
||||
@@ -136,7 +134,7 @@ main(int argc, char **argv)
|
||||
}
|
||||
|
||||
|
||||
while ((c = getopt_long(argc, argv, "d:h:p:U:D:l:f:R:w:k:FWIvr:", long_options,
|
||||
while ((c = getopt_long(argc, argv, "d:h:p:U:D:l:f:R:w:k:FWIv", long_options,
|
||||
&optindex)) != -1)
|
||||
{
|
||||
switch (c)
|
||||
@@ -186,25 +184,6 @@ main(int argc, char **argv)
|
||||
case 'I':
|
||||
runtime_options.ignore_rsync_warn = true;
|
||||
break;
|
||||
case 'r':
|
||||
targ = strtol(optarg, &ptr, 10);
|
||||
|
||||
if(targ < 0) {
|
||||
usage();
|
||||
exit(ERR_BAD_CONFIG);
|
||||
}
|
||||
if(ptr && *ptr) {
|
||||
if(strcmp(ptr, "ms") != 0 && strcmp(ptr, "s") != 0 &&
|
||||
strcmp(ptr, "min") != 0 && strcmp(ptr, "h") != 0 &&
|
||||
strcmp(ptr, "d") != 0)
|
||||
{
|
||||
usage();
|
||||
exit(ERR_BAD_CONFIG);
|
||||
}
|
||||
}
|
||||
|
||||
strncpy(runtime_options.min_recovery_apply_delay, optarg, MAXLEN);
|
||||
break;
|
||||
case 'v':
|
||||
runtime_options.verbose = true;
|
||||
break;
|
||||
@@ -309,6 +288,12 @@ main(int argc, char **argv)
|
||||
strncpy(runtime_options.dbname, DEFAULT_DBNAME, MAXLEN);
|
||||
}
|
||||
|
||||
/* We check that port number is not null */
|
||||
if (!runtime_options.masterport[0])
|
||||
{
|
||||
strncpy(runtime_options.masterport, DEFAULT_MASTER_PORT, MAXLEN);
|
||||
}
|
||||
|
||||
/* Read the configuration file, normally repmgr.conf */
|
||||
if (!runtime_options.config_file[0])
|
||||
strncpy(runtime_options.config_file, DEFAULT_CONFIG_FILE, MAXLEN);
|
||||
@@ -1745,6 +1730,53 @@ do_witness_create(void)
|
||||
|
||||
fclose(pg_conf);
|
||||
|
||||
|
||||
/* start new instance */
|
||||
sprintf(script, "%s/pg_ctl %s -w -D %s start", options.pg_bindir,
|
||||
options.pgctl_options, runtime_options.dest_dir);
|
||||
log_info(_("Start cluster for witness: %s"), script);
|
||||
r = system(script);
|
||||
if (r != 0)
|
||||
{
|
||||
log_err(_("Can't start cluster for witness server\n"));
|
||||
PQfinish(masterconn);
|
||||
exit(ERR_BAD_CONFIG);
|
||||
}
|
||||
|
||||
/* check if we need to create a user */
|
||||
if (runtime_options.username[0] && runtime_options.localport[0] && strcmp(runtime_options.username,"postgres")!=0 )
|
||||
{
|
||||
/* create required user needs to be superuser to create untrusted language function in c */
|
||||
sprintf(script, "%s/createuser -p %s --superuser --login -U postgres %s", options.pg_bindir,
|
||||
runtime_options.localport,runtime_options.username);
|
||||
log_info("Create user for witness db: %s.\n", script);
|
||||
|
||||
r = system(script);
|
||||
if (r != 0)
|
||||
{
|
||||
log_err("Can't create user for witness server\n");
|
||||
PQfinish(masterconn);
|
||||
exit(ERR_BAD_CONFIG);
|
||||
}
|
||||
}
|
||||
|
||||
/* check if we need to create a database */
|
||||
if(runtime_options.dbname[0] && strcmp(runtime_options.dbname,"postgres")!=0 && runtime_options.localport[0])
|
||||
{
|
||||
/* create required db */
|
||||
sprintf(script, "%s/createdb -p %s -U postgres --owner=%s %s",
|
||||
options.pg_bindir, runtime_options.localport,runtime_options.username, runtime_options.dbname);
|
||||
log_info("Create database for witness db: %s.\n", script);
|
||||
|
||||
r = system(script);
|
||||
if (r != 0)
|
||||
{
|
||||
log_err("Can't create database for witness server\n");
|
||||
PQfinish(masterconn);
|
||||
exit(ERR_BAD_CONFIG);
|
||||
}
|
||||
}
|
||||
|
||||
/* Get the pg_hba.conf full path */
|
||||
sqlquery_snprintf(sqlquery, "SELECT name, setting "
|
||||
" FROM pg_settings "
|
||||
@@ -1777,19 +1809,20 @@ do_witness_create(void)
|
||||
PQfinish(masterconn);
|
||||
exit(ERR_BAD_CONFIG);
|
||||
}
|
||||
|
||||
/* start new instance */
|
||||
sprintf(script, "%s/pg_ctl %s -w -D %s start", options.pg_bindir,
|
||||
|
||||
/* reload to adapt for changed pg_hba.conf */
|
||||
sprintf(script, "%s/pg_ctl %s -w -D %s reload", options.pg_bindir,
|
||||
options.pgctl_options, runtime_options.dest_dir);
|
||||
log_info(_("Start cluster for witness: %s"), script);
|
||||
log_info(_("Reload cluster config for witness: %s"), script);
|
||||
r = system(script);
|
||||
if (r != 0)
|
||||
{
|
||||
log_err(_("Can't start cluster for witness server\n"));
|
||||
log_err(_("Can't reload cluster for witness server\n"));
|
||||
PQfinish(masterconn);
|
||||
exit(ERR_BAD_CONFIG);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* register ourselves in the master */
|
||||
sqlquery_snprintf(sqlquery, "INSERT INTO %s.repl_nodes(id, cluster, name, conninfo, priority, witness) "
|
||||
"VALUES (%d, '%s', '%s', '%s', %d, true)",
|
||||
@@ -1825,6 +1858,24 @@ do_witness_create(void)
|
||||
PQfinish(witnessconn);
|
||||
exit(ERR_BAD_CONFIG);
|
||||
}
|
||||
|
||||
/* drop superuser powers if needed */
|
||||
if (runtime_options.username[0] && runtime_options.localport[0] && strcmp(runtime_options.username,"postgres")!=0 )
|
||||
{
|
||||
sqlquery_snprintf(sqlquery, "ALTER ROLE %s NOSUPERUSER", runtime_options.username);
|
||||
log_info("Drop superuser powers on user for witness db: %s.\n", sqlquery);
|
||||
|
||||
log_debug(_("witness create: %s"), sqlquery);
|
||||
res = PQexec(witnessconn, sqlquery);
|
||||
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
|
||||
{
|
||||
log_err(_("Cannot alter user privileges, %s\n"),
|
||||
PQerrorMessage(witnessconn));
|
||||
PQfinish(masterconn);
|
||||
PQfinish(witnessconn);
|
||||
exit(ERR_DB_QUERY);
|
||||
}
|
||||
}
|
||||
PQfinish(masterconn);
|
||||
PQfinish(witnessconn);
|
||||
|
||||
@@ -1874,7 +1925,6 @@ help(const char *progname)
|
||||
printf(_(" -F, --force force potentially dangerous operations\n" \
|
||||
" to happen\n"));
|
||||
printf(_(" -W, --wait wait for a master to appear\n"));
|
||||
printf(_(" -r, --min-recovery-apply-delay=VALUE enable recovery time delay, value has to be a valid time atom (e.g. 5min)"));
|
||||
|
||||
printf(_("\n%s performs some tasks like clone a node, promote it or making follow\n"), progname);
|
||||
printf(_("another node and then exits.\n\n"));
|
||||
@@ -1927,19 +1977,6 @@ create_recovery_file(const char *data_dir)
|
||||
return false;
|
||||
}
|
||||
|
||||
if(*runtime_options.min_recovery_apply_delay)
|
||||
{
|
||||
maxlen_snprintf(line, "\nmin_recovery_apply_delay = %s\n",
|
||||
runtime_options.min_recovery_apply_delay);
|
||||
|
||||
if (fputs(line, recovery_file) == EOF)
|
||||
{
|
||||
log_err(_("recovery file could not be written, it could be necessary to create it manually\n"));
|
||||
fclose(recovery_file);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* FreeFile(recovery_file); */
|
||||
fclose(recovery_file);
|
||||
|
||||
@@ -1950,34 +1987,25 @@ static int
|
||||
test_ssh_connection(char *host, char *remote_user)
|
||||
{
|
||||
char script[MAXLEN];
|
||||
int r = 1, i;
|
||||
int r;
|
||||
|
||||
/* On some OS, true is located in a different place than in Linux
|
||||
* we have to try them all until all alternatives are gone or we
|
||||
* found `true' because the target OS may differ from the source
|
||||
* OS
|
||||
*/
|
||||
const char *truebin_pathes[] = {
|
||||
"/bin/true",
|
||||
"/usr/bin/true",
|
||||
NULL
|
||||
};
|
||||
/* On some OS, true is located in a different place than in Linux */
|
||||
#ifdef __FreeBSD__
|
||||
#define TRUEBIN_PATH "/usr/bin/true"
|
||||
#else
|
||||
#define TRUEBIN_PATH "/bin/true"
|
||||
#endif
|
||||
|
||||
/* Check if we have ssh connectivity to host before trying to rsync */
|
||||
for(i = 0; truebin_pathes[i] && r != 0; ++i)
|
||||
{
|
||||
if (!remote_user[0])
|
||||
maxlen_snprintf(script, "ssh -o Batchmode=yes %s %s %s",
|
||||
options.ssh_options, host, truebin_pathes[i]);
|
||||
else
|
||||
maxlen_snprintf(script, "ssh -o Batchmode=yes %s %s -l %s %s",
|
||||
options.ssh_options, host, remote_user,
|
||||
truebin_pathes[i]);
|
||||
|
||||
log_debug(_("command is: %s\n"), script);
|
||||
r = system(script);
|
||||
}
|
||||
if (!remote_user[0])
|
||||
maxlen_snprintf(script, "ssh -o Batchmode=yes %s %s %s",
|
||||
options.ssh_options, host, TRUEBIN_PATH);
|
||||
else
|
||||
maxlen_snprintf(script, "ssh -o Batchmode=yes %s %s -l %s %s",
|
||||
options.ssh_options, host, remote_user, TRUEBIN_PATH);
|
||||
|
||||
log_debug(_("command is: %s\n"), script);
|
||||
r = system(script);
|
||||
if (r != 0)
|
||||
log_info(_("Can not connect to the remote host (%s)\n"), host);
|
||||
return r;
|
||||
@@ -2000,7 +2028,7 @@ copy_remote_files(char *host, char *remote_user, char *remote_path,
|
||||
maxlen_snprintf(rsync_flags, "%s", options.rsync_options);
|
||||
|
||||
if (runtime_options.force)
|
||||
strcat(rsync_flags, " --delete");
|
||||
strcat(rsync_flags, " --delete --checksum");
|
||||
|
||||
if (!remote_user[0])
|
||||
{
|
||||
@@ -2368,13 +2396,14 @@ static bool
|
||||
copy_configuration(PGconn *masterconn, PGconn *witnessconn)
|
||||
{
|
||||
char sqlquery[MAXLEN];
|
||||
PGresult *res;
|
||||
PGresult *res1;
|
||||
PGresult *res2;
|
||||
int i;
|
||||
|
||||
sqlquery_snprintf(sqlquery, "TRUNCATE TABLE %s.repl_nodes", repmgr_schema);
|
||||
log_debug("copy_configuration: %s\n", sqlquery);
|
||||
res = PQexec(witnessconn, sqlquery);
|
||||
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
|
||||
res1 = PQexec(witnessconn, sqlquery);
|
||||
if (!res1 || PQresultStatus(res1) != PGRES_COMMAND_OK)
|
||||
{
|
||||
fprintf(stderr, "Cannot clean node details in the witness, %s\n",
|
||||
PQerrorMessage(witnessconn));
|
||||
@@ -2383,33 +2412,35 @@ copy_configuration(PGconn *masterconn, PGconn *witnessconn)
|
||||
|
||||
sqlquery_snprintf(sqlquery, "SELECT id, name, conninfo, priority, witness FROM %s.repl_nodes",
|
||||
repmgr_schema);
|
||||
res = PQexec(masterconn, sqlquery);
|
||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||
res1 = PQexec(masterconn, sqlquery);
|
||||
if (PQresultStatus(res1) != PGRES_TUPLES_OK)
|
||||
{
|
||||
fprintf(stderr, "Can't get configuration from master: %s\n",
|
||||
PQerrorMessage(masterconn));
|
||||
PQclear(res);
|
||||
PQclear(res1);
|
||||
return false;
|
||||
}
|
||||
for (i = 0; i < PQntuples(res); i++)
|
||||
for (i = 0; i < PQntuples(res1); i++)
|
||||
{
|
||||
sqlquery_snprintf(sqlquery, "INSERT INTO %s.repl_nodes(id, cluster, name, conninfo, priority, witness) "
|
||||
"VALUES (%d, '%s', '%s', '%s', %d, '%s')",
|
||||
repmgr_schema, atoi(PQgetvalue(res, i, 0)),
|
||||
options.cluster_name, PQgetvalue(res, i, 1),
|
||||
PQgetvalue(res, i, 2),
|
||||
atoi(PQgetvalue(res, i, 3)),
|
||||
PQgetvalue(res, i, 4));
|
||||
repmgr_schema, atoi(PQgetvalue(res1, i, 0)),
|
||||
options.cluster_name, PQgetvalue(res1, i, 1),
|
||||
PQgetvalue(res1, i, 2),
|
||||
atoi(PQgetvalue(res1, i, 3)),
|
||||
PQgetvalue(res1, i, 4));
|
||||
|
||||
res = PQexec(witnessconn, sqlquery);
|
||||
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
|
||||
res2 = PQexec(witnessconn, sqlquery);
|
||||
if (!res2 || PQresultStatus(res2) != PGRES_COMMAND_OK)
|
||||
{
|
||||
fprintf(stderr, "Cannot copy configuration to witness, %s\n",
|
||||
PQerrorMessage(witnessconn));
|
||||
PQclear(res);
|
||||
PQclear(res2);
|
||||
return false;
|
||||
}
|
||||
PQclear(res2);
|
||||
}
|
||||
PQclear(res1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
4
repmgr.h
4
repmgr.h
@@ -67,10 +67,8 @@ typedef struct
|
||||
|
||||
/* parameter used by CLUSTER CLEANUP */
|
||||
int keep_history;
|
||||
|
||||
char min_recovery_apply_delay[MAXLEN];
|
||||
} t_runtime_options;
|
||||
|
||||
#define T_RUNTIME_OPTIONS_INITIALIZER { "", "", "", "", "", "", DEFAULT_WAL_KEEP_SEGMENTS, false, false, false, false, "", "", 0, "" }
|
||||
#define T_RUNTIME_OPTIONS_INITIALIZER { "", "", "", "", "", "", DEFAULT_WAL_KEEP_SEGMENTS, false, false, false, false, "", "", 0 }
|
||||
|
||||
#endif
|
||||
|
||||
@@ -551,7 +551,7 @@ witness_monitor(void)
|
||||
sqlquery_snprintf(sqlquery,
|
||||
"INSERT INTO %s.repl_monitor "
|
||||
"VALUES(%d, %d, '%s'::timestamp with time zone, "
|
||||
" pg_current_xlog_location(), null, "
|
||||
" null, pg_current_xlog_location(), null, "
|
||||
" 0, 0)",
|
||||
repmgr_schema, primary_options.node, local_options.node,
|
||||
monitor_witness_timestamp);
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#define _STRUTIL_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errcode.h>
|
||||
#include "errcode.h"
|
||||
|
||||
#define QUERY_STR_LEN 8192
|
||||
#define MAXLEN 1024
|
||||
|
||||
Reference in New Issue
Block a user