【问题标题】:Specify `statement_timeout` in Postgresql with sqlalchemy?使用 sqlalchemy 在 Postgresql 中指定“statement_timeout”?
【发布时间】:2018-01-04 23:08:49
【问题描述】:

以下 statement_timeout 选项适用于某些 Postgresql 数据库和其他数据库,我得到 Unsupported startup parameter: options。为什么?

这可能是 Postgres 9.4 和 9.6 之间的区别吗?这适用于前者的服务器,而后者则失败。

from sqlalchemy import create_engine

# As is: Unsupported startup parameter: options
db_engine = create_engine("postgresql://user:pw@host/database",
    connect_args={"options": "-c statement_timeout=1000"})

with db_engine.connect() as db_connection:
    print("got it")

具体来说,我得到:

sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) ERROR:  Unsupported startup parameter: options

【问题讨论】:

  • psycopg2 2.7.1,SQLAlchemy 1.1.11,postgres 服务器 9.6.3。这似乎适用于运行 postgres 9.4.1 的另一台服务器,但问题可能不是 postgres 版本差异。

标签: postgresql sqlalchemy psycopg2


【解决方案1】:

您可能已经通过 PgBouncer 连接到这些数据库。

如果是这样,请将ignore_startup_parameters = options 添加到[pgbouncer] 部分下的pgbouncer.ini。

来自https://www.pgbouncer.org/config.html#ignore_startup_parameters

默认情况下,PgBouncer 只允许它在启动数据包中跟踪的参数:client_encodingdatestyletimezonestandard_conforming_strings。所有其他参数都会引发错误。要允许其他参数,可以在此处指定,以便 PgBouncer 知道它们是由管理员处理的,它可以忽略它们。

默认:空

参考资料:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-19
    • 1970-01-01
    • 2022-08-04
    • 2015-01-16
    • 2015-05-07
    • 2019-06-03
    • 1970-01-01
    • 2011-02-10
    相关资源
    最近更新 更多