{"schema": "pgtrue.report/1", "url": "https://pgtrue.postgres.ai/shared/brief/c8b29788-6fe2-48e5-8db9-35fe26e475eb", "published": "2026-10-19T07:59:09Z", "publisher": "PostgresAI", "article": {"title": "new row violates row-level security policy: the causes", "url": "https://now-next.nl/en/insights/postgresql-new-row-violates-row-level-security-policy", "date_published": "2026-10-10T00:00:00Z", "author": "Chris van Eijk", "publisher": "Now-Next"}, "grade": "A-", "axes": [{"axis": "Factual", "summary": "B+ \u00b7 1 wrong of 17 checked \u00b7 0 caveats"}, {"axis": "Applicable", "summary": "B+ \u00b7 1 wrong of 8 checked \u00b7 0 caveats"}, {"axis": "Consistent", "summary": "A \u00b7 0 wrong of 17 checked \u00b7 0 caveats"}, {"axis": "Transparent", "summary": "A \u00b7 0 wrong of 6 checked \u00b7 0 caveats"}, {"axis": "Safe", "summary": "not applicable"}], "findings": [{"anchor": "F17", "url": "https://pgtrue.postgres.ai/shared/brief/c8b29788-6fe2-48e5-8db9-35fe26e475eb#F17", "claim": "\u2026three of them that it is not its own\u2026", "title": "Plain INSERT does not disclose which tenant owns the duplicate slug", "explanation": "Plain INSERT gives the same duplicate-key error for an existing own slug. PostgreSQL 17 documents uniqueness checks outside row policies. The error establishes existence, not ownership. The claimed 3 distinguishing statements must exclude plain INSERT too.", "verdict": "False", "sources": [{"url": "https://github.com/postgres/postgres/blob/083ac033419f690758508e08c1736089384bbee8/doc/src/sgml/ddl.sgml#L2832-L2836", "label": "REL_17_11 \u00b7 doc/src/sgml/ddl.sgml:2832-2836"}, {"url": "https://github.com/postgres/postgres/blob/083ac033419f690758508e08c1736089384bbee8/src/backend/access/nbtree/nbtinsert.c#L667-L669", "label": "REL_17_11 \u00b7 src/backend/access/nbtree/nbtinsert.c:667-669"}, {"url": "https://www.postgresql.org/docs/17/sql-createpolicy.html", "label": "https://www.postgresql.org/docs/17/sql-createpolicy.html"}]}, {"anchor": "F1", "url": "https://pgtrue.postgres.ai/shared/brief/c8b29788-6fe2-48e5-8db9-35fe26e475eb#F1", "claim": "A duplicate-key error on the plain INSERT counts as No.", "title": "The duplicate-key branch can misdiagnose a missing SELECT policy", "explanation": "A duplicate-key error does not exclude a missing SELECT policy. Setup C permits plain INSERT but rejects the explicit-target upsert's SELECT check. ExecInsert checks policies before constraints at nodeModifyTable.c:1018. An existing key then sends the tree toward the wrong cause.", "verdict": "Misleading", "sources": [{"url": "https://github.com/postgres/postgres/blob/083ac033419f690758508e08c1736089384bbee8/src/backend/executor/nodeModifyTable.c#L1018-L1025", "label": "REL_17_11 \u00b7 src/backend/executor/nodeModifyTable.c:1018-1025"}, {"url": "https://github.com/postgres/postgres/blob/083ac033419f690758508e08c1736089384bbee8/src/backend/rewrite/rowsecurity.c#L278-L283", "label": "REL_17_11 \u00b7 src/backend/rewrite/rowsecurity.c:278-283"}, {"url": "https://github.com/postgres/postgres/blob/083ac033419f690758508e08c1736089384bbee8/doc/src/sgml/ref/create_policy.sgml#L296-L303", "label": "REL_17_11 \u00b7 doc/src/sgml/ref/create_policy.sgml:296-303"}, {"url": "https://github.com/postgres/postgres/blob/083ac033419f690758508e08c1736089384bbee8/doc/src/sgml/ddl.sgml#L2832-L2836", "label": "REL_17_11 \u00b7 doc/src/sgml/ddl.sgml:2832-2836"}]}, {"anchor": "F3", "url": "https://pgtrue.postgres.ai/shared/brief/c8b29788-6fe2-48e5-8db9-35fe26e475eb#F3", "claim": "\u2026a row that no permissive policy lets through\u2026", "title": "Permissive failures omit names and restrictive failures can name policies", "explanation": "rowsecurity.c:839 combines permissive checks without a policy name. It adds named restrictive checks afterward at line 863. execMain.c:2199 reports SQLSTATE 42501 for a failed unnamed new-row check.", "verdict": "Accurate", "sources": [{"url": "https://github.com/postgres/postgres/blob/083ac033419f690758508e08c1736089384bbee8/src/backend/rewrite/rowsecurity.c#L839-L843", "label": "REL_17_11 \u00b7 src/backend/rewrite/rowsecurity.c:839-843"}, {"url": "https://github.com/postgres/postgres/blob/083ac033419f690758508e08c1736089384bbee8/src/backend/rewrite/rowsecurity.c#L863-L866", "label": "REL_17_11 \u00b7 src/backend/rewrite/rowsecurity.c:863-866"}, {"url": "https://github.com/postgres/postgres/blob/083ac033419f690758508e08c1736089384bbee8/src/backend/utils/errcodes.txt#L335-L335", "label": "REL_17_11 \u00b7 src/backend/utils/errcodes.txt:335-335"}, {"url": "https://github.com/postgres/postgres/blob/083ac033419f690758508e08c1736089384bbee8/src/backend/executor/execMain.c#L2199-L2202", "label": "REL_17_11 \u00b7 src/backend/executor/execMain.c:2199-2202"}]}, {"anchor": "F4", "url": "https://pgtrue.postgres.ai/shared/brief/c8b29788-6fe2-48e5-8db9-35fe26e475eb#F4", "claim": "\u2026the insert policy is checked before PostgreSQL knows whether there is a conflict\u2026", "title": "INSERT policies run before conflict detection", "explanation": "nodeModifyTable.c:1018 checks the proposed row's policies. Its conflict-index check follows at line 1064. ON CONFLICT DO NOTHING and DO UPDATE cannot bypass an INSERT-policy failure.", "verdict": "Accurate", "sources": [{"url": "https://github.com/postgres/postgres/blob/083ac033419f690758508e08c1736089384bbee8/src/backend/executor/nodeModifyTable.c#L1018-L1025", "label": "REL_17_11 \u00b7 src/backend/executor/nodeModifyTable.c:1018-1025"}, {"url": "https://github.com/postgres/postgres/blob/083ac033419f690758508e08c1736089384bbee8/src/backend/executor/nodeModifyTable.c#L1063-L1065", "label": "REL_17_11 \u00b7 src/backend/executor/nodeModifyTable.c:1063-1065"}]}, {"anchor": "F5", "url": "https://pgtrue.postgres.ai/shared/brief/c8b29788-6fe2-48e5-8db9-35fe26e475eb#F5", "claim": "\u2026RETURNING and ON CONFLICT with a conflict target apply those to the new row too\u2026", "title": "The shown RETURNING and conflict-target writes require SELECT policies", "explanation": "rowsecurity.c:278 adds SELECT policies as new-row checks when SELECT rights are required. create_policy.sgml:296 confirms explicit-target conflict handling. Column-reading WHERE clauses also apply SELECT filters to existing rows at rowsecurity.c:230.", "verdict": "Accurate", "sources": [{"url": "https://github.com/postgres/postgres/blob/083ac033419f690758508e08c1736089384bbee8/src/backend/rewrite/rowsecurity.c#L278-L283", "label": "REL_17_11 \u00b7 src/backend/rewrite/rowsecurity.c:278-283"}, {"url": "https://github.com/postgres/postgres/blob/083ac033419f690758508e08c1736089384bbee8/doc/src/sgml/ref/create_policy.sgml#L296-L303", "label": "REL_17_11 \u00b7 doc/src/sgml/ref/create_policy.sgml:296-303"}, {"url": "https://github.com/postgres/postgres/blob/083ac033419f690758508e08c1736089384bbee8/src/backend/rewrite/rowsecurity.c#L230-L238", "label": "REL_17_11 \u00b7 src/backend/rewrite/rowsecurity.c:230-238"}]}, {"anchor": "F6", "url": "https://pgtrue.postgres.ai/shared/brief/c8b29788-6fe2-48e5-8db9-35fe26e475eb#F6", "claim": "\u2026No separate policy exists for MERGE.", "title": "MERGE applies policies for the action it executes", "explanation": "create_policy.sgml:743 defines no separate MERGE policy. nodeModifyTable.c:2992 checks action policies after WHEN conditions. SELECT filters can hide an existing target row before matching, so an INSERT action can encounter its unique key.", "verdict": "Accurate", "sources": [{"url": "https://github.com/postgres/postgres/blob/083ac033419f690758508e08c1736089384bbee8/doc/src/sgml/ref/create_policy.sgml#L743-L747", "label": "REL_17_11 \u00b7 doc/src/sgml/ref/create_policy.sgml:743-747"}, {"url": "https://github.com/postgres/postgres/blob/083ac033419f690758508e08c1736089384bbee8/src/backend/executor/nodeModifyTable.c#L2992-L3001", "label": "REL_17_11 \u00b7 src/backend/executor/nodeModifyTable.c:2992-3001"}, {"url": "https://github.com/postgres/postgres/blob/083ac033419f690758508e08c1736089384bbee8/src/backend/rewrite/rowsecurity.c#L230-L238", "label": "REL_17_11 \u00b7 src/backend/rewrite/rowsecurity.c:230-238"}, {"url": "https://www.postgresql.org/docs/17/sql-createpolicy.html", "label": "https://www.postgresql.org/docs/17/sql-createpolicy.html"}]}, {"anchor": "F7", "url": "https://pgtrue.postgres.ai/shared/brief/c8b29788-6fe2-48e5-8db9-35fe26e475eb#F7", "claim": "\u2026WITH CHECK is enforced after BEFORE triggers\u2026", "title": "BEFORE triggers precede policy and NOT NULL checks", "explanation": "nodeModifyTable.c:840 runs BEFORE INSERT triggers before policy checks at line 1018. Constraint checks follow at line 1024. The modified tenant value can change policy acceptance. A policy rejection can precede the column's NOT NULL error.", "verdict": "Accurate", "sources": [{"url": "https://github.com/postgres/postgres/blob/083ac033419f690758508e08c1736089384bbee8/src/backend/executor/nodeModifyTable.c#L1018-L1025", "label": "REL_17_11 \u00b7 src/backend/executor/nodeModifyTable.c:1018-1025"}, {"url": "https://github.com/postgres/postgres/blob/083ac033419f690758508e08c1736089384bbee8/doc/src/sgml/ref/create_policy.sgml#L62-L67", "label": "REL_17_11 \u00b7 doc/src/sgml/ref/create_policy.sgml:62-67"}, {"url": "https://github.com/postgres/postgres/blob/083ac033419f690758508e08c1736089384bbee8/src/backend/executor/nodeModifyTable.c#L840-L841", "label": "REL_17_11 \u00b7 src/backend/executor/nodeModifyTable.c:840-841"}, {"url": "https://www.postgresql.org/docs/17/sql-createpolicy.html", "label": "https://www.postgresql.org/docs/17/sql-createpolicy.html"}]}, {"anchor": "F8", "url": "https://pgtrue.postgres.ai/shared/brief/c8b29788-6fe2-48e5-8db9-35fe26e475eb#F8", "claim": "\u2026Check pg_policies for the command and the role, then the row's tenant_id\u2026", "explanation": "system_views.sql:95\u2013103 exposes cmd, qual, and with_check. It maps command codes to SELECT, INSERT, UPDATE, DELETE, and ALL. rowsecurity.c:921\u2013928 accepts PUBLIC and checks inherited role privileges.", "verdict": "Accurate", "sources": [{"url": "https://github.com/postgres/postgres/blob/083ac033419f690758508e08c1736089384bbee8/src/backend/catalog/system_views.sql#L95-L103", "label": "REL_17_11 \u00b7 src/backend/catalog/system_views.sql:95-103"}, {"url": "https://github.com/postgres/postgres/blob/083ac033419f690758508e08c1736089384bbee8/doc/src/sgml/system-views.sgml#L1811-L1813", "label": "REL_17_11 \u00b7 doc/src/sgml/system-views.sgml:1811-1813"}, {"url": "https://github.com/postgres/postgres/blob/083ac033419f690758508e08c1736089384bbee8/src/backend/rewrite/rowsecurity.c#L921-L928", "label": "REL_17_11 \u00b7 src/backend/rewrite/rowsecurity.c:921-928"}]}, {"anchor": "F9", "url": "https://pgtrue.postgres.ai/shared/brief/c8b29788-6fe2-48e5-8db9-35fe26e475eb#F9", "claim": "A bulk import under row-level security is INSERT statements, or a role that bypasses the policy.", "explanation": "copy.c:228\u2013232 contains the COPY FROM rejection for row-level security. The error recommends INSERT statements. This range does not establish which roles avoid that rejection.", "verdict": "Accurate", "sources": [{"url": "https://github.com/postgres/postgres/blob/083ac033419f690758508e08c1736089384bbee8/src/backend/commands/copy.c#L228-L232", "label": "REL_17_11 \u00b7 src/backend/commands/copy.c:228-232"}]}, {"anchor": "F10", "url": "https://pgtrue.postgres.ai/shared/brief/c8b29788-6fe2-48e5-8db9-35fe26e475eb#F10", "claim": "If your application connects as the owner, the absence of this error is the problem.", "title": "Ordinary table owners bypass RLS unless FORCE applies", "explanation": "rls.c:91 documents the ordinary owner exemption and FORCE exception. Under the article's setup, connecting as the owner can admit a row that app would fail.", "verdict": "Accurate", "sources": [{"url": "https://github.com/postgres/postgres/blob/083ac033419f690758508e08c1736089384bbee8/src/backend/utils/misc/rls.c#L91-L93", "label": "REL_17_11 \u00b7 src/backend/utils/misc/rls.c:91-93"}]}, {"anchor": "F11", "url": "https://pgtrue.postgres.ai/shared/brief/c8b29788-6fe2-48e5-8db9-35fe26e475eb#F11", "claim": "An empty or missing setting makes the comparison NULL\u2026", "title": "Missing and empty tenant settings produce a NULL comparison", "explanation": "guc_funcs.c:834 returns NULL for an absent setting with missing_ok. NULLIF converts an empty setting to NULL. func.sgml:645 confirms that ordinary comparisons with NULL yield NULL. The article's expression handles both cases as stated.", "verdict": "Accurate", "sources": [{"url": "https://github.com/postgres/postgres/blob/083ac033419f690758508e08c1736089384bbee8/src/backend/utils/misc/guc_funcs.c#L834-L839", "label": "REL_17_11 \u00b7 src/backend/utils/misc/guc_funcs.c:834-839"}, {"url": "https://github.com/postgres/postgres/blob/083ac033419f690758508e08c1736089384bbee8/doc/src/sgml/func.sgml#L19860-L19862", "label": "REL_17_11 \u00b7 doc/src/sgml/func.sgml:19860-19862"}, {"url": "https://github.com/postgres/postgres/blob/083ac033419f690758508e08c1736089384bbee8/doc/src/sgml/func.sgml#L645-L646", "label": "REL_17_11 \u00b7 doc/src/sgml/func.sgml:645-646"}]}, {"anchor": "F12", "url": "https://pgtrue.postgres.ai/shared/brief/c8b29788-6fe2-48e5-8db9-35fe26e475eb#F12", "claim": "\u2026run in the same transaction just before the write that fails\u2026", "title": "Run transaction-local diagnostics before the failing statement", "explanation": "postgres.c:1139 rejects ordinary commands while the transaction remains aborted. Running the diagnostic SELECT statements before the failing write preserves access to that transaction's tenant setting.", "verdict": "Accurate", "sources": [{"url": "https://github.com/postgres/postgres/blob/083ac033419f690758508e08c1736089384bbee8/src/backend/tcop/postgres.c#L1139-L1145", "label": "REL_17_11 \u00b7 src/backend/tcop/postgres.c:1139-1145"}]}, {"anchor": "F13", "url": "https://pgtrue.postgres.ai/shared/brief/c8b29788-6fe2-48e5-8db9-35fe26e475eb#F13", "claim": "\u2026regardless of whether or not they end up being inserted\u2026", "title": "ON CONFLICT still checks INSERT policies", "explanation": "PostgreSQL 17 CREATE POLICY documents INSERT policy checks for every proposed row. Conflict handling does not exempt existing rows.", "verdict": "Accurate", "sources": [{"url": "https://www.postgresql.org/docs/17/sql-createpolicy.html", "label": "https://www.postgresql.org/docs/17/sql-createpolicy.html"}]}, {"anchor": "F14", "url": "https://pgtrue.postgres.ai/shared/brief/c8b29788-6fe2-48e5-8db9-35fe26e475eb#F14", "claim": "\u2026must satisfy the relation\u2019s SELECT policies\u2026", "title": "RETURNING id adds a SELECT policy check", "explanation": "PostgreSQL 17 CREATE POLICY requires returned inserted rows to satisfy SELECT policies. The article quotes that requirement accurately.", "verdict": "Accurate", "sources": [{"url": "https://www.postgresql.org/docs/17/sql-createpolicy.html", "label": "https://www.postgresql.org/docs/17/sql-createpolicy.html"}]}, {"anchor": "F15", "url": "https://pgtrue.postgres.ai/shared/brief/c8b29788-6fe2-48e5-8db9-35fe26e475eb#F15", "claim": "\u2026the rows proposed for insertion are checked using the relation\u2019s SELECT policies\u2026", "title": "Targeted ON CONFLICT checks SELECT policies", "explanation": "PostgreSQL 17 documents SELECT checks for DO UPDATE and DO NOTHING with an arbiter index or constraint specification.", "verdict": "Accurate", "sources": [{"url": "https://www.postgresql.org/docs/17/sql-createpolicy.html", "label": "https://www.postgresql.org/docs/17/sql-createpolicy.html"}]}, {"anchor": "F18", "url": "https://pgtrue.postgres.ai/shared/brief/c8b29788-6fe2-48e5-8db9-35fe26e475eb#F18", "claim": "\u2026eleven writes against five policy setups\u2026", "title": "The matrix contains 11 writes across 5 setups", "explanation": "The full matrix uses A, B, C, D and F. Its 11 numbered writes give 55 displayed outcomes. Setup E belongs to the additional tests.", "verdict": "Accurate", "sources": []}, {"anchor": "F19", "url": "https://pgtrue.postgres.ai/shared/brief/c8b29788-6fe2-48e5-8db9-35fe26e475eb#F19", "claim": "\u2026three tenants with five rows each\u2026", "title": "The stated starting population totals 15 rows", "explanation": "The stated population is 15 rows (derived: 3 tenants \u00d7 5 rows per tenant). The later starting-row count agrees.", "verdict": "Accurate", "sources": []}]}