aboutsummaryrefslogtreecommitdiff
path: root/src/backend/replication/walreceiverfuncs.c
diff options
context:
space:
mode:
authorTatsuo Ishii <ishii@postgresql.org>2015-03-14 08:16:50 +0900
committerTatsuo Ishii <ishii@postgresql.org>2015-03-14 08:21:56 +0900
commit089b371a3977bd3a7b71a79966e8ea86296ecda3 (patch)
treeaffac4446175fa4498fdc33e03479f0eb9195a48 /src/backend/replication/walreceiverfuncs.c
parent5bdf3cf5ad3048e8376fff6ccf5dafd0e9d2e603 (diff)
downloadpostgresql-089b371a3977bd3a7b71a79966e8ea86296ecda3.tar.gz
postgresql-089b371a3977bd3a7b71a79966e8ea86296ecda3.zip
Fix integer overflow in debug message of walreceiver
The message tries to tell the replication apply delay which fails if the first WAL record is not applied yet. Fix is, instead of telling overflowed minus numeric, showing "N/A" which indicates that the delay data is not yet available. Problem reported by me and patch by Fabrízio de Royes Mello. Back patched to 9.4, 9.3 and 9.2 stable branches (9.1 and 9.0 do not have the debug message).
Diffstat (limited to 'src/backend/replication/walreceiverfuncs.c')
-rw-r--r--src/backend/replication/walreceiverfuncs.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/backend/replication/walreceiverfuncs.c b/src/backend/replication/walreceiverfuncs.c
index 9870d9cf894..9e16c20dbb2 100644
--- a/src/backend/replication/walreceiverfuncs.c
+++ b/src/backend/replication/walreceiverfuncs.c
@@ -307,7 +307,8 @@ GetWalRcvWriteRecPtr(XLogRecPtr *latestChunkStart, TimeLineID *receiveTLI)
}
/*
- * Returns the replication apply delay in ms
+ * Returns the replication apply delay in ms or -1
+ * if the apply delay info is not available
*/
int
GetReplicationApplyDelay(void)
@@ -321,6 +322,8 @@ GetReplicationApplyDelay(void)
long secs;
int usecs;
+ TimestampTz chunckReplayStartTime;
+
SpinLockAcquire(&walrcv->mutex);
receivePtr = walrcv->receivedUpto;
SpinLockRelease(&walrcv->mutex);
@@ -330,7 +333,12 @@ GetReplicationApplyDelay(void)
if (receivePtr == replayPtr)
return 0;
- TimestampDifference(GetCurrentChunkReplayStartTime(),
+ chunckReplayStartTime = GetCurrentChunkReplayStartTime();
+
+ if (chunckReplayStartTime == 0)
+ return -1;
+
+ TimestampDifference(chunckReplayStartTime,
GetCurrentTimestamp(),
&secs, &usecs);