Skip to content

Commit 5209675

Browse files
committed
initial wrapper
0 parents  commit 5209675

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM percona/percona-postgresql-operator:2.6.0-ppg16.8-postgres
2+
3+
# Create a custom entrypoint script that sets OOM score and starts postgres
4+
COPY entrypoint-wrapper.sh /usr/local/bin/
5+
RUN chmod +x /usr/local/bin/entrypoint-wrapper.sh
6+
7+
# We don't change the original ENTRYPOINT - we wrap around it
8+
ENTRYPOINT ["/usr/local/bin/entrypoint-wrapper.sh"]

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# OOM-Protected PostgreSQL Docker Image
2+
3+
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.
4+
5+
## Features
6+
7+
- Sets OOM score adjustment to `-900` for the Patroni process (which manages PostgreSQL)
8+
9+
## How It Works
10+
11+
This image works with the Percona PostgreSQL Operator architecture:
12+
13+
1. Patroni is the process manager that starts and manages PostgreSQL
14+
2. Our wrapper script sets the OOM score adjustment to -1000 for the Patroni process
15+
3. This adjustment is inherited by PostgreSQL processes, protecting them from OOM killer
16+
4. Custom PostgreSQL configuration is provided to optimize memory usage
17+
5. The wrapper script preserves the original entrypoint behavior of the parent image
18+
19+
## Usage
20+
21+
### Basic Usage
22+
23+
```bash
24+
docker build -t oom-protected-postgres .
25+
docker run -d --name postgres oom-protected-postgres
26+
```
27+
28+
## References
29+
30+
- [PostgreSQL documentation on kernel resources](https://www.postgresql.org/docs/current/kernel-resources.html)
31+
- [Percona blog on Out-of-Memory killer](https://www.percona.com/blog/out-of-memory-killer-or-savior/)
32+
- [Docker Hub: percona/percona-postgresql-operator](https://hub.docker.com/r/percona/percona-postgresql-operator)
33+
- [Patroni documentation](https://patroni.readthedocs.io/)

entrypoint-wrapper.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# For Percona PostgreSQL Operator, Patroni is the process manager
5+
# The OOM score adjustment needs to be applied to Patroni process
6+
# which will then be inherited by the PostgreSQL process
7+
8+
# Set OOM score adjustment to -1000 for the current process (Patroni)
9+
# This ensures both Patroni and PostgreSQL processes are killed last by the OOM killer
10+
if [ -f "/proc/self/oom_score_adj" ]; then
11+
echo -900 > /proc/self/oom_score_adj
12+
echo "Set OOM score adjustment to -1000 for Patroni process"
13+
else
14+
echo "WARNING: Cannot set OOM score adjustment (file not found)"
15+
fi
16+
17+
exec "$@"

0 commit comments

Comments
 (0)