Report this

What is the reason for this report?

Can we connect to a PostgreSQL Connection Pool from App Platform?

Posted on March 9, 2022

I have my app & local machine in the trusted sources of the database. I can connect to the database from my local machine but unable to connect to it from the app platform.

Is this something not supported or am I missing something?



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hello, unfortunately using Trusted Sources with App Platform and PostgreSQL connection pools is not supported, however, we are actively working to support that functionality.

So as a workaround I created an Internal Service that’s only accessible by the other components using a PgBouncer docker image:

The thing is you have to create the service through a yaml file using doctl. It should go under services, here is an example:

services:
- envs:
  - key: POOL_MODE
    scope: RUN_AND_BUILD_TIME
    value: transaction
  - key: MAX_CLIENT_CONN
    scope: RUN_AND_BUILD_TIME
    value: "200"
  - key: DEFAULT_POOL_SIZE
    scope: RUN_AND_BUILD_TIME
    value: "20"
  - key: MAX_DB_CONNECTIONS
    scope: RUN_AND_BUILD_TIME
    value: "40"
  - key: SERVER_TLS_SSLMODE
    scope: RUN_AND_BUILD_TIME
    value: require
  - key: DATABASE_URL
    scope: RUN_AND_BUILD_TIME
    type: SECRET
    value: **postgresql://username:password@host:port/dbname**
  image:
    registry: edoburu
    registry_type: DOCKER_HUB
    repository: pgbouncer
    tag: latest
  instance_count: 1
  instance_size_slug: professional-xs
  internal_ports:
  - 5432
  name: pgbouncer

I used this docker image: https://hub.docker.com/r/edoburu/pgbouncer/

Once is up and running you can access it from the other components using the component’s name and port, for example:

DATABASE_URL=postgresql://username:password@pgbouncer:5432/dbname

The component is not accessible publicly so it’s secure. Hope it helps.

Regards, Pedro

This comment has been deleted

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.