BUG #15402: Hot standby server with archive_mode=on keeps initial WAL segments

PG Bug reporting form <noreply@postgresql.org>

From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: harukat@sraoss.co.jp
Date: 2018-09-26T03:26:50Z
Lists: pgsql-bugs
The following bug has been logged on the website:

Bug reference:      15402
Logged by:          TAKATSUKA Haruka
Email address:      harukat@sraoss.co.jp
PostgreSQL version: 11beta4
Operating system:   Linux (CentOS 6)
Description:        

Hello PostgreSQL hackers,

A hot standby server with “archive_mode = on” keeps initial WAL segment
files
that copied by pg_basebackup. It shows the following status.
000000010000000000000042 will be kept forever in this case.

$ ls data_primary/pg_wal/
000000010000000000000042.00000028.backup  00000001000000000000004D
000000010000000000000048                  00000001000000000000004E
000000010000000000000049                  00000001000000000000004F
00000001000000000000004A                  000000010000000000000050
00000001000000000000004B                  000000010000000000000051
00000001000000000000004C                  archive_status
$ ls data_standby/pg_wal/
000000010000000000000042  00000001000000000000004B 
00000001000000000000004F
000000010000000000000048  00000001000000000000004C  archive_status
000000010000000000000049  00000001000000000000004D
00000001000000000000004A  00000001000000000000004E
$ ls data_standby/pg_wal/archive_status/
000000010000000000000042.ready  00000001000000000000004A.done
000000010000000000000048.done   00000001000000000000004B.done
000000010000000000000049.done   00000001000000000000004C.done

Though I understand renaming the .ready to .done manually can clean it,
I would like to fix the server code like the following patch.
I'd appreciate if you would consider that.

- - - - -
diff --git a/src/backend/access/transam/xlog.c
b/src/backend/access/transam/xlog.c
index 5abaeb0..191ba60 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -3963,7 +3963,9 @@ RemoveOldXlogFiles(XLogSegNo segno, XLogRecPtr
RedoRecPtr, XLogRecPtr endptr)
 		 */
 		if (strcmp(xlde->d_name + 8, lastoff + 8) <= 0)
 		{
-			if (XLogArchiveCheckDone(xlde->d_name))
+			if (XLogArchiveCheckDone(xlde->d_name) ||
+			    (XLogArchiveMode != ARCHIVE_MODE_ALWAYS &&
+			     XLogCtl->SharedRecoveryInProgress))
 			{
 				/* Update the last removed location in shared memory first */
 				UpdateLastRemovedPtr(xlde->d_name);
- - - - - -

Thanks,

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Fix WAL recycling on standbys depending on archive_mode