postgres in container with PID 1 aggregating orphaned processes leading to restarts & recovery
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- docker, kubernetes, postgres, shell
调研方向
从报告中的 Dockerfile 示例、docker-entrypoint.sh 命令以及链接的 dumb-init 文章开始。该 issue 未指定仓库文件或测试,因此首先确认所请求的范围是否是对镜像 entrypoint 的更改;完成应包括仓库支持的修复方案,以及验证与 probe 相关的重启不再发生。
由索引模型根据 Issue 内容生成。
描述
The postgres in docker hosted on K8S infrastructure with periodic health and rediness checks experiences regular restarts of the database.
Logs show 'postgres "server process <PID>exited with exit code 2" ' followed by restart and recovery of the database.
happening with a variety of stable postgres versions (12, 14, 16) on the same system
deployed using kubernetes, we monitor health with exec probe
livenessProbe:
exec:
command:
- pg_isready
- -U
- dmp-admin
- -d
- dmp-entity
timeoutSeconds: 1
as well as readiness probe
readinessProbe:
exec:
command:
- /bin/bash
- -c
- pg_isready -U dmp-admin -d dmp-entity && [ ! -f /var/lib/postgresql/backup/pgdump_backup.velero.sql ]
timeoutSeconds: 1
Investigation shows that the postgres db is fine - no exit 2 occurences.
Instead a regular health monitoring process that includes a /bin/bash -c pg_isready .. causes the problem.
Root cause is described here: https://www.cybertec-postgresql.com/en/docker-sudden-death-for-postgresql/ (thanks to laurentz albe)
The postgres in docker setup runs the default process (postgres) as root process of the container with PID 1.
The main postgres container is a health manager/monitor for all other spawned worker processes.
Sudden exits of worker processes lead to DB restart - remediating possible shared memory corruption.
However, orphaned other processes will get the root process as parent process (PID 1) being our postgres main entrypoint.
These processes get orphaned due to to timeout of the monitoring environment.
pg_isready is known to return exit code 2 when not able to connect.
Suggested remediation is in the referenced article: start the container using dum-init.
Example patch we deploy to remediate consists of installing the dumb-init package (using apt) and extending the entrypoint to use dumb-init as the main process (PID 1)
FROM postgres:12
RUN apt update && apt install -y dumb-init && apt clean
ENTRYPOINT ["/usr/bin/dumb-init", "docker-entrypoint.sh"]
CMD ["postgres"]
- 主要语言
- Shell
- 星标
- 2.5k
- 派生
- 1.2k
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
docker-library/postgres 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 48/100
docker-library/postgres#1420 ·
-
难度 4/5 3-5 天 新手友好度 48/100
docker-library/postgres#1419 · 2 条评论 ·
-
难度 4/5 3-5 天 新手友好度 35/100
docker-library/postgres#1389 ·
-
难度 2/5 1-3 小时 新手友好度 35/100
docker-library/postgres#1356 · 5 条评论 · 7 个 reaction ·
-
难度 4/5 3-5 天 新手友好度 25/100
docker-library/postgres#1355 · 10 条评论 · 11 个 reaction ·
查看 docker-library/postgres 的全部 Issue
相似的 Issue
-
priority middle
难度 1/5 1 小时以内 新手友好度 72/100
KATO-Hiro/AtCoderClans#12838 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
heymegabyte/install.doctor#171 ·
-
good first issue needs-triage priority: low
难度 2/5 1-3 小时 新手友好度 78/100
melodic-software/claude-code-plugins#6699 · 1 条评论 ·
维护者通常 1 天内回复
-
area:cli bug
难度 1/5 1 小时以内 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
community-scripts/ProxmoxVE#17824 ·
维护者通常 1 天内回复