Reattach the database

If you’re in a rush, you can also do this manually.

Something like this should do the trick:

  1. Connect to your Postgres instance.
    a. fly ssh console --app <app-name>
    b. psql postgres://postgres:$OPERATOR_PASSWORD@$FLY_APP_NAME.internal:5432

  2. Create a new database
    a. \l+ to list databases.
    b. CREATE DATABASE <database-name>;

  3. Create a new user
    a. \du+ to list users.
    b. CREATE USER <user-name> WITH LOGIN PASSWORD 'password';

  4. Grant access to database
    a. GRANT ALL PRIVILEGES ON DATABASE <database-name> TO <user-name>;

  5. Set your DATABASE_URL secret on your target consumer app.
    a. Your URL should look like:
    postgres://<user>:<password>@<postgres-app>.internal:5432/<database-name>
    b. Test the above URL using psql to ensure it works before setting it.
    c. fly secrets set DATABASE_URL=<database-url> --app <app-name>

1 Like