Short answer
A Postgres policy, or RLS policy, is a named rule attached to a table that decides which rows a role may see (USING) and which rows it may write (WITH CHECK) for a given command. Policies only take effect once row level security is enabled. Permissive policies are combined with OR, restrictive ones with AND, and a missing policy means no access.
Ask an AI about this page:ChatGPTClaude
On this page
A Postgres policy is a named rule on a table that tells row level security which rows a role may read or write for a given command. It is created with CREATE POLICY and does nothing until RLS is enabled on the table. Once RLS is on, Postgres denies everything that no policy allows.
The parts of a policy
create policy "Owners update their notes"
on public.notes
as permissive
for update
to authenticated
using ((select auth.uid()) = user_id)
with check ((select auth.uid()) = user_id);| Part | What it decides | Default |
|---|---|---|
as permissive / as restrictive | Combined with OR (any passing policy is enough) or with AND (all must pass) | permissive |
for … | Which command: select, insert, update, delete or all | all |
to … | Which roles it applies to, in Supabase usually anon or authenticated | public (every role) |
using (…) | Which existing rows are visible or may be changed | – |
with check (…) | Whether the new row may be written | the using expression |
Rows hidden by using disappear silently. A row that fails with check raises an error.
Policies in an AI-built app
AI builders write policies in SQL migrations, and three patterns cause most problems:
using (true)on private data. It switches RLS on in name only; the Security Advisor flags it as lint 0024 (permissive_rls_policy).- An update policy without
with checkthat has a different expression, or no owner check at all. A user can then rewriteuser_idand move a row to another account. - An update policy without a select policy. Postgres needs the row to be visible to an update that reads columns. In our test, an update with only an update policy finished without error and changed nothing, a classic “saving does nothing” bug.
How to check your app
List every policy in the public schema and read each line out loud:
select tablename, policyname, permissive, roles, cmd, qual, with_check
from pg_policies
where schemaname = 'public'
order by tablename, policyname;For each row ask: does roles make sense, is qual (the using part) tied to the caller through auth.uid() or a membership check, and does every UPDATE and INSERT have a with_check? Then test as two different users, as shown in How to test your RLS policies.
How to fix or prevent it
Write one policy per command, limit it to authenticated where visitors don’t need access, use (select auth.uid()) so Postgres evaluates it once per query, and index the column the policy filters on. A policy that says yes to everyone is fixed step by step in RLS policy USING (true).
Frequently asked questions
What is the difference between USING and WITH CHECK?
USING filters the existing rows a command may see or touch (select, update, delete). WITH CHECK validates the new or changed row being written (insert, update). An update policy usually needs both.
What happens if two policies apply to the same table?
Permissive policies, the default, are combined with OR: one passing policy is enough. Restrictive policies are combined with AND and must all pass, on top of at least one permissive policy.
Why does my update run without error but change nothing?
An update that reads columns, for example in its WHERE clause, also needs the row to be visible through a select policy. Without one, the update matches no rows. Add a select policy for the same users.
Sources
- 1.CREATE POLICY — PostgreSQL Documentation
- 2.Row Security Policies — PostgreSQL Documentation
- 3.Row Level Security — Supabase Docs
- 4.Performance and Security Advisors — Supabase Docs