By Sascha Heyer · Last updated December 4, 2026
A Supabase database is a normal Postgres database, so the standard tool for a logical backup is pg_dump. The only Supabase-specific parts are which connection string to use, which schemas to include, and row level security. This guide covers all three.
Step 1: get the right connection string
In the Supabase dashboard, click Connect at the top of your project. You will see three strings. For backups use the Session pooler:
postgresql://postgres.<project-ref>:<password>@aws-0-<region>.pooler.supabase.com:5432/postgres- The direct connection (
db.<project-ref>.supabase.co) works too, but resolves to IPv6 only unless you pay for the IPv4 add-on, and many home and CI networks have no IPv6. - The transaction pooler (port 6543) does not work for pg_dump: it hands each statement to a different server connection, and pg_dump needs one session for its consistent snapshot.
Way 1: the Supabase CLI
The Supabase CLI wraps pg_dump (it runs it in Docker, so Docker must be running) and splits roles, schema and data into three files:
supabase db dump --db-url "$DB_URL" -f roles.sql --role-only
supabase db dump --db-url "$DB_URL" -f schema.sql
supabase db dump --db-url "$DB_URL" -f data.sql --use-copy --data-onlyThis is the format Supabase’s own migration guide restores from, and the easiest way to move a project to a new one. By default the schema dump leaves out the schemas Supabase manages itself, because a new project creates them.
Way 2: pg_dump directly
With the Postgres client tools installed (brew install postgresql@17 on macOS, apt install postgresql-client-17 from the PostgreSQL apt repository on Debian/Ubuntu), one command makes a single compressed file:
pg_dump "$DB_URL" \
--no-owner --no-privileges \
--exclude-schema=extensions --exclude-schema=graphql --exclude-schema=graphql_public \
--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=_realtime --exclude-schema=_analytics \
| gzip > backup-$(date +%F).sql.gz--no-owner --no-privilegeskeeps the file restorable into any Postgres, where Supabase’s internal roles do not exist.- The excluded schemas belong to Supabase’s own services. Keeping
authmeans your users (and their password hashes) are in the backup; keepingstoragemeans the list of your files is. - Use the pg_dump of your server’s major version or newer. Check the server with
psql "$DB_URL" -c 'show server_version'. An older pg_dump stops with “server version mismatch”; see the pg_dump guide.
Row level security: use a backup role
If your tables use row level security, pg_dump may stop with query would be affected by row-level security policy for table. pg_dump refuses to produce a backup that silently misses rows. The clean fix, which Supabase’s troubleshooting guide also suggests, is a dedicated role that can read everything and bypass RLS. Run this once in the SQL editor:
create role liferaft_backup with login password 'a-long-random-password' bypassrls;
grant pg_read_all_data to liferaft_backup;Then connect as liferaft_backup.<project-ref> (the pooler needs the project ref after the role name) with that password. The role can read every table, including auth, and cannot change anything, which also makes it the right credential to hand to a backup service or a CI job. Name it whatever you like.
Way 3: run it every night
A backup you run by hand is a backup you will forget. The smallest reliable version is a scheduled job that dumps, uploads and prunes. A GitHub Actions sketch:
on:
schedule: [{ cron: '0 3 * * *' }]
jobs:
backup:
runs-on: ubuntu-latest
steps:
- run: sudo apt-get install -y postgresql-common && sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y && sudo apt-get install -y postgresql-client-17
- run: /usr/lib/postgresql/17/bin/pg_dump "${{ secrets.DB_URL }}" --no-owner --no-privileges | gzip > backup.sql.gz
- run: aws s3 cp backup.sql.gz "s3://my-backups/supabase/$(date +%F).sql.gz"Do not commit dumps to the repository itself: they contain your users’ data and password hashes. Put them in a private bucket with a lifecycle rule that deletes old copies, and give the job its own credentials.
Every run reads the whole database out of Supabase, and Supabase counts that as egress: 5 GB a month are included on Free, 250 GB on Pro, then $0.09 per GB (December 2026). On the Free plan a weekly schedule is the safe choice; for a large database, do the sums in the egress guide before going daily.
Step 4: prove it restores
Whichever way you choose, the backup is only finished when you have restored it once. Restore into a scratch Postgres (Docker is enough), count rows, compare. The restore guide has the commands, including a query that counts every table on both sides.
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