Skip to content

Commit b674a07

Browse files
skkyalCommitfest Bot
authored andcommitted
Fix duplicate insert during pg_createsubscriber
When pg_createsubscriber is run, the standby node is recovered to a point 'consistent_lsn' and promoted. Then, when the subscription is created, the replication origin is advanced to the 'consistent_lsn'. Then the subscription is enabled and the apply worker starts to send changes from 'consistent_lsn'. When this 'consistent_lsn' is an LSN corresponding to a COMMIT, the records for the transaction for that COMMIT are already replicated to the standby node during the recovery phase. Now, when the subscription is created, the replication origin is advanced and the subscription is enabled. The apply worker starts to apply changes from 'consistent_lsn'. So, records corresponding to the transaction whose COMMIT LSN is 'consistent_lsn' are replicated again. To avoid this, set recovery_target_inclusive = false instead of true. So the standby will recovery till point just before 'consistent_lsn'. And apply worker will start(after enabling of subscription) to apply changes from 'consistent_lsn'. So, above scenorio is avoided.
1 parent 0810fbb commit b674a07

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/bin/pg_basebackup/pg_createsubscriber.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,7 @@ setup_recovery(const struct LogicalRepInfo *dbinfo, const char *datadir, const c
12511251
appendPQExpBufferStr(recoveryconfcontents,
12521252
"recovery_target_timeline = 'latest'\n");
12531253
appendPQExpBufferStr(recoveryconfcontents,
1254-
"recovery_target_inclusive = true\n");
1254+
"recovery_target_inclusive = false\n");
12551255
appendPQExpBufferStr(recoveryconfcontents,
12561256
"recovery_target_action = promote\n");
12571257
appendPQExpBufferStr(recoveryconfcontents, "recovery_target_name = ''\n");

0 commit comments

Comments
 (0)