diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 7378beb684..27332a4cfd 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -4610,6 +4610,11 @@ ReorderBufferToastReplace(ReorderBuffer *rb, ReorderBufferTXN *txn, if (txn->toast_hash == NULL) return; + toast_rel = RelationIdGetRelation(relation->rd_rel->reltoastrelid); + if (!RelationIsValid(toast_rel)) + elog(ERROR, "could not open relation with OID %u", + relation->rd_rel->reltoastrelid); + /* * We're going to modify the size of the change, so to make sure the * accounting is correct we'll make it look like we're removing the change @@ -4624,11 +4629,6 @@ ReorderBufferToastReplace(ReorderBuffer *rb, ReorderBufferTXN *txn, desc = RelationGetDescr(relation); - toast_rel = RelationIdGetRelation(relation->rd_rel->reltoastrelid); - if (!RelationIsValid(toast_rel)) - elog(ERROR, "could not open relation with OID %u", - relation->rd_rel->reltoastrelid); - toast_desc = RelationGetDescr(toast_rel); /* should we allocate from stack instead? */