aboutsummaryrefslogtreecommitdiff
path: root/src/backend/replication/logical/logicalfuncs.c
diff options
context:
space:
mode:
authorSimon Riggs <simon@2ndQuadrant.com>2016-09-05 09:44:38 +0100
committerSimon Riggs <simon@2ndQuadrant.com>2016-09-05 09:44:38 +0100
commitd851bef2d60ff9345249ff67c053e37fe4b364cc (patch)
treedbed79cd566941b179fe9e6b9d930a0502b6af99 /src/backend/replication/logical/logicalfuncs.c
parentb6182081be4a795d70b966be2542ad32d1ffbc20 (diff)
downloadpostgresql-d851bef2d60ff9345249ff67c053e37fe4b364cc.tar.gz
postgresql-d851bef2d60ff9345249ff67c053e37fe4b364cc.zip
Dirty replication slots when using sql interface
When pg_logical_slot_get_changes(...) sets confirmed_flush_lsn to the point at which replay stopped, it doesn't dirty the replication slot. So if the replay didn't cause restart_lsn or catalog_xmin to change as well, this change will not get written out to disk. Even on a clean shutdown. If Pg crashes or restarts, a subsequent pg_logical_slot_get_changes(...) call will see the same changes already replayed since it uses the slot's confirmed_flush_lsn as the start point for fetching changes. The caller can't specify a start LSN when using the SQL interface. Mark the slot as dirty after reading changes using the SQL interface so that users won't see repeated changes after a clean shutdown. Repeated changes still occur when using the walsender interface or after an unclean shutdown. Craig Ringer
Diffstat (limited to 'src/backend/replication/logical/logicalfuncs.c')
-rw-r--r--src/backend/replication/logical/logicalfuncs.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/backend/replication/logical/logicalfuncs.c b/src/backend/replication/logical/logicalfuncs.c
index 4e4c8cdaeb2..9c7be2dc7b6 100644
--- a/src/backend/replication/logical/logicalfuncs.c
+++ b/src/backend/replication/logical/logicalfuncs.c
@@ -321,7 +321,22 @@ pg_logical_slot_get_changes_guts(FunctionCallInfo fcinfo, bool confirm, bool bin
* business..)
*/
if (ctx->reader->EndRecPtr != InvalidXLogRecPtr && confirm)
+ {
LogicalConfirmReceivedLocation(ctx->reader->EndRecPtr);
+ /*
+ * If only the confirmed_flush_lsn has changed the slot won't get
+ * marked as dirty by the above. Callers on the walsender interface
+ * are expected to keep track of their own progress and don't need
+ * it written out. But SQL-interface users cannot specify their own
+ * start positions and it's harder for them to keep track of their
+ * progress, so we should make more of an effort to save it for them.
+ *
+ * Dirty the slot so it's written out at the next checkpoint. We'll
+ * still lose its position on crash, as documented, but it's better
+ * than always losing the position even on clean restart.
+ */
+ ReplicationSlotMarkDirty();
+ }
/* free context, call shutdown callback */
FreeDecodingContext(ctx);