Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Y8Amj-0007fA-Kv for pgsql-hackers@arkaria.postgresql.org; Mon, 05 Jan 2015 16:45:41 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Y8Amj-0002m6-3Y for pgsql-hackers@arkaria.postgresql.org; Mon, 05 Jan 2015 16:45:41 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Y8Amh-0002k5-JC for pgsql-hackers@postgreSQL.org; Mon, 05 Jan 2015 16:45:39 +0000 Received: from smtp-outbound-1.vmware.com ([208.91.2.12]) by magus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1Y8Amc-0003WA-6K for pgsql-hackers@postgreSQL.org; Mon, 05 Jan 2015 16:45:38 +0000 Received: from sc9-mailhost1.vmware.com (sc9-mailhost1.vmware.com [10.113.161.71]) by smtp-outbound-1.vmware.com (Postfix) with ESMTP id 95AB6281BF; Mon, 5 Jan 2015 08:45:28 -0800 (PST) Received: from EX13-CAS-008.vmware.com (EX13-CAS-008.vmware.com [10.113.191.58]) by sc9-mailhost1.vmware.com (Postfix) with ESMTP id 8F5341949F; Mon, 5 Jan 2015 08:45:28 -0800 (PST) Received: from EX13-MBX-024.vmware.com (10.113.191.44) by EX13-MBX-013.vmware.com (10.113.191.33) with Microsoft SMTP Server (TLS) id 15.0.913.22; Mon, 5 Jan 2015 08:45:28 -0800 Received: from [192.168.1.90] (10.113.160.246) by EX13-MBX-024.vmware.com (10.113.191.44) with Microsoft SMTP Server (TLS) id 15.0.913.22; Mon, 5 Jan 2015 08:45:27 -0800 Message-ID: <54AABFA2.3050409@vmware.com> Date: Mon, 5 Jan 2015 18:45:22 +0200 From: Heikki Linnakangas Organization: VMware User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.3.0 MIME-Version: 1.0 To: Andres Freund CC: PostgreSQL-development Subject: Re: [COMMITTERS] pgsql: Change how first WAL segment on new timeline after promotion is References: <20150103185957.GB15316@alap3.anarazel.de> In-Reply-To: <20150103185957.GB15316@alap3.anarazel.de> Content-Type: multipart/mixed; boundary="------------000707080506050008070004" X-Originating-IP: [10.113.160.246] X-ClientProxiedBy: EX13-CAS-013.vmware.com (10.113.191.65) To EX13-MBX-024.vmware.com (10.113.191.44) X-Pg-Spam-Score: -6.9 (------) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org --------------000707080506050008070004 Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit On 01/03/2015 08:59 PM, Andres Freund wrote: > Hi Heikki, > > While writing a test script for > http://archives.postgresql.org/message-id/20141205002854.GE21964%40awork2.anarazel.de > I noticed that this commit broke starting a pg_basebackup -X * without a > recovery.conf present. Which might not be the best idea, but imo is a > perfectly valid thing to do. > > To me the changes to StartupXLOG() in that commit look a bit bogus. The > new startLogSegNo is initialized to XLByteToSeg(EndOfLog)? Which points > to the end of the record +1? Which thus isn't guaranteed to exist as a > segment (e.g. never if the last record was a XLOG_SWITCH). Ah, good point. > Did you perhaps intend to use XLogFileInit(use_existing = true) > instead of XLogFileOpen()? That works for me. Hmm, that doesn't sound right either. XLogFileInit is used when you switch to a new segment, not to open an old segment for writing. It happens to work, because with use_existing = true it will in fact always open the old segment, instead of creating a new one, but I don't think that's in the spirit of how that function's intended to be used. A very simple fix is to not try opening the segment at all. There isn't actually any requirement to have the segment open at that point, XLogWrite() will open it the first time the WAL is flushed. The WAL is flushed after writing the initial checkpoint or end-of-recovery record, which happens pretty soon anyway. Any objections to the attached? > I've attached my preliminary testscript (note it's really not that > interesting at this point) that reliably reproduces the problem for me. Thanks! - Heikki --------------000707080506050008070004 Content-Type: text/x-diff; name="fix-first-segment-open-1.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="fix-first-segment-open-1.patch" diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 5cc7e47..e623463 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -5646,7 +5646,6 @@ StartupXLOG(void) XLogRecPtr RecPtr, checkPointLoc, EndOfLog; - XLogSegNo startLogSegNo; TimeLineID PrevTimeLineID; XLogRecord *record; TransactionId oldestActiveXID; @@ -6633,7 +6632,6 @@ StartupXLOG(void) */ record = ReadRecord(xlogreader, LastRec, PANIC, false); EndOfLog = EndRecPtr; - XLByteToSeg(EndOfLog, startLogSegNo); /* * Complain if we did not roll forward far enough to render the backup @@ -6741,9 +6739,6 @@ StartupXLOG(void) * buffer cache using the block containing the last record from the * previous incarnation. */ - openLogSegNo = startLogSegNo; - openLogFile = XLogFileOpen(openLogSegNo); - openLogOff = 0; Insert = &XLogCtl->Insert; Insert->PrevBytePos = XLogRecPtrToBytePos(LastRec); Insert->CurrBytePos = XLogRecPtrToBytePos(EndOfLog); --------------000707080506050008070004 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers --------------000707080506050008070004--