Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Cloud Run: Cant connect to Postgress SQL

I am following this tutorial to upload my existing Django project running locally on sqlite to Google Cloud Run / Postgres.

I have the cloud_sql_proxy service running and can sign into Postgres from the command line.

I am at the point of running the command

python manage.py migrate

And I get the error:

django.db.utils.OperationalError: connection to server on socket "/cloudsql/cgps-registration-2:us-central-1:cgps-reg-2-postgre-sql/.s.PGSQL.5432" failed: No such file or directory
        Is the server running locally and accepting connections on that socket?

The answer to that questions is Yes, the server is running locally and accepting connections because I can log in with the Postgres client:

agerson@agersons-iMac ~ % psql "sslmode=disable dbname=postgres user=postgres hostaddr=127.0.0.1"  
Password for user postgres: 
psql (14.1, server 13.4)
Type "help" for help.

postgres=> 

I double checked the connection string in my .env file and it has the correct UN / P

Is this scoket not getting created somehow in a previous step?

/cloudsql/cgps-registration-2:us-central-1:cgps-reg-2-postgre-sql/.s.PGSQL.5432
like image 564
AdamG Avatar asked Feb 17 '26 20:02

AdamG


1 Answers

It looks like there's a mismatch between what the app is looking for and how you're launching the proxy. The error explains the problem.

You're launching the proxy like this with an incorrect region name (us-central):

cloud_sql_proxy -instances="cgps-registration-2:us-central:cgps-reg-2-postgre-sql=tcp:5432

But the app is looking for us-central1. Try this (omitting the =tcp:5432 to create a Unix socket):

cloud_sql_proxy -instances="cgps-registration-2:us-central1:cgps-reg-2-postgre-sql
like image 72
enocom Avatar answered Feb 20 '26 15:02

enocom