HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Prevent mysql process being killed by OOM killer

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
killerpreventprocessoombeingmysqlkilled

Problem

I need to protect mysql process so that it won't be killed when system runs out of memory, we have a bunch of adhoc job run on the server from time to time, so I would prefer the adhoc jobs being killed rather than mysql.

I know I can adjust the oom_score_adj, by setting it to -1000, I can exclude it from OOM killer's consideration. But I am not sure if I need to restart the mysql process for new oom_score_adj to take effect? Does adjust the oom_score_adj for a running process still takes effect?

I was following this post and nobody else mentioned about restarting the server for new oom_score_adj to take effect:
https://blog.rimuhosting.com/2015/12/11/dont-let-the-oom-killer-stop-mysql/

Another dumb question is that I can't seem to write to the oom_score_adj file, always getting the permission denied. The oom_score_adj is not owned by root, I have tried a couple of options but keep getting the permission issue:

echo "echo '-100' > /proc/5653/oom_score_adj" | sudo -u {file_owner} sh


Appreciated for any help!

Solution

RHEL7 uses systemd.
Using the OOMScoreAdjust as follows:

sudo systemctl edit mysqld.service


Note: I'm not sure of the exact service name

Add the following text:

[Service]
OOMScoreAdjust=-1000


restart with:

systemctl restart mysqld.service


Check by looking at the score:

cat /proc/$(pidof mysqld)/oom_score_adj

Code Snippets

sudo systemctl edit mysqld.service
[Service]
OOMScoreAdjust=-1000
systemctl restart mysqld.service
cat /proc/$(pidof mysqld)/oom_score_adj

Context

StackExchange Database Administrators Q#256631, answer score: 9

Revisions (0)

No revisions yet.