Skip to main content
This page is archived. Fly Postgres (unmanaged) is no longer maintained, and Fly.io Support is not able to provide support or guidance for it. We now offer Fly.io Managed Postgres, our fully-managed database service that handles all aspects of running production PostgreSQL databases.These pages are kept for reference and are not listed in the navigation. The full set is indexed on the Fly Postgres (Unmanaged) page.

Attach a Fly App

fly postgres attach is a convenience command to quickly associate a Fly App with your Fly Postgres cluster app.
When you attach an app to Postgres, a number of things happen:
  • A new database and user are created in the Postgres cluster app, using the name of the consuming app (a Fly App). If the consuming app is named “my-app”, then both the database and the user are named “my_app”.
  • The user is allocated a generated password.
  • The consuming app and the Postgres app are marked as attached in the great floating ledger in the Fly.io cloud, which enables you to use fly postgres detach later.
When the now-attached consuming app starts, it will have access to an environment variable DATABASE_URL set to a Postgres connection URI with the username, password, host, port, and dbname filled in.

Detach a Fly App

If the consuming app’s access to this database was purely due to fly postgres attach, then you can revoke that access using fly postgres detach.
This will remove the <app name> user from the Postgres cluster, and the DATABASE_URL secret from the <app name> app. The platform will no longer view the two apps as associated. The database is not removed.

Check if a Fly App is attached to a Postgres app

Run fly postgres users list --app <postgres app name> on your Postgres cluster app. If there is an attached Fly App, then the app’s name will be in the list of users. See Users & Roles.