docs: update launch capacity and postgres tuning

This commit is contained in:
Codex
2026-07-01 05:15:31 +08:00
parent 1eb5a13df7
commit c73722202e
8 changed files with 131 additions and 22 deletions

View File

@@ -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 官方文档为准。当前 Codex 环境访问 `https://postgresqlco.nf/tuning-guide` 会返回 403因此落地值不直接抓取该站页面而是把它作为导航来源并以 PostgreSQL 官方文档本项目真实压测结果共同校验。
说明postgresqlco.nf 的 tuning guide 适合作为 `postgresql.conf` 参数分类和调参入口参考;具体参数语义、重启要求风险边界和版本差异仍以 PostgreSQL 官方文档为准。当前 Codex 环境直接访问 `https://postgresqlco.nf/tuning-guide` 会返回 403因此落地值不直接抓取该站页面而是把它作为导航来源并以 PostgreSQL 官方文档本项目真实压测结果和上线可观测性共同校验。
## 适用前提
@@ -45,6 +45,12 @@
| `idle_in_transaction_session_timeout` | `60s` | `60s` | 防止后台或脚本长事务占锁 |
| `statement_timeout` | `30s` | `30s` | API 请求不应长期占用数据库;导入脚本用会话级覆盖 |
| `lock_timeout` | `5s` | `5s` | 防止普通请求长时间等锁 |
| `temp_file_limit` | `4GB` | `8GB` | 给报表/导入留出空间,同时避免异常 SQL 无限落临时文件 |
| `log_temp_files` | `128MB` | `128MB` | 记录大临时文件,定位排序/哈希溢出和缺索引问题 |
| `log_checkpoints` | `on` | `on` | 记录 checkpoint便于把延迟波动和 WAL/checkpoint 压力关联起来 |
| `track_io_timing` | `on` | `on` | 压测和灰度期定位读写 I/O 耗时 |
| `track_wal_io_timing` | `on` | `on` | 定位答题、订单、导入等写入场景的 WAL I/O 压力 |
| `max_parallel_workers_per_gather` | `1` | `2` | 4 核 OLTP/API 场景避免单个查询吃掉过多并行 worker |
## 证据采集脚本
@@ -75,6 +81,8 @@ PG_TUNING_PROFILE=shared-host npm run perf:postgres:evidence -- --strict --json
- `jit=off`
- `statement_timeout``idle_in_transaction_session_timeout``lock_timeout` 不得为 0。
- `track_io_timing=on``track_wal_io_timing=on``log_checkpoints=on`
- `temp_file_limit``log_temp_files``max_parallel_workers_per_gather` 必须落在 profile 范围内。
- 所有 profile 参数必须在允许范围内。
- `pending_restart` 必须为 0。
- `pg_stat_statements` 必须可用。
@@ -122,7 +130,13 @@ where name in (
'log_min_duration_statement',
'idle_in_transaction_session_timeout',
'statement_timeout',
'lock_timeout'
'lock_timeout',
'temp_file_limit',
'log_temp_files',
'log_checkpoints',
'track_io_timing',
'track_wal_io_timing',
'max_parallel_workers_per_gather'
)
order by name;
```
@@ -154,10 +168,16 @@ alter system set log_min_duration_statement = '500ms';
alter system set idle_in_transaction_session_timeout = '60s';
alter system set statement_timeout = '30s';
alter system set lock_timeout = '5s';
alter system set temp_file_limit = '4GB';
alter system set log_temp_files = '128MB';
alter system set log_checkpoints = 'on';
alter system set track_io_timing = 'on';
alter system set track_wal_io_timing = 'on';
alter system set max_parallel_workers_per_gather = '1';
select pg_reload_conf();
```
以下参数需要重启 PostgreSQL 才会生效:`max_connections``shared_buffers``wal_buffers`。执行后用下面语句确认:
以下参数需要重启 PostgreSQL 才会生效:`max_connections``shared_buffers``wal_buffers``track_io_timing``track_wal_io_timing``log_checkpoints``log_temp_files``temp_file_limit``max_parallel_workers_per_gather` 通常可 reload但仍以后续 `pending_restart` 检查为准。执行后用下面语句确认:
```sql
select name, setting, unit, pending_restart
@@ -278,6 +298,12 @@ alter system reset log_min_duration_statement;
alter system reset idle_in_transaction_session_timeout;
alter system reset statement_timeout;
alter system reset lock_timeout;
alter system reset temp_file_limit;
alter system reset log_temp_files;
alter system reset log_checkpoints;
alter system reset track_io_timing;
alter system reset track_wal_io_timing;
alter system reset max_parallel_workers_per_gather;
select pg_reload_conf();
```