MagicStack / MagicStack/asyncpg
Add support for PGOPTIONS environment variable
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 8.1k
- 派生
- 468
- PR 合并指标
- 30 天内没有已合并 PR
描述
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
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从读取现有 PG 环境变量的 asyncpg/connect_utils.py 开始,并将所需行为与 PostgreSQL 的 libpq 环境变量文档进行对比。在设置 PGOPTIONS 的情况下运行提供的复现程序 test_asyncpg_timeout.py;当 PGOPTIONS 的值被解释为服务器设置,并且 statement_timeout 示例的行为与 psql 一致时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- postgresql, python
- 领域
- databases
- Issue 类型
- 功能
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 52/100