Jacob Paris
← Back to all content

Set up PostgreSQL on Fly

Fly is a managed container platform with first class support for Postgres databases.

By the end of this article you'll have a deployed database and a connection string you can pass to your app.

Getting started

Use the Fly CLI to create a new postgres database.

fly postgres create

Choose whichever settings you want. When choosing a region, your top concern should be keeping your database as close as possible to your server.

Fly will output a connection string, which you can use to connect to your database from other Fly apps. Note that it ends in .flycast – this will not be valid outside of Fly.

Save the connection string to your app's .env file


Make it accessible outside of Fly

If you want to access the database from outside of Fly, you'll need to allocate an IP address for it.

fly ips allocate-v6 --app app-name-1234

Then update your connection string to use the public .fly.dev domain instead of .flycast.


Connect to your database

You should now be able to connect to the database using the connection string. If you have psql installed, you can run the following command:

psql "postgres://postgres:asdfasdfasdfasdf@app-name-1234.fly.dev:5432"

If you enter a new terminal session inside the database, then you've connected successfully and your database is ready to use.

Professional headshot

Hey there! I'm a developer, designer, and digital nomad building cool things with Remix, and I'm also writing Moulton, the Remix Community Newsletter

About once per month, I send an email with:

  • New guides and tutorials
  • Upcoming talks, meetups, and events
  • Cool new libraries and packages
  • What's new in the latest versions of Remix

Stay up to date with everything in the Remix community by entering your email below.

Unsubscribe at any time.