Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

postgres in container with PID 1 aggregating orphaned processes leading to restarts & recovery

未关闭
#1,349 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 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,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

docker-library/postgres 的其他 Issue

查看 docker-library/postgres 的全部 Issue

相似的 Issue

更多 Shell/Bash Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。