How to copy local postgres DB to fly.io?

I’m evaluating fly.io deployment of my phx app. Is there an easy way to copy my local postgres db to my fly.io db?

Exact steps will depend on what you’ve done thus far or not.

Has the database been created within Postgres on your Fly Postgres app? If so, skip this step:

flyctl ssh console -a fly-postgres-app-name
createdb -p 5433 -U postgres server-db-name

Next, setup a proxy tunnel to the Fly Postgres app:

flyctl proxy 5433:5432 -a fly-postgres-app-name

In another terminal, dump your local database and restore it on the Fly Postgres app via the proxy:

pg_dump -O local-db-name | psql postgres://postgres@localhost:5433/server-db-name

If you’ve already setup another role within Postgres on your Fly Postgres app, you can use it instead of the postgres user: postgres://server-role-name@localhost:5433/server-db-name

3 Likes

Generally for fly.io specific questions you might want to try https://community.fly.io first

1 Like