mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-23 15:16:29 +00:00
Compare commits
5 Commits
v1.2.0
...
REL1_2_STA
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e479ef4bd1 | ||
|
|
6390a41953 | ||
|
|
d7d91e1c12 | ||
|
|
d5ec394c54 | ||
|
|
f6093386a8 |
@@ -129,10 +129,10 @@ mkdir_p(char *path, mode_t omode)
|
|||||||
{
|
{
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
mode_t numask,
|
mode_t numask,
|
||||||
oumask;
|
oumask;
|
||||||
int first,
|
int first,
|
||||||
last,
|
last,
|
||||||
retval;
|
retval;
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
p = path;
|
p = path;
|
||||||
|
|||||||
84
repmgr.c
84
repmgr.c
@@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
@@ -125,7 +126,7 @@ main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
while ((c = getopt_long(argc, argv, "d:h:p:U:D:f:R:w:k:F:I:v", long_options,
|
while ((c = getopt_long(argc, argv, "d:h:p:U:D:f:R:w:k:FIv", long_options,
|
||||||
&optindex)) != -1)
|
&optindex)) != -1)
|
||||||
{
|
{
|
||||||
switch (c)
|
switch (c)
|
||||||
@@ -160,7 +161,7 @@ main(int argc, char **argv)
|
|||||||
if (atoi(optarg) > 0)
|
if (atoi(optarg) > 0)
|
||||||
runtime_options.keep_history = atoi(optarg);
|
runtime_options.keep_history = atoi(optarg);
|
||||||
else
|
else
|
||||||
runtime_options.keep_history = 0;
|
runtime_options.keep_history = 0;
|
||||||
break;
|
break;
|
||||||
case 'F':
|
case 'F':
|
||||||
runtime_options.force = true;
|
runtime_options.force = true;
|
||||||
@@ -255,7 +256,7 @@ main(int argc, char **argv)
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
log_err(_("%s: too many command-line arguments (first extra is \"%s\")\n"),
|
log_err(_("%s: too many command-line arguments (first extra is \"%s\")\n"),
|
||||||
progname, argv[optind + 1]);
|
progname, argv[optind]);
|
||||||
usage();
|
usage();
|
||||||
exit(ERR_BAD_CONFIG);
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
@@ -367,7 +368,7 @@ do_cluster_show(void)
|
|||||||
conn = establishDBConnection(options.conninfo, true);
|
conn = establishDBConnection(options.conninfo, true);
|
||||||
|
|
||||||
sqlquery_snprintf(sqlquery, "SELECT conninfo FROM %s.repl_nodes;", repmgr_schema);
|
sqlquery_snprintf(sqlquery, "SELECT conninfo FROM %s.repl_nodes;", repmgr_schema);
|
||||||
log_debug("cluster show: %s\n", sqlquery);
|
log_debug("cluster show: %s\n", sqlquery);
|
||||||
res = PQexec(conn, sqlquery);
|
res = PQexec(conn, sqlquery);
|
||||||
|
|
||||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||||
@@ -403,7 +404,7 @@ static void
|
|||||||
do_cluster_cleanup(void)
|
do_cluster_cleanup(void)
|
||||||
{
|
{
|
||||||
int master_id;
|
int master_id;
|
||||||
PGconn *conn;
|
PGconn *conn;
|
||||||
PGconn *master_conn;
|
PGconn *master_conn;
|
||||||
PGresult *res;
|
PGresult *res;
|
||||||
char sqlquery[QUERY_STR_LEN];
|
char sqlquery[QUERY_STR_LEN];
|
||||||
@@ -429,15 +430,15 @@ do_cluster_cleanup(void)
|
|||||||
if (runtime_options.keep_history > 0)
|
if (runtime_options.keep_history > 0)
|
||||||
{
|
{
|
||||||
sqlquery_snprintf(sqlquery, "DELETE FROM %s.repl_monitor "
|
sqlquery_snprintf(sqlquery, "DELETE FROM %s.repl_monitor "
|
||||||
" WHERE age(now(), last_monitor_time) >= '%d days'::interval;",
|
" WHERE age(now(), last_monitor_time) >= '%d days'::interval;",
|
||||||
repmgr_schema, runtime_options.keep_history);
|
repmgr_schema, runtime_options.keep_history);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sqlquery_snprintf(sqlquery, "TRUNCATE TABLE %s.repl_monitor;", repmgr_schema);
|
sqlquery_snprintf(sqlquery, "TRUNCATE TABLE %s.repl_monitor;", repmgr_schema);
|
||||||
}
|
}
|
||||||
|
|
||||||
log_debug("cluster cleanup: %s\n", sqlquery);
|
log_debug("cluster cleanup: %s\n", sqlquery);
|
||||||
res = PQexec(master_conn, sqlquery);
|
res = PQexec(master_conn, sqlquery);
|
||||||
if (PQresultStatus(res) != PGRES_COMMAND_OK)
|
if (PQresultStatus(res) != PGRES_COMMAND_OK)
|
||||||
{
|
{
|
||||||
@@ -450,7 +451,7 @@ do_cluster_cleanup(void)
|
|||||||
|
|
||||||
/* Let's VACUUM the table to avoid autovacuum to be launched in an unexpected hour */
|
/* Let's VACUUM the table to avoid autovacuum to be launched in an unexpected hour */
|
||||||
sqlquery_snprintf(sqlquery, "VACUUM %s.repl_monitor;", repmgr_schema);
|
sqlquery_snprintf(sqlquery, "VACUUM %s.repl_monitor;", repmgr_schema);
|
||||||
log_debug("cluster cleanup: %s\n", sqlquery);
|
log_debug("cluster cleanup: %s\n", sqlquery);
|
||||||
res = PQexec(master_conn, sqlquery);
|
res = PQexec(master_conn, sqlquery);
|
||||||
|
|
||||||
/* XXX There is any need to check this VACUUM happens without problems? */
|
/* XXX There is any need to check this VACUUM happens without problems? */
|
||||||
@@ -1038,7 +1039,7 @@ do_standby_clone(void)
|
|||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
exit(ERR_BAD_CONFIG);
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We need all 4 parameters, and they can be retrieved only by superusers */
|
/* We need all 4 parameters, and they can be retrieved only by superusers */
|
||||||
if (PQntuples(res) != 4)
|
if (PQntuples(res) != 4)
|
||||||
{
|
{
|
||||||
@@ -1603,11 +1604,18 @@ test_ssh_connection(char *host, char *remote_user)
|
|||||||
char script[MAXLEN];
|
char script[MAXLEN];
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
|
/* 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 */
|
/* Check if we have ssh connectivity to host before trying to rsync */
|
||||||
if (!remote_user[0])
|
if (!remote_user[0])
|
||||||
maxlen_snprintf(script, "ssh -o Batchmode=yes %s /bin/true", host);
|
maxlen_snprintf(script, "ssh -o Batchmode=yes %s %s", host, TRUEBIN_PATH);
|
||||||
else
|
else
|
||||||
maxlen_snprintf(script, "ssh -o Batchmode=yes %s -l %s /bin/true", host, remote_user);
|
maxlen_snprintf(script, "ssh -o Batchmode=yes %s -l %s %s", host, remote_user, TRUEBIN_PATH);
|
||||||
|
|
||||||
log_debug(_("command is: %s"), script);
|
log_debug(_("command is: %s"), script);
|
||||||
r = system(script);
|
r = system(script);
|
||||||
@@ -1633,7 +1641,7 @@ copy_remote_files(char *host, char *remote_user, char *remote_path,
|
|||||||
maxlen_snprintf(rsync_flags, "%s", options.rsync_options);
|
maxlen_snprintf(rsync_flags, "%s", options.rsync_options);
|
||||||
|
|
||||||
if (runtime_options.force)
|
if (runtime_options.force)
|
||||||
strcat(rsync_flags, " --delete");
|
strcat(rsync_flags, " --delete --checksum");
|
||||||
|
|
||||||
if (!remote_user[0])
|
if (!remote_user[0])
|
||||||
{
|
{
|
||||||
@@ -1825,32 +1833,36 @@ check_parameters_for_action(const int action)
|
|||||||
static void
|
static void
|
||||||
write_primary_conninfo(char* line)
|
write_primary_conninfo(char* line)
|
||||||
{
|
{
|
||||||
char host_buf[MAXLEN] = "";
|
char host_buf[MAXLEN] = "";
|
||||||
char conn_buf[MAXLEN] = "";
|
char conn_buf[MAXLEN] = "";
|
||||||
char user_buf[MAXLEN] = "";
|
char user_buf[MAXLEN] = "";
|
||||||
char password_buf[MAXLEN] = "";
|
char password_buf[MAXLEN] = "";
|
||||||
|
|
||||||
/* Environment variable for password (UGLY, please use .pgpass!) */
|
/* Environment variable for password (UGLY, please use .pgpass!) */
|
||||||
const char *password = getenv("PGPASSWORD");
|
const char *password = getenv("PGPASSWORD");
|
||||||
if (password != NULL) {
|
if (password != NULL)
|
||||||
maxlen_snprintf(password_buf, " password=%s", password);
|
{
|
||||||
}
|
maxlen_snprintf(password_buf, " password=%s", password);
|
||||||
else if (require_password) {
|
}
|
||||||
log_err(_("%s: PGPASSWORD not set, but having one is required\n"),
|
else if (require_password)
|
||||||
progname);
|
{
|
||||||
exit(ERR_BAD_PASSWORD);
|
log_err(_("%s: PGPASSWORD not set, but having one is required\n"),
|
||||||
}
|
progname);
|
||||||
|
exit(ERR_BAD_PASSWORD);
|
||||||
|
}
|
||||||
|
|
||||||
if (runtime_options.host[0]) {
|
if (runtime_options.host[0])
|
||||||
maxlen_snprintf(host_buf, " host=%s", runtime_options.host);
|
{
|
||||||
}
|
maxlen_snprintf(host_buf, " host=%s", runtime_options.host);
|
||||||
|
}
|
||||||
|
|
||||||
if (runtime_options.username[0]) {
|
if (runtime_options.username[0])
|
||||||
maxlen_snprintf(user_buf, " user=%s", runtime_options.username);
|
{
|
||||||
}
|
maxlen_snprintf(user_buf, " user=%s", runtime_options.username);
|
||||||
|
}
|
||||||
|
|
||||||
maxlen_snprintf(conn_buf, "port=%s%s%s%s",
|
maxlen_snprintf(conn_buf, "port=%s%s%s%s",
|
||||||
(runtime_options.masterport[0]) ? runtime_options.masterport : "5432", host_buf, user_buf, password_buf);
|
(runtime_options.masterport[0]) ? runtime_options.masterport : "5432", host_buf, user_buf, password_buf);
|
||||||
|
|
||||||
maxlen_snprintf(line, "primary_conninfo = '%s'", conn_buf);
|
maxlen_snprintf(line, "primary_conninfo = '%s'", conn_buf);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -186,7 +186,7 @@ main(int argc, char **argv)
|
|||||||
/* I need the id of the primary as well as a connection to it */
|
/* I need the id of the primary as well as a connection to it */
|
||||||
log_info(_("%s Connecting to primary for cluster '%s'\n"),
|
log_info(_("%s Connecting to primary for cluster '%s'\n"),
|
||||||
progname, local_options.cluster_name);
|
progname, local_options.cluster_name);
|
||||||
primaryConn = getMasterConnection(myLocalConn,
|
primaryConn = getMasterConnection(myLocalConn,
|
||||||
local_options.cluster_name,
|
local_options.cluster_name,
|
||||||
&primary_options.node,NULL);
|
&primary_options.node,NULL);
|
||||||
if (primaryConn == NULL)
|
if (primaryConn == NULL)
|
||||||
@@ -270,7 +270,7 @@ MonitorExecute(void)
|
|||||||
log_err(_("We couldn't reconnect to master. Now checking if another node has been promoted.\n"));
|
log_err(_("We couldn't reconnect to master. Now checking if another node has been promoted.\n"));
|
||||||
for (connection_retries = 0; connection_retries < 6; connection_retries++)
|
for (connection_retries = 0; connection_retries < 6; connection_retries++)
|
||||||
{
|
{
|
||||||
primaryConn = getMasterConnection(myLocalConn,
|
primaryConn = getMasterConnection(myLocalConn,
|
||||||
local_options.cluster_name, &primary_options.node,NULL);
|
local_options.cluster_name, &primary_options.node,NULL);
|
||||||
if (PQstatus(primaryConn) == CONNECTION_OK)
|
if (PQstatus(primaryConn) == CONNECTION_OK)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user