| From: | Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com> | 
|---|---|
| To: | Pg Hackers <pgsql-hackers(at)postgresql(dot)org> | 
| Subject: | Relcache leak when row triggers on partitions are fired by COPY | 
| Date: | 2017-05-16 00:12:10 | 
| Message-ID: | CAEepm=15Jss-yhFApuKzxcoCuFnb8TR8iQiWMjG=CLYPx48QLw@mail.gmail.com | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-hackers | 
Hi hackers,
While testing the patch I'm writing for the transition table open
item, I noticed that we can leak Relation objects like this:
postgres=# create table parent (a text, b int) partition by list (a);
CREATE TABLE
postgres=# create table child partition of parent for values in ('AAA');
CREATE TABLE
postgres=# create or replace function my_trigger_func() returns
trigger language plpgsql as $$ begin raise notice 'hello'; return
null; end; $$;
CREATE FUNCTION
postgres=# create trigger child_trigger after insert or update or
delete on child for each row execute procedure my_trigger_func();
CREATE TRIGGER
postgres=# copy parent (a, b) from stdin;
Enter data to be copied followed by a newline.
End with a backslash and a period on a line by itself.
>> AAA 42
>> \.
NOTICE:  hello
WARNING:  relcache reference leak: relation "child" not closed
COPY 1
The leaked object is created by ExecGetTriggerResultRel, called by
afterTriggerInvokeEvents.  That function relies on someone, usually
ExecEndPlan or EvalPlanQualEnd, to clean up es_trig_target_relations.
Shouldn't copy.c do the same thing (see attached)?  Or perhaps there
should there be an ExecCleanupTriggerState(estate) used by all places?
-- 
Thomas Munro
http://www.enterprisedb.com
| Attachment | Content-Type | Size | 
|---|---|---|
| fix-relcache-leak-in-copy-with-triggers.patch | application/octet-stream | 854 bytes | 
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Amit Langote | 2017-05-16 00:32:49 | Re: Relcache leak when row triggers on partitions are fired by COPY | 
| Previous Message | Tom Lane | 2017-05-15 23:57:21 | Re: Receive buffer size for the statistics socket |