我正在尝试使用此连接字符串将云运行容器连接到PostgreSQL 11数据库
postgresql+psycopg2://username:password@/db?host=/cloudsql/project-name:region:dbinstance
当我尝试运行我的容器时,它会返回这个错误
2019-10-24 13:30:53.910 CEST sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not connect to server: Connection refused
2019-10-24 13:30:53.910 CEST Is the server running locally and accepting
2019-10-24 13:30:53.910 CEST connections on Unix domain socket "/cloudsql/project-name:region:dbinstance/.s.PGSQL.5432"?
2019-10-24 13:30:53.910 CEST(Background on this error at: http://sqlalche.me/e/e3q8)
我还尝试使用这个连接字符串
postgresql+psycopg2://username:password@/db?unix_socket=/cloudsql/project-name:region:dbinstance
返回此错误消息的
2019-10-24 11:11:43.733 CESTsqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) invalid dsn: invalid connection option "unix_socket"
2019-10-24 11:11:43.733 CEST(Background on this error at: http://sqlalche.me/e/f405)
2019-10-24 11:11:44.469 CESTContainer called exit(1).
发布于 2019-10-24 20:38:33
对于从Cloud Run连接到Cloud SQL实例,谷歌有this指南。您可以在那里找到Python代码片段。
正如文档所述,PostgreSQL标准要求Unix套接字在套接字路径中具有.s.PGSQL.5432后缀。有些库会自动应用此后缀,但其他库则要求您按如下方式指定套接字路径:
https://stackoverflow.com/questions/58541431
复制相似问题