RE: Table refer leak in logical replication

From: "houzj(dot)fnst(at)fujitsu(dot)com" <houzj(dot)fnst(at)fujitsu(dot)com>
To: "tanghy(dot)fnst(at)fujitsu(dot)com" <tanghy(dot)fnst(at)fujitsu(dot)com>
Cc: "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: RE: Table refer leak in logical replication
Date: 2021-04-06 01:15:33
Message-ID: OS0PR01MB571686F75FBDC219FF3DFF0D94769@OS0PR01MB5716.jpnprd01.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> WARNING: relcache reference leak: relation "xxx" not closed.
>
> Example of the procedure:
> ------publisher------
> create table test (a int primary key);
> create publication pub for table test;
>
> ------subscriber------
> create table test (a int primary key);
> create subscription sub connection 'dbname=postgres' publication pub;
> create function funcA() returns trigger as $$ begin return null; end; $$ language
> plpgsql; create trigger my_trig after insert or update or delete on test for each
> row execute procedure funcA(); alter table test enable replica trigger my_trig;
>
> ------publisher------
> insert into test values (6);
>
> It seems an issue about reference leak. Anyone can fix this?

It seems ExecGetTriggerResultRel will reopen the target table because it cannot find an existing one.
Storing the opened table in estate->es_opened_result_relations seems solves the problem.

Attaching a patch that fix this.
BTW, it seems better to add a testcase for this ?

Best regards,
houzj

Attachment Content-Type Size
fix_table_refer_leak.diff application/octet-stream 1.3 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message shiy.fnst@fujitsu.com 2021-04-06 01:49:15 RE: Table refer leak in logical replication
Previous Message tanghy.fnst@fujitsu.com 2021-04-06 01:04:51 Table refer leak in logical replication