8 min read
How to back up a Supabase database properly
Most founders assume Supabase has them covered, until an AI tool runs a migration that drops a table, or someone deletes the wrong rows. Here's what you have, what you don't, and how to make a backup you control.
1. Know what you already have
- Supabase's own backups depend on your plan. Open your project's Database settings, then Backups, to see what's kept and for how long. On the Free plan, don't count on one you can restore yourself.
- Files in Storage buckets aren't inside database backups. Back them up separately if they matter.
- A backup stored inside the same account doesn't help if you lose access to the account, or the project is deleted.
2. Make a login that can only read
Don't back up with the postgres login: anything holding it can change or delete everything. Create a role that can read every table and nothing else. It needs to bypass row-level security, or the backup silently misses rows.
create role backup_reader with login password 'choose-a-long-random-password' bypassrls;
grant pg_read_all_data to backup_reader;
alter role backup_reader set default_transaction_read_only = on;3. Dump it with pg_dump
Use the session pooler or direct connection string from the dashboard's Connect panel, with port 5432. The transaction pooler (port 6543) doesn't work for pg_dump. Use a pg_dump version at least as new as your database.
pg_dump "postgresql://backup_reader.<project-ref>:<password>@<pooler-host>:5432/postgres" \
--format=custom --no-owner --no-privileges --file=backup.dump4. Store it somewhere else, and test it
- Upload it to storage in a different account: Cloudflare R2, Amazon S3, Backblaze B2. Keep a few weeks of copies.
- A backup you've never restored is a hope, not a backup. Restore one into a throwaway database now and then and count the rows.
- Schedule it. A backup that depends on remembering doesn't happen.
Prompt for your AI tool
Before changing my database schema or deleting data, write the change as a migration file I can review, list exactly which tables and rows it affects, and remind me to take a backup first. Never run destructive SQL directly.
Vern Backup does all of this every night
Nightly backups of your Postgres or Supabase database through a read-only login (Vern refuses one that could change data), stored in your own bucket, each one checked. Vern keeps only the record, never your data.
Who gets it: Pro, Agency and Vern Care
See plans