Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f3nUF-0006cL-7d for pgsql-bugs@arkaria.postgresql.org; Wed, 04 Apr 2018 18:50:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f3nUE-0008Np-5y for pgsql-bugs@arkaria.postgresql.org; Wed, 04 Apr 2018 18:50:22 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f3nUD-0008NL-Vp for pgsql-bugs@lists.postgresql.org; Wed, 04 Apr 2018 18:50:22 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f3nUA-0006OQ-QS for pgsql-bugs@postgresql.org; Wed, 04 Apr 2018 18:50:21 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w34IoCCv022962; Wed, 4 Apr 2018 14:50:12 -0400 From: Tom Lane To: Michael Paquier cc: TipTop Labs , Dmitry Dolgov <9erthalion6@gmail.com>, Masahiko Sawada , Michael Paquier , PostgreSQL mailing lists Subject: Re: BUG #14999: pg_rewind corrupts control file global/pg_control In-reply-to: <20180404072625.GB2208@paquier.xyz> References: <20180305075431.GH2266@paquier.xyz> <20180305090111.GI2266@paquier.xyz> <20180307014624.GC1744@paquier.xyz> <30255.1522711675@sss.pgh.pa.us> <20180403024110.GB1621@paquier.xyz> <20180404072625.GB2208@paquier.xyz> Comments: In-reply-to Michael Paquier message dated "Wed, 04 Apr 2018 16:26:25 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <22960.1522867812.1@sss.pgh.pa.us> Date: Wed, 04 Apr 2018 14:50:12 -0400 Message-ID: <22961.1522867812@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Michael Paquier writes: > So after that I falled back to your patch and began testing it, which is > where I noticed that we can *never* give the insurance to recover a data > folder on which an error has happened in the middle of a pg_rewind. The > reason for that is quite simple: even if the truncation has been moved > down to the moment where the first chunk of a file is received, you may > have already done work on some relation files. Particularly, some of > them may have been truncated down to a given size without a new range of > blocks fetched from the source. So the data folder would be in an > inconsistent state if trying to rewind it again. Yes, we certainly cannot guarantee that failure partway through pg_rewind leaves a consistent state of the target data directory. It is likely worth pointing that out in the documentation. Whether we can or should do anything about it is a different question. When I first started looking at this thread, I wondered if maybe somebody had had in mind to create an active defense against starting a postmaster in an inconsistent target cluster, by dint of intentionally truncating pg_control before the transfer starts and not making it valid again till the very end. It's now clear from looking at the code that that's not what's going on :-(. But I wonder how hard it would be to make it so, and whether that'd be worth doing if it's not too hard. Actually, probably a safer way to attack that would be to remove or rename the topmost PG_VERSION file, and then put it back afterwards. That'd be far easier to recover from manually, if need be, than clobbering pg_control. In any case, that seems separate from the question of what to do with read-only files in the data directory. Should we push forward with committing Michael's previous patch, and leave that issue for later? regards, tom lane