我正在尝试使用此连接字符串将Cloud Run容器连接到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).
要从Cloud Run连接到Cloud SQL实例,Google会提供本指南。您可以在此处找到Python代码段。
如文档所述,PostgreSQL标准要求Unix套接字在套接字路径中具有.s.PGSQL.5432后缀。一些库会自动应用此后缀,但是其他库则要求您按以下方式指定套接字路径:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句