Rails fails to connect to google cloud sql using proxy

Viewed 1045

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?

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.

Related