Skip to content

Commit 15d90a0

Browse files
committed
Fix timestamp of sent message for write context in logical decoding
When sending data for logical decoding using the streaming replication protocol via a WAL sender, the timestamp of the sent write message is allocated at the beginning of the message when preparing for the write, and actually computed when the write message is ready to be sent. The timestamp was getting computed after sending the message. This impacts anything using logical decoding, causing for example logical replication to report mostly NULL for last_msg_send_time in pg_stat_subscription. This commit makes sure that the timestamp is computed before sending the message. This is wrong since 5a991ef, so backpatch down to 9.4. Author: Jeff Janes Discussion: https://postgr.es/m/CAMkU=1z=WMn8jt7iEdC5sYNaPgAgOASb_OW5JYv-vMdYaJSL-w@mail.gmail.com Backpatch-through: 9.4
1 parent 00ac1ec commit 15d90a0

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/backend/replication/walsender.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,9 +1072,6 @@ WalSndWriteData(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid,
10721072
TimestampTz now;
10731073
int64 now_int;
10741074

1075-
/* output previously gathered data in a CopyData packet */
1076-
pq_putmessage_noblock('d', ctx->out->data, ctx->out->len);
1077-
10781075
/*
10791076
* Fill the send timestamp last, so that it is taken as late as possible.
10801077
* This is somewhat ugly, but the protocol's set as it's already used for
@@ -1087,6 +1084,9 @@ WalSndWriteData(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid,
10871084
memcpy(&ctx->out->data[1 + sizeof(int64) + sizeof(int64)],
10881085
tmpbuf.data, sizeof(int64));
10891086

1087+
/* output previously gathered data in a CopyData packet */
1088+
pq_putmessage_noblock('d', ctx->out->data, ctx->out->len);
1089+
10901090
CHECK_FOR_INTERRUPTS();
10911091

10921092
/* Try to flush pending output to the client */

0 commit comments

Comments
 (0)