set transaction\query timeout in psycopg2?

后端 未结 3 1879
甜味超标
甜味超标 2020-12-15 05:32

Is there a way to set a timeout in psycopg2 for db transactions or for db queries?

A sample use-case:
Heroku limits django web requests to 30sec

3条回答
  •  被撕碎了的回忆
    2020-12-15 05:46

    Looks like PostgreSQL 9.6 added idle transaction timeouts. See:

    • https://www.postgresql.org/docs/9.6/static/runtime-config-client.html#GUC-IDLE-IN-TRANSACTION-SESSION-TIMEOUT for reference.
    • http://blog.dbi-services.com/a-look-at-postgresql-9-6-killing-idle-transactions-automatically/ as an example.

    PostgreSQL 9.6 is also supported in Heroku so you should be able to use this.

提交回复
热议问题