Re: Re: COPY FROM with RLS - Mailing list pgsql-hackers

From jian he
Subject Re: Re: COPY FROM with RLS
Date
Msg-id CACJufxHU3tetCM+Qymxpj7-OLP8b6x3HJAnARadSrEAt64MHkg@mail.gmail.com
Whole thread
List pgsql-hackers
On Tue, Jun 30, 2026 at 9:20 AM Yilin Zhang <jiezhilove@126.com> wrote:
>
> Hi, I found another issue with the v2 patch.
> When running COPY FROM against a partitioned table with RLS enabled, ExecSetupPartitionTupleRouting gets invoked
twice,
> which creates two separate sets of PartitionTupleRouting structures.
> One of these sets never gets cleaned up, and PostgreSQL’s ResourceOwner mechanism catches this and emits the
followingwarnings: 
>
>   WARNING:  resource was not closed: relation "rls_part_1"
>   WARNING:  resource was not closed: relation "rls_part_2"
>
> Best regards,
> --
> Yilin Zhang
>

Hi.
While v2 has extensive failure test cases, it doesn't have a single
successful test case,
that's why this issue wasn't found.
The 2 issues you reported are fixed in the attached v3.

Also, previously in v2:
+COPY r1 FROM STDIN WITH (DELIMITER ','); -- fail
+ERROR:  new row violates row-level security policy "p2" for table "r1"
+CONTEXT:  COPY r1, line 1: "4"

it's better to remove the CONTEXT line.
because ExecWithCheckOptions has comments like:
/*
 * For WITH CHECK OPTIONs coming from views, we might be
 * able to provide the details on the row, depending on
 * the permissions on the relation (that is, if the user
 * could view it directly anyway).  For RLS violations, we
 * don't include the data since we don't know if the user
 * should be able to view the tuple as that depends on the
 * USING policy.
 */



--
jian
https://www.enterprisedb.com/

Attachment

pgsql-hackers by date:

Previous
From: Laurenz Albe
Date:
Subject: Re: equalPolicy() doesn't compare the permissive flag
Next
From: Rui Zhao
Date:
Subject: Re: allow spread checkpoints when changing checksums online