Skip to content

Instantly share code, notes, and snippets.

@abhishekhugetech
Created January 15, 2026 05:33
Show Gist options
  • Select an option

  • Save abhishekhugetech/04b4bf89780ee3000d75e17ba8744232 to your computer and use it in GitHub Desktop.

Select an option

Save abhishekhugetech/04b4bf89780ee3000d75e17ba8744232 to your computer and use it in GitHub Desktop.
Gist to copy supabase DB to another DB
docker run --name test_postgres -e POSTGRES_PASSWORD=123456 -p 5433:5432 -d postgres
# returns container is as a018bf7d5e0a
# We'll be using this container to run psql commands
# docker exec -it a018bf7d5e0a psql
# Dump roles and schema
supabase db dump --db-url "postgresql://[USER]:[PASSWORD]@[HOST]:5432/postgres" -f roles.sql --role-only
supabase db dump --db-url "postgresql://[USER]:[PASSWORD]@[HOST]:5432/postgres" -f schema.sql
# Copy roles into container
docker cp ./roles.sql a018bf7d5e0a:/roles.sql
docker cp ./schema.sql a018bf7d5e0a:/schema.sql
docker exec -it a018bf7d5e0a psql \
--single-transaction \
--variable ON_ERROR_STOP=1 \
--command 'SET session_replication_role = replica' \
--file roles.sql \
--file schema.sql \
--dbname "postgresql://[USER]:[PASSWORD]@[HOST]:6543/postgres"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment