Hi, While working on a feature patch that I’m going to post soon, I noticed a small issue in reorderbuffer.c. In the REORDER_BUFFER_CHANGE_TRUNCATE branch of ReorderBufferProcessTXN(), some opened relations might be skipped without being closed, leading to leaked relcache references.
The relevant code is:
```
relations = palloc0_array(Relation, nrelids);
for (i = 0; i < nrelids; i++)
{
Oid relid =
change->data.truncate.relids[i];
Relation rel;
rel = RelationIdGetRelation(relid);
if (!RelationIsValid(rel))
elog(ERROR, "could not open relation
with OID %u", relid);
if (!RelationIsLogicallyLogged(rel))
continue; <===== it should close rel
before skipping it
relations[nrelations++] = rel;
}
/* Apply the truncate. */
ReorderBufferApplyTruncate(rb, txn, nrelations,
relations, change,
streaming);
for (i = 0; i < nrelations; i++)
RelationClose(relations[i]);
```
In the loop, each relation that is appended to relations is closed after the
loop. However, when RelationIsLogicallyLogged(rel) returns false, the relation
is skipped without being closed, causing the leak.
The attached patch makes a small fix to close the relation before continuing.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
v1-0001-Fix-relcache-reference-leak-when-decoding-TRUNCAT.patch
Description: Binary data
