Menu

pg_dump on Supabase: "query would be affected by row-level security policy"
📰

pg_dump on Supabase: "query would be affected by row-level security policy"

DEV Community: postgres·AK D·about 2 hours ago
#VBdEArsn
#devtopostgresql#devto#dev#role#backup
Reading 0:00
15s threshold

On Supabase, tables exposed to the API should have row-level security, and storage.objects has it on every project. That changes what pg_dump can read, depending on the role that runs it.

By default, the dump fails

pg_dump sets row_security = off . That does not skip RLS. It makes Postgres raise an error instead of filtering rows:

ERROR: query would be affected by row-level security policy for table "profiles"

Enter fullscreen mode

Exit fullscreen mode

This happens for any role that is not a superuser and has no BYPASSRLS , unless it owns the table and the table is not forced. A failed backup is the good outcome: you notice.

The flag that hides it

The usual answer to that error is --enable-row-security . pg_dump then dumps only the rows the role can see. A backup role usually matches no policy written for anon or authenticated , so those tables come out empty. Exit code 0, no warning.

pg_read_all_data does not help

pg_read_all_data (Postgres 14+) grants SELECT on everything, but not BYPASSRLS .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.