Diagnostic Queries
Symptoms
An UPDATE produced a row that does not satisfy the policy’s USING expression (the visibility condition) for the table. With RLS enabled, PostgreSQL blocks it with SQLSTATE 42501 (insufficient_privilege).
- The resulting row would not be visible under the USING expression.
- Specific to policies that use USING for write checks.
- Common when an UPDATE moves a row out of the user’s scope.
What the server log shows
ERROR: new row violates row-level security policy (USING expression) for table "documents"
Why PostgreSQL raises this — what the manual says
Section 5.9 Row Security Policies:
“A policy can be specified to apply to ALL commands, or to SELECT, INSERT, UPDATE, or DELETE.”
When a policy has no separate WITH CHECK, its USING expression also validates new/updated rows. If the resulting row fails that expression, the write is disallowed and PostgreSQL reports 42501.
Common causes
- An UPDATE changing a row so it no longer matches the USING expression.
- A policy relying on USING for both read and write checks.
- Session context the policy depends on being unset/incorrect.
How to fix it
- Keep the updated row within the bounds the USING expression allows.
- Add an explicit
WITH CHECKpolicy if write rules should differ from read rules. - Verify the session settings the policy references.
Related & next steps
Reference: PostgreSQL 18 Section 5.9 “Row Security Policies”.
Thanks — noted. This helps keep the database accurate.