Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Cloud Run API to Cloud SQL (Postgres) - Unable to connect.

I must be doing something wrong and I appreciate any help I can get with this.

This is what is happening:

I created a simple hello world cloud run api, and that worked just fine.

I then tried to connect to the postgres cloud sql database I created and wanted to return a SELECT NOW(). 

 

 

This is what code assist says:

 

server.ts code in the immersive is configured to use the corresponding socketPath: '/cloudsql/test:us-west1:test-db', the ECONNREFUSED 127.0.0.1:5432 error you are still getting strongly points back to the Unix domain socket file not being ready or accessible when your application attempts to connect, leading to the pg library's fallback TCP connection.

The problem is, I can not connect to the database, and I am unsure why.

// const dbConfig = {
//   user: 'username',
//   socketPath: '/cloudsql/test:us-west1:test-db', //  Name
//   database: 'dbname',
//   password: '',
// };
 
I have been trying to use code assist, gemini, and we tried so many different solutions we ended up going in circles with no success.
 
Does socketPath work? Is there another alterative to connect to this database? I have been trying for 2 days to establish a connection and for some reason I am failing.
 
I made sure there was no enviroment variables, and also made sure the database is in the sql connection.
 
I am completely stumped.
 
 
 

 

0 0 14
0 REPLIES 0