/* fd and filename for currently open WAL file */
static int walfile = -1;
static char current_walfile_name[MAXPGPATH] = "";
+static bool reportFlushPosition = false;
static XLogRecPtr lastFlushPosition = InvalidXLogRecPtr;
static PGresult *HandleCopyStream(PGconn *conn, XLogRecPtr startpos,
len += 1;
sendint64(blockpos, &replybuf[len]); /* write */
len += 8;
- sendint64(lastFlushPosition, &replybuf[len]); /* flush */
+ if (reportFlushPosition)
+ sendint64(lastFlushPosition, &replybuf[len]); /* flush */
+ else
+ sendint64(InvalidXLogRecPtr, &replybuf[len]); /* flush */
len += 8;
sendint64(InvalidXLogRecPtr, &replybuf[len]); /* apply */
len += 8;
return false;
if (replication_slot != NULL)
+ {
+ /*
+ * Report the flush position, so the primary can know what WAL we'll
+ * possibly re-request, and remove older WAL safely.
+ *
+ * We only report it when a slot has explicitly been used, because
+ * reporting the flush position makes one elegible as a synchronous
+ * replica. People shouldn't include generic names in
+ * synchronous_standby_names, but we've protected them against it so
+ * far, so lets continue to do so in the situations we don't need
+ * to. Without a slot reporting back wouldn't have any effect anyway.
+ */
+ reportFlushPosition = true;
sprintf(slotcmd, "SLOT \"%s\" ", replication_slot);
+ }
else
+ {
+ reportFlushPosition = false;
slotcmd[0] = 0;
+ }
if (sysidentifier != NULL)
{