Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 702466 - dev-db/postgresql - prevent getting killed when OOM
Summary: dev-db/postgresql - prevent getting killed when OOM
Status: UNCONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: PgSQL Bugs
URL:
Whiteboard:
Keywords: PATCH
Depends on:
Blocks:
 
Reported: 2019-12-10 14:51 UTC by Vanni Della Ricca
Modified: 2019-12-10 21:01 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
patch to init script (postgres.init.patch,455 bytes, patch)
2019-12-10 14:53 UTC, Vanni Della Ricca
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Vanni Della Ricca 2019-12-10 14:51:12 UTC
Hi.
If an system is going down to ram postgresql is often an good candidate to be killed by oom-killer. 
Posgresql documentation (https://www.postgresql.org/docs/11/kernel-resources.html#LINUX-MEMORY-OVERCOMMIT) provide some tricks to prevents that postmaster process will be killed, making the database inconsistent and taking a long time to starting up.
In gentoo linux startup file (openrc) there aren't a point to adjust oom_score_adj for postmaster but is possible set PG_OOM_ADJUST_FILE and PG_OOM_ADJUST_VALUE in PG_EXTRA_ENV for correcting child process in /etc/conf.d/postgres-X.
An idea must be create a new variable in /etc/conf.d/postgres-X (eg. PG_MASTER_OOM_ADJUST="-1000") and using it in init scrpit:

if [ ${PG_MASTER_OOM_ADJUST} ] ; then
  echo ${PG_MASTER_OOM_ADJUST} > /proc/self/oom_score_adj
fi

before process start, complete patch will be attached.
Many thanks

Reproducible: Always
Comment 1 Vanni Della Ricca 2019-12-10 14:53:13 UTC
Created attachment 599060 [details, diff]
patch to init script

this patch require var PG_MASTER_OOM_ADJUST will be setting in /etc/conf.d/postgres-X
Comment 2 Jeroen Roovers (RETIRED) gentoo-dev 2019-12-10 17:01:23 UTC
Comment on attachment 599060 [details, diff]
patch to init script

>--- postgresql-11-20191210	2019-12-10 16:53:39.000000000 +0100
>+++ postgresql-11	2019-12-10 17:40:02.000000000 +0100
>@@ -86,6 +86,9 @@
> 
>     rm -f "${DATA_DIR%/}/postmaster.pid"
> 
>+    if [ ${PG_MASTER_OOM_ADJUST} ] ; then
>+	echo ${PG_MASTER_OOM_ADJUST} > /proc/self/oom_score_adj

That doesn't prevent the process getting killed; it would merely decrease the likelihood of killing it in favour of killing other processes first.
Comment 3 Vanni Della Ricca 2019-12-10 17:11:35 UTC
(In reply to Jeroen Roovers from comment #2)
> Comment on attachment 599060 [details, diff] [details, diff]
> patch to init script
> 
> >--- postgresql-11-20191210	2019-12-10 16:53:39.000000000 +0100
> >+++ postgresql-11	2019-12-10 17:40:02.000000000 +0100
> >@@ -86,6 +86,9 @@
> > 
> >     rm -f "${DATA_DIR%/}/postmaster.pid"
> > 
> >+    if [ ${PG_MASTER_OOM_ADJUST} ] ; then
> >+	echo ${PG_MASTER_OOM_ADJUST} > /proc/self/oom_score_adj
> 
> That doesn't prevent the process getting killed; it would merely decrease
> the likelihood of killing it in favour of killing other processes first.

Of courese, I've used an incorrect term.