Re: BUG #19026: ResourceOwnerForget can't find owner for invalid plancache

From: Dilip Kumar <dilipbalaut(at)gmail(dot)com>
To: exclusion(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #19026: ResourceOwnerForget can't find owner for invalid plancache
Date: 2025-08-20 11:21:07
Message-ID: CAFiTN-st+8+OQExTgLB1FUi_i+NSBz9aUeuzAcRzx6nQZDHUwg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Wed, Aug 20, 2025 at 4:01 PM PG Bug reporting form
<noreply(at)postgresql(dot)org> wrote:
>
> The following bug has been logged on the website:
>
> Bug reference: 19026
> Logged by: Alexander Lakhin
> Email address: exclusion(at)gmail(dot)com
> PostgreSQL version: 18beta3
> Operating system: Ubuntu 24.04
> Description:
>
> The following script:
> create function part_hashint4_noop(value int4, seed int8)
> returns int8 as $$
> create table t();
> select value + seed;
> $$ language sql strict immutable parallel safe;
>
> create operator class part_test_int4_ops for type int4 using hash as
> function 2 part_hashint4_noop(int4, int8);
>
> create table pt(i int) partition by hash (i part_test_int4_ops);
> create table p1 partition of pt for values with (modulus 4, remainder 0);
>
> insert into pt values (1);
> insert into pt values (1);
>
> triggers an expected error and then an internal one:
> ERROR: CREATE TABLE is not allowed in a non-volatile function
> CONTEXT: SQL function "part_hashint4_noop" statement 1
>
> ERROR: XX000: plancache reference 0x643ae41a7d98 is not owned by resource
> owner Portal
> CONTEXT: SQL function "part_hashint4_noop" during startup
> LOCATION: ResourceOwnerForget, resowner.c:618

The problem is in init_execution_state() we store the

On error resource owner will be released, but that references are
still maintained in the plan and cowner in fcache, but on error the
transaction will be aborted and this resource owner will be released.
So next time when we try to clean up, it will access invalid memory.
So a simple fix would be to cleanup on error as attached POC.

--
Regards,
Dilip Kumar
Google

Attachment Content-Type Size
release_plan_on_error.patch application/octet-stream 1.5 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Kirill Reshke 2025-08-20 11:43:32 Re: BUG #19026: ResourceOwnerForget can't find owner for invalid plancache
Previous Message hubert depesz lubaczewski 2025-08-20 11:19:25 Re: BUG #19025: PostgreSQL log is not rotated