<entry><type>text</type></entry>
<entry>Get last transaction log location received and synced to disk by
streaming replication. While streaming replication is in progress
- this will increase monotonically. But when streaming replication is
- restarted this will back off to the replication starting position,
- typically the beginning of the WAL file containing the current
- replay location. If recovery has completed this will remain static at
+ this will increase monotonically. If recovery has completed this will
+ remain static at
the value of the last WAL record received and synced to disk during
recovery. If streaming replication is disabled, or if it has not yet
started, the function returns NULL.
/* Fetch information required to start streaming */
strlcpy(conninfo, (char *) walrcv->conninfo, MAXCONNINFO);
- startpoint = walrcv->receivedUpto;
+ startpoint = walrcv->receiveStart;
SpinLockRelease(&walrcv->mutex);
/* Arrange to clean up at walreceiver exit */
/* Update shared-memory status */
SpinLockAcquire(&walrcv->mutex);
- walrcv->latestChunkStart = walrcv->receivedUpto;
- walrcv->receivedUpto = LogstreamResult.Flush;
+ if (XLByteLT(walrcv->receivedUpto, LogstreamResult.Flush))
+ {
+ walrcv->latestChunkStart = walrcv->receivedUpto;
+ walrcv->receivedUpto = LogstreamResult.Flush;
+ }
SpinLockRelease(&walrcv->mutex);
/* Signal the startup process that new WAL has arrived */
walrcv->walRcvState = WALRCV_STARTING;
walrcv->startTime = now;
- walrcv->receivedUpto = recptr;
- walrcv->latestChunkStart = recptr;
+ /*
+ * If this is the first startup of walreceiver, we initialize
+ * receivedUpto and latestChunkStart to receiveStart.
+ */
+ if (walrcv->receiveStart.xlogid == 0 &&
+ walrcv->receiveStart.xrecoff == 0)
+ {
+ walrcv->receivedUpto = recptr;
+ walrcv->latestChunkStart = recptr;
+ }
+ walrcv->receiveStart = recptr;
SpinLockRelease(&walrcv->mutex);
WalRcvState walRcvState;
pg_time_t startTime;
+ /*
+ * receiveStart is the first byte position that will be received.
+ * When startup process starts the walreceiver, it sets receiveStart
+ * to the point where it wants the streaming to begin.
+ */
+ XLogRecPtr receiveStart;
+
/*
* receivedUpto-1 is the last byte position that has already been
- * received. When startup process starts the walreceiver, it sets
- * receivedUpto to the point where it wants the streaming to begin. After
- * that, walreceiver updates this whenever it flushes the received WAL to
- * disk.
+ * received. At the first startup of walreceiver, receivedUpto is
+ * set to receiveStart. After that, walreceiver updates this whenever
+ * it flushes the received WAL to disk.
*/
XLogRecPtr receivedUpto;