简体   繁体   English

Google App Engine Rails Postgres 无法连接到 Cloud SQL 数据库:没有这样的文件或目录

[英]Google App Engine Rails Postgres won't connect to Cloud SQL database: No such file or directory

I have a Rails app that should be hosted via Google Cloud App Engine.我有一个应该通过 Google Cloud App Engine 托管的 Rails 应用程序。 It has a Postgres database setup.它有一个 Postgres 数据库设置。 I followed this tutorial: https://cloud.google.com/ruby/rails/using-cloudsql-postgres我遵循了本教程: https://cloud.google.com/ruby/rails/using-cloudsql-postgres

I added all my configurations in app.yaml:我在 app.yaml 中添加了所有配置:

entrypoint: bundle exec rackup --port $PORT
env: flex
runtime: ruby

env_variables:
  SECRET_KEY_BASE: [SECRET_KEY]

beta_settings:
  cloud_sql_instances: [INSTANCE]

and database.yml:和database.yml:

production:
  adapter: postgresql
  encoding: unicode
  pool: 5
  timeout: 5000
  username: postgres
  password: [DB_PASSWORD]
  database: [DB_DATABASE]
  host: /cloudsql/[INSTANCE]

The Cloud SQL instance is setup correctly as I can connect to it using Cloud SQL proxy: https://cloud.google.com/sql/docs/postgres/connect-admin-proxy Cloud SQL 实例设置正确,因为我可以使用 Cloud SQL 代理连接到它: https://cloud.google-admin-proxy/sql/docs/postgre

After deployment to App Engine and trying to migrate it gives me the follwoing error:部署到 App Engine 并尝试迁移后,出现以下错误:

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/[INSTANCE]/.s.PGSQL.5432"?

This also happens with a running proxy locally and trying to这也发生在本地运行的代理并尝试

RAILS_ENV=production rake db:create rake db:migrate

I see that /cloudsql folder is missing when I SSH into the App Engine's VM.当我 SSH 进入 App Engine 的虚拟机时,我看到 /cloudsql 文件夹丢失了。 I double-checked, access rights should be there and Cloud SQL API and Cloud SQL Admin API are enabled.我仔细检查了,访问权限应该在那里,并且 Cloud SQL API 和 Cloud SQL Admin ZDB93444238D7143CADE1已启用。 I also noticed that when SSHing into the App Engine's VMs (apparently there are two, I tried both of them) and running ls the directories are completely empty.我还注意到,当通过 SSH 连接到 App Engine 的虚拟机(显然有两个,我都尝试过)并运行 ls 时,目录完全是空的。 The deployment worked though as I can access the app but not the controller that require DB connection.尽管我可以访问应用程序,但部署工作正常,但不能访问需要数据库连接的 controller。

I followed this old but better explained GCP tutorial (this tutorial is designed to use cloud shell) and I realized that is mandatory to have running Cloud SQL Proxy on your local env (in another terminal or background)我遵循了这个旧但更好解释的GCP 教程(本教程旨在使用云 shell),我意识到必须在本地环境(在另一个终端或后台)上运行 Cloud SQL 代理

Cloud sql proxy will create the unix socket file云 sql 代理将创建 unix 套接字文件

Listening on /cloudsql/tetsingfakeproject:us-central1:testdatabase ce/.s.PGSQL.5432 for tetsingfakeproject:us-central1:testdatabase

This in order to perform the migrations, and you can pass that step on the local environment.这是为了执行迁移,您可以在本地环境中传递该步骤。

Notes about using this tutorial关于使用本教程的注意事项

I followed all steps of the old tutorial with some alternative steps我按照旧教程的所有步骤进行了一些替代步骤

In the step 3, I ran the newest command to enable the SQL admin api:在第 3 步中,我运行了最新命令以启用 SQL 管理员 api:

gcloud service enable sqladmin.googleapis.com

In the step 10, I installed the pg and appengine packages using these commands instead modifying the file "Gemfile"在第 10 步中,我使用这些命令安装了 pg 和 appengine 包,而不是修改文件“Gemfile”

bundle add pg
bundle add appengine

If the deploy time of this ruby app takes more than 10 minutes, please run this command如果此 ruby 应用程序的部署时间超过 10 分钟,请运行此命令

gcloud config set app/cloud_build_timeout 3600s

And run gcloud app deploy again.并再次运行gcloud app deploy

following this tutorial I can get a functional App Engine Service using ruby + postgresql, I had a lot of issues using the other tutorial按照本教程,我可以使用 ruby + postgresql 获得功能性 App Engine 服务,我在使用其他教程时遇到了很多问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当前将Google Container Engine(GKE)上的Rails与Google Cloud SQL连接的最佳方法是什么 - What is currently the best way to connect Rails on Google Container Engine (GKE) with Google Cloud SQL 新的Rails应用程序Postgres将无法安装 - New Rails app Postgres won't install Docker Compose:Rails不会尊重DATABASE_URL连接到Postgres - Docker Compose: Rails won't respect the DATABASE_URL to connect to Postgres Postgres不会使用c9.io连接到Ruby on Rails应用程序中的服务器 - Postgres won't connect to server in Ruby on Rails app using c9.io Rails控制台将无法连接到数据库 - rails console won't connect to database 如何从Google Container Engine连接Google Cloud SQL? - How to connect Google Cloud SQL from Google Container Engine? Rails应用程序将无法连接到PostgreSQL - Rails app won't connect to PostgreSQL 在Google Cloud App Engine中托管Rails App并设置环境变量 - Host Rails App in the Google Cloud App Engine and set Environment variables 将 Rails 6 应用程序部署到 Google Cloud Platform App Engine 时出错 - Error while deploying Rails 6 app to Google Cloud Platform App Engine 无法通过Rails连接Heroku上的现有Postgres数据库 - Can't connect existing postgres database on heroku via rails
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM