import Layout from '~/layouts/DefaultGuideLayout'
export const meta = { title: 'Migrate from Postgres to Supabase', description: 'Migrate your Postgres database to Supabase.', }
This is a guide for migrating your Postgres database to Supabase. Supabase is a robust and open-source platform. Supabase provide all the backend features developers need to build a product: a Postgres database, authentication, instant APIs, edge functions, realtime subscriptions, and storage. Postgres is the core of Supabase—for example, you can use row-level security and there are more than 40 Postgres extensions available.
This guide demonstrates how to migrate your Postgres database to Supabase to get the most out of Postgres while gaining access to all the features you need to build a project.
- Log in to your provider to get the connection details for your Postgres database.
- Click on PSQL Command and edit it adding the content after
PSQL_COMMAND=
.
Example:
%env PSQL_COMMAND=PGPASSWORD=RgaMDfTS_password_FTPa7 psql -h dpg-a_server_in.oregon-postgres.provider.com -U my_db_pxl0_user my_db_pxl0
- If you're new to Supabase, create a project.
- Go to the Database settings for your project in the Supabase Dashboard.
- Under Connection Info, note your Host (
$SUPABASE_HOST
). - Save your password or reset it if you forgot it.
The fastest way to migrate your database is with the Supabase migration tool on Google Colab. Alternatively, you can use the pg_dump and psql command line tools, which are included in a full PostgreSQL installation.
<Tabs scrollable size="small" type="underlined" defaultActiveId="colab" queryGroup="migrate-method"
- Set the environment variables (
PSQL_COMMAND
,SUPABASE_HOST
,SUPABASE_PASSWORD
) in the Colab notebook. - Run the first two steps in the notebook in order. The first sets the variables and the second installs PSQL and the migration script.
- Run the third step to start the migration. This will take a few minutes.
Use pg_dump
with your Postgres credentials to export your database to a file (e.g., dump.sql
).
pg_dump --clean --if-exists --quote-all-identifiers \
-h $HOST -U $USER -d $DATABASE \
--no-owner --no-privileges > dump.sql
Use psql
to import the Postgres database file to your Supabase project.
psql -h $SUPA_URL -U postgres --file dump.sql -p 6543 -d postgres
- To only migrate a single database schema, add the
--schema=PATTERN
parameter to yourpg_dump
command. - To exclude a schema:
--exclude-schema=PATTERN
. - To only migrate a single table:
--table=PATTERN
. - To exclude a table:
--exclude-table=PATTERN
.
Run pg_dump --help
for a full list of options.
export const Page = ({ children }) =>
export default Page