简体   繁体   English

Google Cloud Run:无法连接到 Postgress SQL

[英]Google Cloud Run: Cant connect to Postgress SQL

I am following this tutorial to upload my existing Django project running locally on sqlite to Google Cloud Run / Postgres.我正在按照本教程将在 sqlite 上本地运行的现有 Django 项目上传到 Google Cloud Run / Postgres。

I have the cloud_sql_proxy service running and can sign into Postgres from the command line.我正在运行 cloud_sql_proxy 服务,并且可以从命令行登录 Postgres。

I am at the point of running the command我正在运行命令

python manage.py migrate

And I get the error:我得到了错误:

django.db.utils.OperationalError: connection to server on socket "/cloudsql/cgps-registration-2:us-central-1:cgps-reg-2-postgre-sql/.s.PGSQL.5432" failed: No such file or directory
        Is the server running locally and accepting connections on that socket?

The answer to that questions is Yes, the server is running locally and accepting connections because I can log in with the Postgres client:该问题的答案是肯定的,服务器在本地运行并接受连接,因为我可以使用 Postgres 客户端登录:

agerson@agersons-iMac ~ % psql "sslmode=disable dbname=postgres user=postgres hostaddr=127.0.0.1"  
Password for user postgres: 
psql (14.1, server 13.4)
Type "help" for help.

postgres=> 

I double checked the connection string in my.env file and it has the correct UN / P我仔细检查了 my.env 文件中的连接字符串,它具有正确的 UN / P

Is this scoket not getting created somehow in a previous step?这个 scoket 不是在上一步中以某种方式创建的吗?

/cloudsql/cgps-registration-2:us-central-1:cgps-reg-2-postgre-sql/.s.PGSQL.5432

It looks like there's a mismatch between what the app is looking for and how you're launching the proxy.看起来应用程序正在寻找的内容与您启动代理的方式不匹配。 The error explains the problem.该错误说明了问题。

You're launching the proxy like this with an incorrect region name (us-central):您正在使用不正确的区域名称(us-central)启动这样的代理:

cloud_sql_proxy -instances="cgps-registration-2:us-central:cgps-reg-2-postgre-sql=tcp:5432

But the app is looking for us-central-1.但该应用正在寻找 us-central-1。 Try this (omitting the =tcp:5432 to create a Unix socket):试试这个(省略=tcp:5432以创建 Unix 套接字):

cloud_sql_proxy -instances="cgps-registration-2:us-central-1:cgps-reg-2-postgre-sql

Also, side note, if you're using pg14 (looks like you're using pg13), there's currently a bug in the API that prevents a Unix socket connection.另外,请注意,如果您使用的是 pg14(看起来您正在使用 pg13),则 API 中当前存在一个错误,该错误会阻止 Unix 套接字连接。 See the tracking issue for more.有关更多信息,请参阅跟踪问题 Other versions of postgres aren't affected.其他版本的 postgres 不受影响。

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

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