Supabase database

How to check row level security is on for every Supabase table

Run a query on pg_class that lists each table in the public schema with its relrowsecurity flag and its policy count. A row where rls_on is false is a table with no row rules. A row where it is true but the policy count is 0 is locked to everyone.

TL;DR

  • Query pg_class (or pg_tables) for every table in public. false means RLS is off.
  • Join pg_policy to see policy counts. RLS on with 0 policies blocks the API roles. RLS on with policies still needs its policies read and tested.
  • Repeat for every schema you expose through the API.
  • Do not test from the SQL editor’s default role. Table owners normally bypass RLS.

What does “RLS enabled” mean in Postgres?

Row level security is a per-table switch. PostgreSQL stores it as relrowsecurity in the pg_class catalog: true if the table has row-level security enabled. The pg_tables view shows the same flag as rowsecurity. Once it is on, every normal read or write needs a policy to allow it, and with no policy a default-deny applies: no rows are visible or can be changed.

For a Supabase app this is the whole boundary. Requests from the browser run as anon or authenticated. If RLS is off and those roles have been granted access, they can read and change every row. Supabase’s docs say to enable RLS on every table in an exposed schema.

Which query lists every table and its RLS status?

The short version uses pg_tables:

rls-status-short.sql
select schemaname, tablename, rowsecurity
from pg_tables
where schemaname = 'public'
order by rowsecurity, tablename;

The better version uses pg_class. It also covers partitioned tables, shows whether RLS is forced on the owner, and counts policies:

rls-status-full.sql
-- Every table in public: RLS flag, forced flag, number of policies
select c.relname as table_name,
       c.relrowsecurity as rls_on,
       c.relforcerowsecurity as rls_forced,
       count(p.polname) as policies
from pg_class c
join pg_namespace n on n.oid = c.relnamespace
left join pg_policy p on p.polrelid = c.oid
where n.nspname = 'public' and c.relkind in ('r', 'p')
group by c.relname, c.relrowsecurity, c.relforcerowsecurity
order by c.relrowsecurity, c.relname;

Run it in the Supabase SQL editor, or locally with psql against a copy built from your migrations. It only reads the catalogs, so it changes nothing. Here relkind 'r' is an ordinary table and 'p' a partitioned table.

How do I read the result?

rls_onpoliciesWhat it meansFinding
falseanyNo row rules. If the API roles have grants, anyone with your public key can read and change every row. Switch RLS on and add policies.PL-008
true0Locked to the API roles. Safe, but the app shows empty results, and the quick fix people reach for is often a leak.PL-003
true1 or moreProtected only as well as the policies. Read them, then test the table as anon, a stranger and the owner.PL-001, PL-002, PL-005

Some tables are meant to be public, such as a product list. A false there still deserves a decision, not an accident. A table full of emails or phone numbers with rls_on = false is the one to fix today.

Is RLS on enough?

No. RLS on only means a policy decides. A policy that says using (true) decides yes for everyone. List the read policies and look at the roles and conditions:

list-policies.sql
select tablename, policyname, roles, cmd, qual
from pg_policies
where schemaname = 'public' and cmd in ('SELECT', 'ALL')
order by tablename;

Look for {public} or {anon} in roles, and for a qual of true or one that never mentions auth.uid(). Then test each table as the three people who matter. RLS policies explained has the script.

What does this query miss?

  • Other schemas. Change 'public' to any other schema you expose through the API.
  • Views. A view has no RLS flag and runs as its owner unless it uses security_invoker (PL-014, guide).
  • Functions. Supabase’s docs say RLS doesn’t apply to functions, so grant execute only to the roles that need it (PL-006).
  • Files. Storage has its own policies on storage.objects (PL-015, guide).
  • Owner bypass. The table owner, and any role with BYPASSRLS, skips RLS unless the owner is forced with FORCE ROW LEVEL SECURITY. The SQL editor usually runs as such a role, so never judge a table by what you see there.

How do I switch RLS on without breaking the app?

Put the change in a new migration, so it is versioned and can be rebuilt:

supabase/migrations/…_enable_rls_orders.sql
alter table public.orders enable row level security;

create policy "Users read own orders" on public.orders
  for select to authenticated
  using ((select auth.uid()) = user_id);

Enabling RLS with no policy blocks everything, which breaks the page that reads the table. Add the policies in the same migration, then test as the owner to confirm they still see their rows. Supabase’s docs also describe event triggers that enable RLS automatically on new tables. If you use one, still re-run the query after each AI change.

Questions people ask

What is the difference between rowsecurity in pg_tables and relrowsecurity in pg_class?

They are the same flag. The pg_tables view reads it from pg_class.relrowsecurity and calls it rowsecurity. Use pg_class when you also want partitioned tables, the forced flag or a join to policies.

Does RLS on mean my table is private?

No. It means policies decide. A table with RLS on and a policy of using (true) is readable by everyone that policy covers. Check the policies, then test as anon, a stranger and the owner.

Why can I see every row when I query in the SQL editor?

The editor usually connects as the postgres role, which owns your tables. PostgreSQL’s docs say table owners normally bypass row security, and superusers and roles with BYPASSRLS always do. Use set local role anon inside a transaction to test.

What does FORCE ROW LEVEL SECURITY do?

It makes a table’s owner subject to its policies as well. The API roles are not owners, so it does not change what your public key can read. It matters for server code that connects as the owner.

Does Supabase turn on RLS automatically for new tables?

Do not assume it. For tables created with SQL, Supabase’s docs tell you to enable RLS yourself, and describe event triggers that can do it for you. Run the query above after each change to be sure.

Sources

The checks behind this guide, each with example code, a self-check and the fix.

Free check

Check your app for this, free.

Paste your public repo. PatchLabs rebuilds your database from its migrations, tests it as a visitor, a stranger and the owner, reads the code for keys and risky patterns, and hands you the fix.

First app free, fixes includedNever touches your database

Written by Manraj Singh Dhillon. Last checked 11 Nov 2026. Code samples are synthetic and run against your own project; nothing here names a real app. Spotted a mistake? Tell us.