Anna
Anna

Reputation: 149

How to connect to gcloud postgres db from a container inside cloud run

I've a container inside my cloud run that expects to receive DATABASE_URL variable. I would like to connect to my existing GCP postgres db, but i just can't get it work. I've defined a private IP on my db instance and trying to connect via this url string

postgres://<db-user-name>:<my-password>@<my-ip>/<my-db-name>

In the logs I can see that it's just stock on:

level=info msg="Connecting with postgres://<username>:<password>@<db-ip>/<dbname>"

For few minutes and then it's say:

level=info msg="Unable to connect to database" error="Could not Connect to SQL: dial tcp <ip>:5432: connect: connection timed out"

Any help would be appreciated.

Upvotes: 0

Views: 629

Answers (1)

Ashok
Ashok

Reputation: 3581

You may have to edit postgresql.conf and pg_hba.conf files.

postgresql.conf:

listen_addresses = '*'

pg_hba.conf file:

host    all         all         192.168.1.0/24        md5

Upvotes: 1

Related Questions