Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails fails to connect to google cloud sql using proxy

I'm deploying a rails 5 app using Google Cloud SQL(postgresql) & App Engine and I am having issues with the proxy. I followed the tutorial here Ruby on Rails Cloud Sql and setup the proxy successfully.

From my local machine: psql -h "/cloudsql/[CONNECTION:NAME]" --user [USER] --password

I can see all remote databases and the connections being handled by proxy in the other window. Next I try to run rake db:migrate and get the following error.

PG::ConnectionBad: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/cloudsql/[CONNECTION:NAME]/.s.PGSQL.5432"?

Here is my database.yml

  default: &default
  adapter: postgresql
  encoding: utf8
  pool: 5
  timeout: 5000
  username: [USER]
  password: [USER:PASS]
  host: /cloudsql/[CONNECTION:NAME]

Since the proxy is working from the local machine it must be something in my rails app or pg gem. I've reinstall the PG gem with no change. How can get I get my rails app to use the proxy successfully?

like image 218
Korben Dallas Avatar asked Nov 08 '22 21:11

Korben Dallas


1 Answers

Did you activate the Cloud SQL API?

In my case I had forgotten that. Enable that one in your API console. Then it worked for me.

like image 162
Hendrik Avatar answered Nov 15 '22 06:11

Hendrik