From e3e1c5de4eacb02b252f50d6aa8aba2b8b986960 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Mon, 4 Apr 2016 12:56:00 +0900 Subject: [PATCH] Use "immediately_reserve" parameter in pg_create_physical_replication_slot (9.6) --- dbutils.c | 18 ++++++++++++++---- dbutils.h | 3 ++- repmgr.c | 6 ++++-- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/dbutils.c b/dbutils.c index 5a378f90..243231cb 100644 --- a/dbutils.c +++ b/dbutils.c @@ -889,7 +889,7 @@ get_repmgr_schema_quoted(PGconn *conn) bool -create_replication_slot(PGconn *conn, char *slot_name) +create_replication_slot(PGconn *conn, char *slot_name, int server_version_num) { char sqlquery[QUERY_STR_LEN]; int query_res; @@ -926,9 +926,19 @@ create_replication_slot(PGconn *conn, char *slot_name) return false; } - sqlquery_snprintf(sqlquery, - "SELECT * FROM pg_create_physical_replication_slot('%s')", - slot_name); + /* In 9.6 and later, reserve the LSN straight away */ + if (server_version_num >= 90600) + { + sqlquery_snprintf(sqlquery, + "SELECT * FROM pg_create_physical_replication_slot('%s', TRUE)", + slot_name); + } + else + { + sqlquery_snprintf(sqlquery, + "SELECT * FROM pg_create_physical_replication_slot('%s')", + slot_name); + } log_debug(_("create_replication_slot(): Creating slot '%s' on primary\n"), slot_name); log_verbose(LOG_DEBUG, "create_replication_slot():\n%s\n", sqlquery); diff --git a/dbutils.h b/dbutils.h index 9d08c8bd..8d980d8e 100644 --- a/dbutils.h +++ b/dbutils.h @@ -115,7 +115,7 @@ int wait_connection_availability(PGconn *conn, long long timeout); bool cancel_query(PGconn *conn, int timeout); char *get_repmgr_schema(void); char *get_repmgr_schema_quoted(PGconn *conn); -bool create_replication_slot(PGconn *conn, char *slot_name); +bool create_replication_slot(PGconn *conn, char *slot_name, int server_version_num); int get_slot_record(PGconn *conn, char *slot_name, t_replication_slot *record); bool drop_replication_slot(PGconn *conn, char *slot_name); bool start_backup(PGconn *conn, char *first_wal_segment, bool fast_checkpoint); @@ -133,3 +133,4 @@ int get_node_replication_state(PGconn *conn, char *node_name, char *output) t_server_type parse_node_type(const char *type); int get_data_checksum_version(const char *data_directory); #endif + diff --git a/repmgr.c b/repmgr.c index 22c8477f..74a70334 100644 --- a/repmgr.c +++ b/repmgr.c @@ -1585,7 +1585,7 @@ do_standby_clone(void) */ if (options.use_replication_slots) { - if (create_replication_slot(upstream_conn, repmgr_slot_name) == false) + if (create_replication_slot(upstream_conn, repmgr_slot_name, server_version_num) == false) { PQfinish(upstream_conn); exit(ERR_DB_QUERY); @@ -2368,7 +2368,9 @@ do_standby_follow(void) if (options.use_replication_slots) { - if (create_replication_slot(master_conn, repmgr_slot_name) == false) + int server_version_num = get_server_version(master_conn, NULL); + + if (create_replication_slot(master_conn, repmgr_slot_name, server_version_num) == false) { PQExpBufferData event_details; initPQExpBuffer(&event_details);