Attach or Detach a Fly App

Attach a Fly App

fly postgres attach is a convenience command to quickly associate a Fly app with your Fly Postgres cluster.

flyctl postgres attach --app <app-name> <postgres-app-name>

When you attach an app to Postgres, a number of things happen:

  • A new database and user are created in the Postgres App. If the attached app is named “myapp”, both the database and the user are named “myapp” too.
  • 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 cloud. The main value of this is in order to be able to use fly pg detach later.

When the attached 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, you can revoke that access using flyctl postgres detach.

flyctl postgres detach --app <app-name> <postgres-app-name>

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.