This Docker image extends percona/percona-postgresql-operator:2.6.0-ppg16.8-postgres
with configurations to reduce the chances of PostgreSQL being killed by the Out-of-Memory (OOM) killer in Linux.
- Sets OOM score adjustment to
-900
for the PostgreSQL postmaster process - Uses a root-to-user approach to ensure proper privileges for OOM adjustment
- Intelligently identifies and protects the PostgreSQL postmaster process
- Preserves the original container entrypoint and behavior
- Multi-architecture support (amd64/x86_64 and arm64/aarch64)
This image uses a focused approach to OOM protection specifically targeting the PostgreSQL postmaster process:
- The container temporarily runs as root to gain necessary privileges
- Our wrapper script sets the initial OOM score adjustment to -900
- A background monitor continuously identifies and adjusts the PostgreSQL postmaster process
- The script exports PG_OOM environment variables for child process handling
- The wrapper script executes the original entrypoint with the original user (UID 26)
This approach ensures that the PostgreSQL postmaster process (the main database process) is the last process to be killed by the Linux OOM killer if memory becomes scarce.
The wrapper script uses multiple methods to identify the PostgreSQL postmaster process:
- Pattern matching for
postgres -D /pgdata/pg
- Parent-child relationship detection for postgres processes
- Fallback to single postgres process detection
All actions are logged to /tmp/postgres-oom-adjuster.log
for transparency and debugging.
docker build -t oom-protected-postgres .
docker run -d --name postgres oom-protected-postgres
This repository includes a GitHub Action that automatically builds and pushes the Docker image to GitHub Container Registry (ghcr.io) whenever changes are pushed to the main branch.
The workflow:
- Builds the Docker image for multiple architectures (amd64 and arm64)
- Tags it with:
latest
tag- Short SHA of the commit (e.g.,
sha-a1b2c3d
) - Date in YYYYMMDD format
- Pushes it to GitHub Container Registry as a multi-architecture manifest
Once built, you can pull the image directly, and Docker will automatically select the right architecture for your system:
docker pull ghcr.io/[your-username]/mpg-postgres-image/oom-protected-postgres:latest