chore: gate production postgres tuning and taro handoff

This commit is contained in:
Codex
2026-07-01 04:27:19 +08:00
parent 6bdb2a175a
commit 69b4d3b62d
14 changed files with 702 additions and 44 deletions

View File

@@ -1,6 +1,6 @@
# PostgreSQL 4 核 16G 生产调参基线
更新时间2026-06-30
更新时间2026-07-01
这份文档用于后续把 Supabase/PostgreSQL 自托管到 4 核 16G 云服务器时做生产起步配置。目标是先给题库 SaaS 一个安全、可回滚、可观测的基线,而不是追求一次性压满硬件。
@@ -12,7 +12,7 @@
- PostgreSQL 官方 WAL/Checkpointhttps://www.postgresql.org/docs/current/runtime-config-wal.html
- PostgreSQL 官方 Connectionshttps://www.postgresql.org/docs/current/runtime-config-connection.html
说明postgresqlco.nf 的页面可作为参数分类和调参入口参考;具体参数语义、重启要求和风险以 PostgreSQL 官方文档为准。
说明postgresqlco.nf 的页面可作为参数分类和调参入口参考;具体参数语义、重启要求和风险以 PostgreSQL 官方文档为准。当前 Codex 环境访问 `https://postgresqlco.nf/tuning-guide` 会返回 403因此落地值不直接抓取该站页面而是把它作为导航来源并以 PostgreSQL 官方文档和本项目真实压测结果共同校验。
## 适用前提
@@ -65,6 +65,26 @@ npm run perf:postgres:evidence
上云后建议顺序是:先采集一次默认值,应用本文件 shared-host 参数并重启需要重启的项,再采集一次,然后跑 API 阶梯压测。调参证据和压测报告一起进入本地 `production-launch-evidence.json`,不要提交真实证据文件。
生产上线门禁使用严格模式:
```bash
PG_TUNING_PROFILE=shared-host npm run perf:postgres:evidence -- --strict --json
```
严格模式会按 `scripts/lib/postgres-tuning-profile.js` 检查 4 核 16G profile
- `jit=off`
- `statement_timeout``idle_in_transaction_session_timeout``lock_timeout` 不得为 0。
- 所有 profile 参数必须在允许范围内。
- `pending_restart` 必须为 0。
- `pg_stat_statements` 必须可用。
如果 PostgreSQL 是独立数据库主机,可改用:
```bash
PG_TUNING_PROFILE=dedicated-db npm run perf:postgres:evidence -- --strict --json
```
## 应用连接池边界
4 核机器的关键不是把 `max_connections` 拉大,而是控制同时活跃 SQL 的数量。
@@ -107,7 +127,13 @@ where name in (
order by name;
```
同机部署推荐先执行:
同机部署推荐先生成 SQL 后人工复核再执行:
```bash
npm run perf:postgres:sql -- --profile=shared-host
```
等价的 shared-host 起步 SQL 如下:
```sql
alter system set max_connections = '80';