【问题标题】:problem connecting cloud run to postgresql 11 database将云运行连接到 postgresql 11 数据库的问题
【发布时间】:2020-02-20 19:08:26
【问题描述】:

我正在尝试使用此连接字符串将我的云运行容器连接到我的 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).

【问题讨论】:

    标签: python postgresql google-cloud-platform google-cloud-run


    【解决方案1】:

    对于从 Cloud Run 连接到 Cloud SQL 实例,Google 提供了this 指南。你可以在那里找到 Python sn-p。

    如文档所述,PostgreSQL 标准要求 Unix 套接字在套接字路径中具有 .s.PGSQL.5432 后缀。一些库会自动应用此后缀,但其他库要求您指定套接字路径,如下所示:

    【讨论】:

    • 我的库自动应用它:)
    猜你喜欢
    • 1970-01-01
    • 2021-07-17
    • 2023-01-24
    • 2023-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-29
    相关资源
    最近更新 更多