Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Postgres DATABASE_URL to connect cloud run to postgres on cloud SQL

I am trying to connect my cloud run app to cloud sql, here is my cloudbuild.yaml

steps:
- name: 'gcr.io/cloud-builders/npm'
  env:
    - DATABASE_URL=$_DATABASE_URL
  entrypoint: npx
  dir: './server'
  args:
    - 'prisma'
    - 'migrate'
    - 'deploy'

However, I keep on getting the error Please make sure your database server is running at '/cloudsql/learninfra001:us-central1:learninfra001-postgres':'5432'. Here is the _DATABASE_URL I use for substitution variable postgresql://postgres:password@localhost/db?schema=public&host=/cloudsql/learninfra001:us-central1:learninfra001-postgres I have made sure the following:

  • The default cloud run service account has Cloud SQL Client role
  • The database db is created
  • Within the cloudrun service, under connections, the Cloud SQL connections is pointing to the correct instance (learninfra001:us-central1:learninfra001-postgres)

Using white-listed public IP, I am able to connect to the DB. However, I just can't seem to get cloud run to work. Is there anything else I could check? Or is there a way to get more logging to see why it is not connecting?

like image 838
Max Yuan Avatar asked Jul 17 '26 01:07

Max Yuan


1 Answers

In short, you'll need to enable a Cloud SQL connection to your Cloud SQL instance from Cloud Build.

See https://cloud.google.com/sql/docs/mysql/connect-build for details.

like image 60
enocom Avatar answered Jul 20 '26 11:07

enocom



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!