]> granicus.if.org Git - postgresql/commitdiff
Fix bogus time printout in walreceiver's debug log messages.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 4 Apr 2014 15:43:38 +0000 (11:43 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 4 Apr 2014 15:44:13 +0000 (11:44 -0400)
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

index ae087535f780c50d26e8e883a07fbf0a983b888a..60ad86d2a60398781154ada23c2dad16ba865381 100644 (file)
@@ -1196,9 +1196,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);
+       }
 }