diff --git a/docker-compose.yml b/docker-compose.yml index 4bdd7fde..d5d0acc7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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} diff --git a/docker/compose.env.example b/docker/compose.env.example index 6824b379..8e3ea749 100644 --- a/docker/compose.env.example +++ b/docker/compose.env.example @@ -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