Skip to content

Commit 8120c74

Browse files
committed
Fix bogus time printout in walreceiver's debug log messages.
The displayed sendtime and receipttime were always exactly equal, because somebody forgot that timestamptz_to_str returns a static buffer (thereby simplifying life for most callers, at the cost of complicating it for those who need two results concurrently). Apply the same pstrdup solution used by the other call sites with this issue. Back-patch to 9.2 where the faulty code was introduced. Per bug #9849 from Haruka Takatsuka, though this is not exactly his patch. Possibly we should change timestamptz_to_str's API, but I wouldn't want to do so in the back branches.
1 parent 59202fa commit 8120c74

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/backend/replication/walreceiver.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,9 +1199,19 @@ ProcessWalSndrMessage(XLogRecPtr walEnd, TimestampTz sendTime)
11991199
SpinLockRelease(&walrcv->mutex);
12001200

12011201
if (log_min_messages <= DEBUG2)
1202+
{
1203+
char *sendtime;
1204+
char *receipttime;
1205+
1206+
/* Copy because timestamptz_to_str returns a static buffer */
1207+
sendtime = pstrdup(timestamptz_to_str(sendTime));
1208+
receipttime = pstrdup(timestamptz_to_str(lastMsgReceiptTime));
12021209
elog(DEBUG2, "sendtime %s receipttime %s replication apply delay %d ms transfer latency %d ms",
1203-
timestamptz_to_str(sendTime),
1204-
timestamptz_to_str(lastMsgReceiptTime),
1210+
sendtime,
1211+
receipttime,
12051212
GetReplicationApplyDelay(),
12061213
GetReplicationTransferLatency());
1214+
pfree(sendtime);
1215+
pfree(receipttime);
1216+
}
12071217
}

0 commit comments

Comments
 (0)