postgres.git / summary / log / commit / refs

commit    ed1cb4241585efe86d45edfed9eaf1995aa5421f
Author:   Tom Lane <tgl@sss.pgh.pa.us>
Date:     Fri Apr 04 15:43:41 2014 +0000
First released in: 9.4.0, 9.2.9, 9.3.5

    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.


src/backend/replication/walreceiver.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c index 7a0102d694b..88e65d9501c 100644 --- a/src/backend/replication/walreceiver.c +++ b/src/backend/replication/walreceiver.c @@ -767,9 +767,19 @@ ProcessWalSndrMessage(XLogRecPtr walEnd, TimestampTz sendTime) SpinLockRelease(&walrcv->mutex); if (log_min_messages <= DEBUG2) + { + char *sendtime; + char *receipttime; + + /* Copy because timestamptz_to_str returns a static buffer */ + sendtime = pstrdup(timestamptz_to_str(sendTime)); + receipttime = pstrdup(timestamptz_to_str(lastMsgReceiptTime)); elog(DEBUG2, "sendtime %s receipttime %s replication apply delay %d ms transfer latency %d ms", - timestamptz_to_str(sendTime), - timestamptz_to_str(lastMsgReceiptTime), + sendtime, + receipttime, GetReplicationApplyDelay(), GetReplicationTransferLatency()); + pfree(sendtime); + pfree(receipttime); + } } [parent: 7d1e0e8d7a96]