Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lpIuG-0005kr-9g for pgsql-hackers@arkaria.postgresql.org; Fri, 04 Jun 2021 23:07:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lpIuE-0000hB-Hf for pgsql-hackers@arkaria.postgresql.org; Fri, 04 Jun 2021 23:07:10 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lpIuE-0000gz-7H for pgsql-hackers@lists.postgresql.org; Fri, 04 Jun 2021 23:07:10 +0000 Received: from smtp-fw-80006.amazon.com ([99.78.197.217]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lpIuB-0003kR-IM for pgsql-hackers@postgresql.org; Fri, 04 Jun 2021 23:07:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1622848027; x=1654384027; h=subject:from:to:cc:references:message-id:date: mime-version:in-reply-to; bh=wF7giTMyMl19XVAmGyfYhP72u4EPGMQ7Onduyilq0iY=; b=CpLm6j2V7N7XyZEj4+ktF2a67HupwCfa/ikpRJQ1Ie4YIj/DOTvk77tE iUytvBYnz2hm3Z1UoPKyok/xH2ejpxNsHmeCVhTSlEZbZ5UdCGPAo++d5 mThEmMgMQQQNnK2PeDzfmKMczbPyll7H6ojry8YLsN4xHuDXYu3y7efyg 8=; X-IronPort-AV: E=Sophos;i="5.83,249,1616457600"; d="scan'208,217";a="5045488" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO email-inbound-relay-2c-456ef9c9.us-west-2.amazon.com) ([10.25.36.214]) by smtp-border-fw-80006.pdx80.corp.amazon.com with ESMTP; 04 Jun 2021 23:07:04 +0000 Received: from EX13MTAUWB001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan3.pdx.amazon.com [10.236.137.198]) by email-inbound-relay-2c-456ef9c9.us-west-2.amazon.com (Postfix) with ESMTPS id 54AFFC21E4; Fri, 4 Jun 2021 23:07:04 +0000 (UTC) Received: from EX13D18UWA002.ant.amazon.com (10.43.160.199) by EX13MTAUWB001.ant.amazon.com (10.43.161.207) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Fri, 4 Jun 2021 23:07:03 +0000 Received: from 186590ce269b.ant.amazon.com (10.43.160.41) by EX13D18UWA002.ant.amazon.com (10.43.160.199) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Fri, 4 Jun 2021 23:07:03 +0000 Subject: Re: logical decoding bug: segfault in ReorderBufferToastReplace() From: Jeremy Schneider To: Andres Freund , "Drouvot, Bertrand" CC: Tomas Vondra , PostgreSQL-development References: <20191205133836.lulisfo2fphdrjp3@development> <20191211163522.t2ljtydarlmusoix@alap3.anarazel.de> <81182626-e836-061f-8f19-204edac18922@amazon.com> Message-ID: Date: Fri, 4 Jun 2021 16:07:02 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:78.0) Gecko/20100101 Thunderbird/78.10.2 MIME-Version: 1.0 In-Reply-To: <81182626-e836-061f-8f19-204edac18922@amazon.com> Content-Type: multipart/alternative; boundary="------------D44CE0FB5DCABF2F4EA8BB57" Content-Language: en-US X-Originating-IP: [10.43.160.41] X-ClientProxiedBy: EX13D44UWC002.ant.amazon.com (10.43.162.169) To EX13D18UWA002.ant.amazon.com (10.43.160.199) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --------------D44CE0FB5DCABF2F4EA8BB57 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit On 12/13/19 16:13, Jeremy Schneider wrote: > On 12/11/19 08:35, Andres Freund wrote: >> Seems like we clearly should add an elog(ERROR) here, so we error out, >> rather than crash. > done - in the commit that I replied to when I started this thread :) > > https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=69f883fef14a3fc5849126799278abcc43f40f56 Another PostgreSQL user ran into this issue. This time on version 12.5 - so instead of a crash they got the error message from the commit. ERROR: XX000: could not open relation with OID 0 LOCATION: ReorderBufferToastReplace, reorderbuffer.c:305 Upon seeing this error message, I realized that the base relation OID would be very useful when the toast relation OID is "0". Would this patch work to show that? diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 2d9e1279bb..b90603b051 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -4598,8 +4598,8 @@ ReorderBufferToastReplace(ReorderBuffer *rb, ReorderBufferTXN *txn,         toast_rel = RelationIdGetRelation(relation->rd_rel->reltoastrelid);         if (!RelationIsValid(toast_rel)) -               elog(ERROR, "could not open relation with OID %u", -                        relation->rd_rel->reltoastrelid); +               elog(ERROR, "could not open toast relation with OID %u (base relation with OID %u)", +                        relation->rd_rel->reltoastrelid, relation->rd_rel->oid);         toast_desc = RelationGetDescr(toast_rel); Thoughts? -Jeremy -- Jeremy Schneider Database Engineer Amazon Web Services --------------D44CE0FB5DCABF2F4EA8BB57 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: 8bit
On 12/13/19 16:13, Jeremy Schneider wrote:
On 12/11/19 08:35, Andres Freund wrote:
Seems like we clearly should add an elog(ERROR) here, so we error out,
rather than crash.
done - in the commit that I replied to when I started this thread :)

https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=69f883fef14a3fc5849126799278abcc43f40f56


Another PostgreSQL user ran into this issue. This time on version 12.5 - so instead of a crash they got the error message from the commit.

ERROR: XX000: could not open relation with OID 0
LOCATION: ReorderBufferToastReplace, reorderbuffer.c:305

Upon seeing this error message, I realized that the base relation OID would be very useful when the toast relation OID is "0".

Would this patch work to show that?

diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index 2d9e1279bb..b90603b051 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -4598,8 +4598,8 @@ ReorderBufferToastReplace(ReorderBuffer *rb, ReorderBufferTXN *txn,

        toast_rel = RelationIdGetRelation(relation->rd_rel->reltoastrelid);
        if (!RelationIsValid(toast_rel))
-               elog(ERROR, "could not open relation with OID %u",
-                        relation->rd_rel->reltoastrelid);
+               elog(ERROR, "could not open toast relation with OID %u (base relation with OID %u)",
+                        relation->rd_rel->reltoastrelid, relation->rd_rel->oid);

        toast_desc = RelationGetDescr(toast_rel);

Thoughts?

-Jeremy

-- 
Jeremy Schneider
Database Engineer
Amazon Web Services
--------------D44CE0FB5DCABF2F4EA8BB57--