relation OID in ReorderBufferToastReplace error message

Jeremy Schneider <schnjere@amazon.com>

From: Jeremy Schneider <schnjere@amazon.com>
To: PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2021-07-02T01:25:58Z
Lists: pgsql-hackers
I've recently been working with a PostgreSQL database where we saw
ReorderBufferToastReplace() fail due to a reltoastrelid value of 0.  In
the original thread, Amit pointed out a connection to the speculative
insert decoding memory leak bug.  Bertrand built a test case confirming
that a speculative abort record followed by an insert on another table
would in fact produce the error message from ReorderBufferToastReplace()
that we had seen, and accordingly we're pretty sure that was the root
cause in this particular database.

https://www.postgresql.org/message-id/5f9a118e-86c5-d4f1-b584-199a33757cd4%40amazon.com

Nonetheless, in the process of troubleshooting it occurred to me that
this error message would be more useful in general if it included the
base relation OID in the error message. Amit suggested a separate thread
- so here we are.  :)

https://www.postgresql.org/message-id/CAA4eK1%2BdeBBnMVPxfLuv1Aa7tuh-7e3FvnSvWTaCy4-_HPcBLg%40mail.gmail.com

Anyone have thoughts?  Would I need a commitfest entry to propose a
two-line tweak like this?

-Jeremy



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);


-- 
Jeremy Schneider
Database Engineer
Amazon Web Services

Commits

  1. Back-patch "Add parent table name in an error in reorderbuffer.c."

  2. Add parent table name in an error in reorderbuffer.c.

  3. Fix reorder buffer memory accounting for toast changes.

  4. Add logical change details to logical replication worker errcontext.

  5. Fix toast rewrites in logical decoding.

  6. Add error codes to some corruption log messages