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 1f89qT-0000ZG-TF for pgsql-bugs@arkaria.postgresql.org; Mon, 16 Apr 2018 19:31:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f89qS-0002ZR-Ro for pgsql-bugs@arkaria.postgresql.org; Mon, 16 Apr 2018 19:31:20 +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 1f89qS-0002ZH-IF for pgsql-bugs@lists.postgresql.org; Mon, 16 Apr 2018 19:31:20 +0000 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1f89qN-0005kQ-KW for pgsql-bugs@postgresql.org; Mon, 16 Apr 2018 19:31:20 +0000 Received: by mail-wr0-x242.google.com with SMTP id d1so29143071wrj.13 for ; Mon, 16 Apr 2018 12:31:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=uhJDgmlSFpzzP221Tg8a7I3IOQ+ykSWLQ19Pkt1pcjw=; b=dVxs/l0aoW764YyaQj4Jmrc0fepo3iaWOxxTEwUoLG2uCRQBYAM2dOH7J5LMCnf0D5 nhpWT/Zsu2H8F0IDA42mle6JNcpEzq2s8OqlL7vzH/19zbZQ/8IKUrhbNlj+K8oGs4an Sy0GbuOcvKuR/pymlbc8LYg9hcYqGY7GerfbM4OaVZbgn9DHCYfmgqDHJ3n642TI17FA 73nvmpzBW/ueynEit9SaA3bLnKMcdXiI1UferN8919xkWAqy9hCxvbVBG2RgAVag886B zdkpu8Pkq8FZp+Oh7ulrchzstv9wNEUihri8ky6/7pk1CTDB4kRYu76/XsATqSJ6riYu iMXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=uhJDgmlSFpzzP221Tg8a7I3IOQ+ykSWLQ19Pkt1pcjw=; b=q82vnPMANbSr7dYUEJDYasU+i8T4y88tvu77xuirApr7Hh7Vq8NQoG4aK6ASBQNr0V ftepfyU0yJdRg5QuvrVy66sziaD9XZbT0ZwWBNLDew/p5HyGyAMYwfmG46nl/dTXTJTL +fBu4r+3rPA/11jKv63JaimPzCtvkXZDk97XGFuR7fqIsRxmLZRkHWDvlw3SNUvClHqD VjIm7tUN454g/ihQkrXm/Op770A7mfSb5ELVg8H3LzAY6khCZzR4mPjGQZsMjFl4P2lF NXI+DBtU/hQ6CwjSGQHoME2R/M0MlMzv5e2MrAQG22OLUYeQjDnMTMLJT4cpsPnQI30T yjFg== X-Gm-Message-State: ALQs6tBN0ujFwF2p24vv02qtCnOGTT2nND5SFxFtfyN5TV3nr5EV/7NO ESOTNBg1wE43QJRnWNvhXpJhIg== X-Google-Smtp-Source: AIpwx48Kzigrb5SRDNlPjJRXmrc/uCKbUgSlkikcucXYYYwpxvIZ4wZEyOG8ls1UiJDu9pkTAQL5MQ== X-Received: by 10.28.58.81 with SMTP id h78mr1542114wma.110.1523907072371; Mon, 16 Apr 2018 12:31:12 -0700 (PDT) Received: from [10.137.2.19] (ip-78-102-97-226.net.upcbroadband.cz. [78.102.97.226]) by smtp.gmail.com with ESMTPSA id 6sm10292550wmf.31.2018.04.16.12.31.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Apr 2018 12:31:11 -0700 (PDT) Subject: Re: Standby corruption after master is restarted To: emre@hasegeli.com Cc: PostgreSQL Bugs , gurkan.gur@innogames.com, david.pusch@innogames.com, patrick.schmidt@innogames.com References: From: Tomas Vondra Message-ID: <30d65a09-417a-530c-d70f-7b01ed66ebc1@2ndquadrant.com> Date: Mon, 16 Apr 2018 21:31:08 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 04/16/2018 04:55 PM, Emre Hasegeli wrote: >> OK, and on the standby? I suppose it breaks right after the >> CHECKPOINT_SHUTDOWN record, right? > > Actually pg_xlogdump fails right at the SHUTDOWN record: > >> rmgr: Heap2 len (rec/tot): 58/ 58, tx: 0, lsn: 1DFB/D6BDDEA0, prev 1DFB/D6BDDE60, desc: CLEAN remxid 0, blkref #0: rel 1663/16385/141744 blk 331538 >> rmgr: Heap2 len (rec/tot): 58/ 58, tx: 0, lsn: 1DFB/D6BDDEE0, prev 1DFB/D6BDDEA0, desc: CLEAN remxid 0, blkref #0: rel 1663/16385/141744 blk 331539 >> rmgr: Heap2 len (rec/tot): 110/ 110, tx: 0, lsn: 1DFB/D6BDDF20, prev 1DFB/D6BDDEE0, desc: CLEAN remxid 0, blkref #0: rel 1663/16385/141744 blk 331540 >> rmgr: Heap2 len (rec/tot): 100/ 100, tx: 0, lsn: 1DFB/D6BDDF90, prev 1DFB/D6BDDF20, desc: CLEAN remxid 0, blkref #0: rel 1663/16385/141744 blk 331541 >> pg_xlogdump: FATAL: error in WAL record at 1DFB/D6BDDF90: unexpected pageaddr 1DFB/66BDE000 in log segment 0000000000001DFB000000D6, offset 12443648 > >> Hmmm. I'm not sure what exactly debian upgrade script (and IIRC it >> depends on packages). I wonder if it does fast/smart/immediate. > > I couldn't find it quickly. > >> And can you determine how the broken WAL got to the standby? Was it by >> directly fetching from the primary, or from the barman archive? Is it >> broken in the archive too? > > It must be streamed from the primary. The log was on on the archive > during the incident. The good log file came there later. Such logs > are repeated on the standby before the error: > OK, so the standby connects to the primary, gets a (corrupted) WAL segment from it, which then gets archived? That would contradict the theory of race condition between recycling the WAL segment and copying it to the standby, because we never recycle segments that have not been archived yet (obviously). But I'm not sure that's the exact sequence of events, of course. Can you check if the "incorrect" part of the WAL segment matches some previous segment? Verifying that shouldn't be very difficult (just cut a bunch of bytes using hexdump, compare to the incorrect data). Assuming you still have the WAL archive, of course. That would tell us that the corrupted part comes from an old recycled segment. >> 2018-03-28 14:00:30 UTC [3693-67] LOG: invalid resource manager ID 39 at 1DFB/D43BE688 >> 2018-03-28 14:00:30 UTC [25347-1] LOG: started streaming WAL from primary at 1DFB/D4000000 on timeline 5 >> 2018-03-28 14:00:59 UTC [3748-357177] LOG: restartpoint starting: time >> WARNING: terminating connection because of crash of another server process >> DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared m > emory. >> HINT: In a moment you should be able to reconnect to the database and repeat your command. >> 2018-03-28 14:01:23 UTC [25347-2] FATAL: could not receive data from WAL stream: SSL SYSCALL error: EOF detected > Hmmm, I see you're using SSL. I don't think that could break affect anything, but maybe I should try mimicking this aspect too. >> I think one hypothesis is that the standby starts fetching a WAL segment >> from the primary, and while doing that it gets recycled and overwritten >> (so the standby gets bogus somewhere half-way through). That should not >> be possible, of course, but perhaps there's something broken right after >> a restart? A race condition or something like that? > > If I haven't missed anything on the hexdumps I posted, the logs of the > master and the standby are the same until the position on > pg_controldata. I cannot understand how it can fail for something > later. Is it possible that this is triggered if the replication is > interrupted on a certain point? > Which position? The controldata shows location of the last checkpoint, which says where the replay should start. Or am I missing something? regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services