Connect to public or private DB URL from app?
I'm just coming back around to updating an old project sicne the DB migrations a few months back.
I have PgBouncer connected to my Postgres DB.
- From my app I am connecting to the Public DB URL for PgBouncer
- then PgBouncer connects to the Postgres DB via private internal connection (whatever was setup during that deployment).
I just need to confirm that the app connecting to the public DB url is correct.
Thanks
Solution:Jump to solution
pgbouncer should be connecting to your database via the private network and your app should be connecting to pgbouncer via the private network too
9 Replies
Project ID:
c0958e3e-4cd8-4f89-9376-7c4003820f57
c0958e3e-4cd8-4f89-9376-7c4003820f57
Solution
pgbouncer should be connecting to your database via the private network and your app should be connecting to pgbouncer via the private network too
okay this is working:
I'm using prisma and their pgbouncer docs say to set the pgBouncer URL then connect direct to postgres as
directUrl
for Prisma Migrate
https://www.prisma.io/docs/orm/prisma-client/setup-and-configuration/databases-connections/pgbouncer#prisma-migrate-and-pgbouncer-workaround
If I try to use the private Url for postgres for Direct I get an error but I think it should be fine connecting to public?
you do not want to connect to the public url as that would subject yourself to egress fees
are you getting that error during build?
If I change this to
DATABASE_URL_DIRECT=${{myapp-db.DATABASE_PRIVATE_URL}}
in the variables and deploy I get that error in the build log and it fails
But it works with DATABASE_URL_DIRECT=${{myapp-db.DATABASE_URL}}
the private network is not available during build on the legacy builder, switch to the new builder in the service settings
amazing, that worked. Thanks so much!
no problem!