chore(deploy): tune postgres memory parameters and limit (CACHE-2)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
rootandClaude Opus 5.5 committed 2026-09-29 17:16:50 +08:00
1 parent 05b163ce32
commit 71d2cd70cf
2 files changed
+29

No files matched your search

+21
View File
@@ -19,6 +19,27 @@ services:
postgres:
image: postgres:16-alpine
restart: unless-stopped
# 内存参数按 4C/8G 机器给 PG 3G 设定(CACHE-2);机器不同按 docs/runbook/storage.md「PG 参数」调整,
# 改 .env 里的 PG_* 后 docker compose up -d postgres 重建生效
command:
- postgres
- -c
- shared_buffers=${PG_SHARED_BUFFERS:-2GB}
- -c
- effective_cache_size=${PG_EFFECTIVE_CACHE_SIZE:-5GB}
- -c
- work_mem=${PG_WORK_MEM:-32MB}
- -c
- maintenance_work_mem=${PG_MAINTENANCE_WORK_MEM:-256MB}
- -c
- max_wal_size=${PG_MAX_WAL_SIZE:-2GB}
mem_limit: ${PG_MEM_LIMIT:-3g}
deploy:
resources:
limits:
memory: ${PG_MEM_LIMIT:-3g}
# 并行查询的动态共享内存走 /dev/shm,Docker 缺省 64MB 不够
shm_size: 512mb
environment:
POSTGRES_USER: umt
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?请设置 POSTGRES_PASSWORD}
+8
View File
@@ -17,6 +17,14 @@ PGID=10001
# 备份保留份数(0 = 不轮转)
BACKUP_KEEP=14
# PG 内存(缺省按 4C/8G 给 PG 3G;调整方法见 docs/runbook/storage.md「PG 参数」)
# PG_MEM_LIMIT=3g
# PG_SHARED_BUFFERS=2GB
# PG_EFFECTIVE_CACHE_SIZE=5GB
# PG_WORK_MEM=32MB
# PG_MAINTENANCE_WORK_MEM=256MB
# PG_MAX_WAL_SIZE=2GB
LOG_LEVEL=info
# APP_VERSION=v0.1.0
# 国内网络构建换源(可选):APT_MIRROR=mirrors.ustc.edu.cn