From 4a73bdcfd0f6329ffc4d226441856e8b2c8ead26 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Mon, 16 May 2022 15:50:02 +0900 Subject: [PATCH] need to provide the follow target node record for node follow internal otherwise fails when using a dedicated replication user. WIP. --- repmgr-action-standby.c | 3 +-- repmgr-client.c | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/repmgr-action-standby.c b/repmgr-action-standby.c index 36ceaede..cc9829c1 100644 --- a/repmgr-action-standby.c +++ b/repmgr-action-standby.c @@ -3348,10 +3348,9 @@ do_standby_follow_internal(PGconn *primary_conn, PGconn *follow_target_conn, t_n update_node_record_slot_name(primary_conn, config_file_options.node_id, local_node_record.slot_name); } - if (create_replication_slot(follow_target_conn, local_node_record.slot_name, - NULL, + follow_target_node_record, output) == false) { log_error("%s", output->data); diff --git a/repmgr-client.c b/repmgr-client.c index 5fcfff84..cf7f45c8 100644 --- a/repmgr-client.c +++ b/repmgr-client.c @@ -97,14 +97,15 @@ static t_user_type ReplicationSlotUser = USER_TYPE_UNKNOWN; static ItemList cli_errors = {NULL, NULL}; static ItemList cli_warnings = {NULL, NULL}; -static PGconn *_get_replication_slot_connection(PGconn *conn, - char *replication_user, - bool *use_replication_protocol); static void _determine_replication_slot_user(PGconn *conn, t_node_info *upstream_node_record, char **replication_user); +static PGconn *_get_replication_slot_connection(PGconn *conn, + char *replication_user, + bool *use_replication_protocol); + int main(int argc, char **argv) { @@ -3755,7 +3756,7 @@ create_replication_slot(PGconn *conn, char *slot_name, t_node_info *upstream_nod case USER_TYPE_UNKNOWN: log_error("unable to determine user for replication slot creation"); return false; - case REPMGR_USER: + case REPMGR_USER: log_info(_("replication slots will be created by user \"%s\""), PQuser(conn)); return true; @@ -3874,6 +3875,10 @@ drop_replication_slot_if_exists(PGconn *conn, int node_id, char *slot_name) bool use_replication_protocol = false; PGconn *slot_conn = NULL; + slot_conn = _get_replication_slot_connection(conn, + replication_user, + &use_replication_protocol); + if (use_replication_protocol == true) { success = drop_replication_slot_replprot(conn, slot_name); @@ -3955,6 +3960,15 @@ _determine_replication_slot_user(PGconn *conn, t_node_info *upstream_node_record ReplicationSlotUser = REPLICATION_USER_NODE; *replication_user = upstream_node_record->repluser; } + else + { + /* This should never happen */ + log_error("unable to determine replication slot user"); + if (upstream_node_record != NULL) + log_debug("%i %s %s", upstream_node_record->node_id, upstream_node_record->repluser, PQuser(conn)); + else + log_debug("upstream_node_record not provided"); + } } }