aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2019-11-06 16:12:51 +0900
committerMichael Paquier <michael@paquier.xyz>2019-11-06 16:12:51 +0900
commit404d25f3c5494db139a6898937c4d1072d085e2d (patch)
treedfb5f29d050ae2c7c1176b9d0665d06712e7240b /src
parent5c9b0cdc52e3ada22fa30cf8c4fcd78fdad29ea7 (diff)
downloadpostgresql-404d25f3c5494db139a6898937c4d1072d085e2d.tar.gz
postgresql-404d25f3c5494db139a6898937c4d1072d085e2d.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/backend/replication/walsender.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index 685cb40d089..84b08e945f8 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -1074,9 +1074,6 @@ WalSndWriteData(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid,
TimestampTz now;
int64 now_int;
- /* output previously gathered data in a CopyData packet */
- pq_putmessage_noblock('d', ctx->out->data, ctx->out->len);
-
/*
* Fill the send timestamp last, so that it is taken as late as possible.
* This is somewhat ugly, but the protocol's set as it's already used for
@@ -1089,6 +1086,9 @@ WalSndWriteData(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid,
memcpy(&ctx->out->data[1 + sizeof(int64) + sizeof(int64)],
tmpbuf.data, sizeof(int64));
+ /* output previously gathered data in a CopyData packet */
+ pq_putmessage_noblock('d', ctx->out->data, ctx->out->len);
+
CHECK_FOR_INTERRUPTS();
/* Try to flush pending output to the client */