Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Add support for PGOPTIONS environment variable

未关闭
#1,070 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
52/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
postgresql, python
领域
databases

调研方向

从读取现有 PG 环境变量的 asyncpg/connect_utils.py 开始,并将所需行为与 PostgreSQL 的 libpq 环境变量文档进行对比。在设置 PGOPTIONS 的情况下运行提供的复现程序 test_asyncpg_timeout.py;当 PGOPTIONS 的值被解释为服务器设置,并且 statement_timeout 示例的行为与 psql 一致时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

asyncpg supports an explicit server_options=... dict connection method parameter, but does not seem to populate its value from the PGOPTIONS environment variable. This is a feature request for it to do so.

Specifically, asyncpg/connect_utils.py reads user, host, port, database, password, and SSL information with calls like os.getenv('PGUSER'), os.environ.get('PGHOST'), etc. There is no corresponding call for reading PGOPTIONS.

I would like to set the environment variable PGOPTIONS='-c default_transaction_read_only=on -c statement_timeout=120s' and have asyncpg interpret its values as server_settings the way libpq does. For instance, the below works for psql:

PGOPTIONS='-c statement_timeout=1s' psql -c "SELECT pg_sleep(2)"
ERROR:  canceling statement due to statement timeout

but a simple asyncpg script running the same ignores the statement_timeout since it never reads the value of PGOPTIONS.

$ PGOPTIONS='-c statement_timeout=1s' ./test_asyncpg_timeout.py 
SELECT 1

https://www.postgresql.org/docs/current/libpq-envars.html

主要语言
Python
星标
8.1k
派生
469
平均合并
4 天 1 小时
30 天内合并 PR
14

环境准备

我们还没有检查这个项目的环境配置文件。先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

MagicStack/asyncpg 的其他 Issue

查看 MagicStack/asyncpg 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。