Guide

pg_dump with Supabase: flags, RLS errors and version mismatch

Everything that goes wrong when you point pg_dump at Supabase, and the fix for each: the pooler, version mismatch, row level security, Supabase-managed schemas and slow dumps.

By Sascha Heyer · Last updated December 4, 2026

pg_dump is the standard way to take a logical backup of Postgres, and it works against Supabase like against any Postgres. Five things trip people up. Here they are, with the error you will see and the fix.

1. “timeout expired” or “Network is unreachable”

You are probably using the direct connection db.<ref>.supabase.co, which is IPv6-only unless the project has the IPv4 add-on. Use the Session pooler string from the dashboard’s Connect button instead:

pg_dump "postgresql://postgres.<project-ref>:<password>@aws-0-<region>.pooler.supabase.com:5432/postgres" ...

Note the user: on the pooler it is postgres.<project-ref> (or <your-role>.<project-ref>), not just postgres. And use port 5432 (session mode), not 6543 (transaction mode): pg_dump needs one session for its snapshot.

2. “aborting because of server version mismatch”

pg_dump: error: aborting because of server version mismatch
pg_dump: detail: server version: 17.4; pg_dump version: 15.10

pg_dump refuses to dump a server newer than itself. Install the client of the server’s major version (or newer) and call it by its full path:

# macOS
brew install postgresql@17
/opt/homebrew/opt/postgresql@17/bin/pg_dump --version

# Debian / Ubuntu, from the PostgreSQL apt repository
sudo apt install -y postgresql-common && sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y
sudo apt install -y postgresql-client-17
/usr/lib/postgresql/17/bin/pg_dump --version

A newer pg_dump can dump an older server, so pg_dump 17 handles both Postgres 15 and 17 projects. The restore side wants the same or a newer server version than the dump came from.

3. “query would be affected by row-level security policy”

pg_dump: error: query failed: ERROR:  query would be affected by row-level security policy for table "invoices"

pg_dump runs with row_security = off so it never makes an incomplete backup by accident; if the role you connect with is subject to a policy, it stops instead. Connect with a role that bypasses RLS. Create a read-only one in the SQL editor:

create role liferaft_backup with login password 'a-long-random-password' bypassrls;
grant pg_read_all_data to liferaft_backup;

pg_read_all_data (Postgres 14+) grants read access to every table, view and sequence in every schema; bypassrls lets pg_dump see every row. The role cannot write. Connect as liferaft_backup.<project-ref> through the pooler.

4. Permission errors on Supabase schemas

Some schemas belong to Supabase services and are not readable by every role (vault, pgsodium), and others are recreated by every new project anyway (realtime, graphql, extensions). Exclude them:

pg_dump "$DB_URL" --no-owner --no-privileges \
  --exclude-schema=extensions --exclude-schema=graphql --exclude-schema=graphql_public \
  --exclude-schema=realtime --exclude-schema=_realtime --exclude-schema=supabase_functions \
  --exclude-schema=vault --exclude-schema=pgsodium --exclude-schema=pgsodium_masks \
  --exclude-schema=net --exclude-schema=cron --exclude-schema=_analytics \
  | gzip > backup.sql.gz

Keep auth (users, identities, sessions) and storage (bucket and object metadata) in: they are your data. --no-owner --no-privileges leaves out ALTER OWNER and GRANT statements for roles that will not exist where you restore.

5. Big databases and slow dumps

  • Compress on the fly (| gzip) rather than writing plain SQL first; dumps of text-heavy tables shrink five to ten times.
  • For very large databases use the directory format with parallel jobs: pg_dump -Fd -j 4 -f backup-dir, restored with pg_restore -j 4. It needs a session per job, so stay on the session pooler.
  • Skip bulky tables you can rebuild with --exclude-table-data, for example audit logs you do not need back.

A consistent snapshot

pg_dump always dumps from one snapshot, so the file is consistent even while your app writes. If you want row counts that match the file exactly (to check a restore later), take them in the same snapshot: open a repeatable read transaction, run select pg_export_snapshot(), count inside it, and pass the snapshot id to pg_dump --snapshot=<id> while the transaction stays open. That is how Liferaft’s manifests are made.

Rather not run this yourself? Liferaft runs the dump every night through a read-only role, stores the copy outside Supabase, and restores it every week to count every row. Free for one Supabase project; Solo is $9 a month for five. Back up my Supabase project free

More guides

Compare Supabase backup tools