Skip to content

Commit ed1cb42

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 7d1e0e8 commit ed1cb42

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
@@ -767,9 +767,19 @@ ProcessWalSndrMessage(XLogRecPtr walEnd, TimestampTz sendTime)
767767
SpinLockRelease(&walrcv->mutex);
768768

769769
if (log_min_messages <= DEBUG2)
770+
{
771+
char *sendtime;
772+
char *receipttime;
773+
774+
/* Copy because timestamptz_to_str returns a static buffer */
775+
sendtime = pstrdup(timestamptz_to_str(sendTime));
776+
receipttime = pstrdup(timestamptz_to_str(lastMsgReceiptTime));
770777
elog(DEBUG2, "sendtime %s receipttime %s replication apply delay %d ms transfer latency %d ms",
771-
timestamptz_to_str(sendTime),
772-
timestamptz_to_str(lastMsgReceiptTime),
778+
sendtime,
779+
receipttime,
773780
GetReplicationApplyDelay(),
774781
GetReplicationTransferLatency());
782+
pfree(sendtime);
783+
pfree(receipttime);
784+
}
775785
}

0 commit comments

Comments
 (0)