Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hJDbb-0001iS-7U for pgsql-bugs@arkaria.postgresql.org; Wed, 24 Apr 2019 08:50:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hJDbX-0000Aa-7v for pgsql-bugs@arkaria.postgresql.org; Wed, 24 Apr 2019 08:50:11 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hJDbW-0000AS-Rp for pgsql-bugs@lists.postgresql.org; Wed, 24 Apr 2019 08:50:11 +0000 Received: from cyclops.postgrespro.ru ([93.174.131.138] helo=mail.postgrespro.ru) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hJDbS-0006p5-Jn for pgsql-bugs@lists.postgresql.org; Wed, 24 Apr 2019 08:50:09 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 2671E21C3ECE for ; Wed, 24 Apr 2019 11:50:04 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=x tagged_above=-99 required=4 WHITELISTED tests=[] autolearn=unavailable Received: from [192.168.3.134] (broadband-95-84-150-205.ip.moscow.rt.ru [95.84.150.205]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 588D221C3E9B for ; Wed, 24 Apr 2019 11:50:03 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1556095803; bh=mntaGwDsNRCjyQvDzUr+55YyCua2PqCYY9vFEZw9f40=; h=Subject:To:References:From:Date:In-Reply-To; b=mAzU/Fk7RjQ1nDLII+BbIVd1x3L1vVI3Fo40f6ixx1jbTLltnSwJdje4uC8st8Ffu pQXGYM6O0O64A1IUax8vXBOvgQAV0+233BVDOZTQgyyZnSkfrpxGGdoCg7C0LLIXSO MW9MVfFkwWpPraYeSRa9GEd8SnmYiYr1IaYr0LB4= Subject: Re: amcheck assert failure To: pgsql-bugs@lists.postgresql.org References: <906cac0a-1201-e981-5043-7ca0d97d2a17@postgrespro.ru> <61090467-0a38-d58b-dfcc-81463e66708c@postgrespro.ru> <23979.1555962717@sss.pgh.pa.us> From: Grigory Smolkin Message-ID: <39998e3e-816b-f9ed-2a69-6ac7f05dea4a@postgrespro.ru> Date: Wed, 24 Apr 2019 11:50:02 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 04/22/2019 11:31 PM, Peter Geoghegan wrote: > On Mon, Apr 22, 2019 at 12:51 PM Tom Lane wrote: >> Nonetheless ... do we really want an assertion failure rather than >> some more-mundane error report? Seems like the point of amcheck >> is to detect data corruption, so I'd rather get an ERROR than an >> assertion (which would not fire in production builds anyway). > (Apologies for sending this a second time, Tom -- somehow failed to CC > the list the first time) > > I think that the size cross-check must have failed to catch the problem: > > /* > * lp_len should match the IndexTuple reported length exactly, since > * lp_len is completely redundant in indexes, and both sources of > * tuple length are MAXALIGN()'d. nbtree does not use lp_len all that > * frequently, and is surprisingly tolerant of corrupt lp_len fields. > */ > if (tupsize != ItemIdGetLength(itemid)) > ereport(ERROR, > (errcode(ERRCODE_INDEX_CORRUPTED), > errmsg("index tuple size does not equal lp_len in > index \"%s\"", > RelationGetRelationName(state->rel)), > errdetail_internal("Index tid=(%u,%u) tuple > size=%zu lp_len=%u page lsn=%X/%X.", > state->targetblock, offset, > tupsize, ItemIdGetLength(itemid), > (uint32) (state->targetlsn >> 32), > (uint32) state->targetlsn), > errhint("This could be a torn page problem."))); > > It seems like the length from tupsize (IndexTupleSize()) happened to > match the redundant ItemIdGetLength()-reported size from the line > pointer. No idea how that could actually be possible, since the value > returned by ItemIdGetLength() would be 12592. What are the chances of > that accidentally matching what the wild itup pointer reported as its > IndexTupleSize()? > > The only explanation I can think of is that the assertion failure was > from the core code -- _bt_check_natts() is itself called within core > code assertions, so it's just about possible that that was how this > happened, before amcheck was even called. Doesn't seem like a very > good explanation. Do you think that that's possible, Grigory? No, it was definitely amcheck: https://pastebin.postgrespro.ru/?2c8ddf5254b2c625#PTbr+jbxFPu2wfy5SFDWdiqaqPN/N5WX8t6mo5rDpmo= > > In any case, you're clearly right that amcheck could be more defensive > here. My pg_hexedit tool detected that there was an LP_UNUSED item > pointer with storage (i.e. whose lp_len > 0), which is a check that > amcheck can and should perform, but doesn't. Especially because it > would prevent a deference of a likely-wild pointer (IndexTuple). > > We could: > > * Throw an error when any line item reports lp_len == 0. > > * Throw an error when there is a line item that's either LP_UNUSED, or > LP_REDIRECT. The corrupt page sent by Grigory had both. > > What do you think of the idea of committing some simple checks to do > this with contrib/amcheck on v12? > -- Grigory Smolkin Postgres Professional: http://www.postgrespro.com The Russian Postgres Company