How can 2 apps share a Postgres db?

Hi! I’m new to fly. What is the recommended way to share 1 postgres db across different apps? It should be easy so I think I must be doing it the wrong way.

I deployed 1 app (consumer facing website) which was attached with a newly created postgres app. This works fine. After I deployed the 2nd app (admin website), I’ve tried to attach the previous postgres app to it but there was an error. The log says public.users relation doesn’t exist. I also tried to set the DATABASE_URL secret manually using the postgres’s credentials earlier but it also doesn’t work.

Any help would be appreciated!

The “simplest” way to do this is to copy the DATABASE_URL from the first app, and set it as a secret in the second:

fly secrets set DATABASE_URL=<copied> -a <name-of-admin-app>

By default, the attach process creates a new database in the same postgres cluster. You can override the --database-name to attach to an existing database, if you want. But copying the secret is simpler.