> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fly.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Attach or Detach a Fly App

<Warning>
  Important: We are not able to provide support or guidance for unmanaged Postgres. We now offer [Fly.io Managed Postgres](/mpg) , our fully-managed database service that handles all aspects of running production PostgreSQL databases.
</Warning>

<img src="https://mintcdn.com/fly-io/v-XOGeVK6s4rQ-4y/images/attach-detach.webp?fit=max&auto=format&n=v-XOGeVK6s4rQ-4y&q=85&s=d68811869346447846f8c6cd2bc290b9" alt="" width="820" height="374" data-path="images/attach-detach.webp" />

## Attach a Fly App

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

```
fly postgres attach <postgres app name> --app <app name>
```

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`.

```
fly postgres detach <postgres app name> --app <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.

## 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](/postgres/managing/users-and-roles).
