简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM