pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: TAKATSUKA Haruka <harukat@sraoss.co.jp>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #15402: Hot standby server with archive_mode=on keeps initial WAL segments
Date: Thu, 27 Sep 2018 13:44:30 +0900
Message-ID: <20180927044430.GP1659@paquier.xyz> (raw)
In-Reply-To: <20180926141236.160707712aea82341f01b03f@sraoss.co.jp>
References: <15402-a453c90ed4cf88b2@postgresql.org>
	<20180926035205.GJ1659@paquier.xyz>
	<20180926133640.99bfbc7ea82f71aa91a02c11@sraoss.co.jp>
	<20180926141236.160707712aea82341f01b03f@sraoss.co.jp>

On Wed, Sep 26, 2018 at 02:12:36PM +0900, TAKATSUKA Haruka wrote:
> I think is it natural that some segments are not archived when you 
> switch archive_mode back-and-forth.
> 
> I also think a fix to prevent generating .ready file at hot standby
> server in this case is better. I don't have a concrete idea to do so now.

I looked at this problem, and I completely agree.  From what I can see,
the restart point run on the standby creates a .ready file for the
oldest segment because there were no .done file present in it, so the
checkpointer thinks that it should mark the file with .ready, and then
makes it ready for archiving, which is never going to happen with
archive_mode = on.  All the newer segments are already marked with
.done, so they are getting recycled correctly.

Your patch is not completely correct though, as the origin of the
problem comes from XLogArchiveCheckDone(), which should be made more
solid depending on the archive mode used.  The solution attached
actually fixes a second bug, which is less annoying by the way, as past
backup history files may stay behind on standbys.  I looked at all the
code paths of XLogArchivingActive() and that's the only problem I can
see. In guc.c, SHOW archive_command would print as "(disabled)" on
standbys even if archive_mode = on, but we lived with this behavior for
ages.  The user can understand that archiving is enabled only on a
primary this way when looking at a standby, so that should not be
changed.

Takatsuka-san, what do you think?
--
Michael

Attachments:

  [text/x-diff] archive-standby-checks.patch (900B, ../20180927044430.GP1659@paquier.xyz/2-archive-standby-checks.patch)
  download | inline diff:
diff --git a/src/backend/access/transam/xlogarchive.c b/src/backend/access/transam/xlogarchive.c
index 4a039b1190..a0e53119ef 100644
--- a/src/backend/access/transam/xlogarchive.c
+++ b/src/backend/access/transam/xlogarchive.c
@@ -620,9 +620,16 @@ XLogArchiveCheckDone(const char *xlog)
 {
 	char		archiveStatusPath[MAXPGPATH];
 	struct stat stat_buf;
+	bool		inRecovery = RecoveryInProgress();
 
-	/* Always deletable if archiving is off */
-	if (!XLogArchivingActive())
+	/*
+	 * The file is always deletable if archive_mode is "off".  On standbys
+	 * archiving is disabled if archive_mode is "on", and enabled with
+	 * "always".  On a primary, archiving is enabled if archive_mode is
+	 * "on" or "always".
+	 */
+	if (!((XLogArchivingActive() && !inRecovery) ||
+		  (XLogArchivingAlways() && inRecovery)))
 		return true;
 
 	/* First check for .done --- this means archiver is done with it */

  [application/pgp-signature] signature.asc (832B, ../20180927044430.GP1659@paquier.xyz/3-signature.asc)
  download

view thread (9+ messages)  latest in thread

Message-ID: <20180927044430.GP1659@paquier.xyz>
Permalink:  ../20180927044430.GP1659@paquier.xyz/
Also on:    postgresql.org/message-id/20180927044430.GP1659@paquier.xyz

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: michael@paquier.xyz, harukat@sraoss.co.jp, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #15402: Hot standby server with archive_mode=on keeps initial WAL segments
  In-Reply-To: <20180927044430.GP1659@paquier.xyz>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox