aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2018-08-01 17:39:07 -0400
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2018-08-01 17:47:15 -0400
commitc40489e449ea08e154cd62fa055785873f7bdac8 (patch)
treec97f4789aa534001c9ca479d0a89570066375e87 /src
parent91bc213d90c5a8f2b2e162d4ecf09b9301027ceb (diff)
downloadpostgresql-c40489e449ea08e154cd62fa055785873f7bdac8.tar.gz
postgresql-c40489e449ea08e154cd62fa055785873f7bdac8.zip
Fix logical replication slot initialization
This was broken in commit 9c7d06d60680, which inadvertently gave the wrong value to fast_forward in one StartupDecodingContext call. Fix by flipping the value. Add a test for the obvious error, namely trying to initialize a replication slot with an nonexistent output plugin. While at it, move the CreateDecodingContext call earlier, so that any errors are reported before sending the CopyBoth message. Author: Dave Cramer <davecramer@gmail.com> Reviewed-by: Andres Freund <andres@anarazel.de> Discussion: https://postgr.es/m/CADK3HHLVkeRe1v4P02-5hj55H3_yJg3AEtpXyEY5T3wuzO2jSg@mail.gmail.com
Diffstat (limited to 'src')
-rw-r--r--src/backend/replication/logical/logical.c2
-rw-r--r--src/backend/replication/walsender.c23
2 files changed, 14 insertions, 11 deletions
diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c
index 3cd4eefb9bf..bb83fc9d42d 100644
--- a/src/backend/replication/logical/logical.c
+++ b/src/backend/replication/logical/logical.c
@@ -312,7 +312,7 @@ CreateInitDecodingContext(char *plugin,
ReplicationSlotSave();
ctx = StartupDecodingContext(NIL, InvalidXLogRecPtr, xmin_horizon,
- need_full_snapshot, true,
+ need_full_snapshot, false,
read_page, prepare_write, do_write,
update_progress);
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index d60026dfd1a..c83ff3b5732 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -1068,6 +1068,19 @@ StartLogicalReplication(StartReplicationCmd *cmd)
got_STOPPING = true;
}
+ /*
+ * Create our decoding context, making it start at the previously ack'ed
+ * position.
+ *
+ * Do this before sending CopyBoth, so that any errors are reported early.
+ */
+ logical_decoding_ctx =
+ CreateDecodingContext(cmd->startpoint, cmd->options, false,
+ logical_read_xlog_page,
+ WalSndPrepareWrite, WalSndWriteData,
+ WalSndUpdateProgress);
+
+
WalSndSetState(WALSNDSTATE_CATCHUP);
/* Send a CopyBothResponse message, and start streaming */
@@ -1077,16 +1090,6 @@ StartLogicalReplication(StartReplicationCmd *cmd)
pq_endmessage(&buf);
pq_flush();
- /*
- * Initialize position to the last ack'ed one, then the xlog records begin
- * to be shipped from that position.
- */
- logical_decoding_ctx = CreateDecodingContext(cmd->startpoint, cmd->options,
- false,
- logical_read_xlog_page,
- WalSndPrepareWrite,
- WalSndWriteData,
- WalSndUpdateProgress);
/* Start reading WAL from the oldest required WAL. */
logical_startptr = MyReplicationSlot->data.restart_lsn;