{"id":2093,"date":"2016-05-25T10:49:53","date_gmt":"2016-05-25T10:49:53","guid":{"rendered":"http:\/\/hostileblog.com\/?p=2093"},"modified":"2020-11-03T10:57:19","modified_gmt":"2020-11-03T15:57:19","slug":"oom-killer-out-of-memory-error-linux","status":"publish","type":"post","link":"https:\/\/www.carnaghan.com\/oom-killer-out-of-memory-error-linux\/","title":{"rendered":"The OOM Killer : How to Fix Out of Memory Error in Linux?"},"content":{"rendered":"

Since two weeks, my website was frequently crashing because the MySQL server stopped<\/a> abruptly at random times of the day.<\/p>\n

This issue started when I was on a holiday. My site was down for several hours. I configured crontab to start MySQL server when the service had stopped. This didn’t help.<\/p>\n

I enabled query cache to reduce the load on the server. I use NGINX Fast CGI cache, APCu, and OpCache for my sites. Thus, I didn’t felt the need to install a caching plugin<\/a> for my WordPress blog.<\/p>\n

I reinstalled WordPress, changed DB structure of WordPress Database<\/a> tables from MyISAM to INNODB, but the MySQL service was still crashing. I checked error logs and found that the MySQL server stopped each time the PHP executed the code in the wp-db.php file.<\/p>\n

To seek help, I created a new thread on WordPress forum. One of the users asked me to check system log files (messages, Syslog) which can be found under the \/var\/log directory. The messages log file was populated with the below message:<\/p>\n

out of memory in UB 815792: OOM killed process 29747 (MySQLD) error messages.<\/code><\/p>\n

The out of memory manager module in my Linux VPS<\/a> was killing the MySQL service immediately after the crontab started it.<\/p>\n

\"OOM<\/p>\n

OOM is a system module which ensures that aggressive processes using high system resources are killed to avoid malfunctioning of the system. In my case, the MySQLD service was using a large volume of RAM due to which the OOM killer had no other option than killing MySQLD process.<\/p>\n

To fix the problem, I stopped MySQL server along with the services dependent on it. Then, I rebooted the VPS.<\/p>\n

What should you do to prevent OOM process killer from stopping MySQL, PHP-FPM, NGINX, Apache, Oracle DB<\/strong> or any other critical service?<\/p>\n

Check Linux memory<\/strong> usage often with commands like ps aux and <\/code>free -mt<\/code>. Once you find that the server doesn’t have enough free memory, identify the process which is using the most RAM and check its configuration. For example, if the PHP-FPM processes are using a large amount of RAM, you should tweak its configuration to lower the system memory usage.<\/p>\n

Kill stopped jobs<\/strong>: When you stop a job in Linux, the task is still assigned resources the system had allocated to it. To free up these resources, you should terminate all finished jobs. To do so, run the below command in the terminal:<\/p>\n

jobs -ps<\/code><\/p>\n

Now, the terminal will display a list of process ids of stopped jobs. Use kill -9 pid<\/code> command to kill them.<\/p>\n

Check log files<\/strong>: If your website is deployed on a VPS server, you should check PHP, Nginx, MySQL as well as system log files every 2 or 3 hours. Use the command tail -30 file_name<\/code> to learn about the latest errors.<\/p>\n

Use updated software<\/strong>: When a developer or a company releases a new version of a product, the bugs that were found in earlier version of the software would have been fixed. If you’re using a CMS, make sure that the software you’re about to upgrade is compatible with your CMS.<\/p>\n

If this doesn’t help, lower the max connections default value in my.cnf file to 50. Configure the PHP-FPM process manager to create additional processes ondemand and reduce the value of max children variable.<\/p>\n

Conclusion<\/strong>: Fixing out of memory errors in Linux can be tricky. You should first find the cause of the problem by checking the error log files. If the problem is occurring because of poor code or slow SQL query, you should fix the code. If the code works great on other machines, reboot the OS.<\/p>\n","protected":false},"excerpt":{"rendered":"

Since two weeks, my website was frequently crashing because the MySQL server stopped abruptly at random times of the day. This issue started when I was on a holiday. My site was down for several hours. I configured crontab to start MySQL server when the service had stopped. This didn’t help. I enabled query cache to […]<\/p>\n","protected":false},"author":11,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24],"tags":[11413,7020,7032,7036],"post_series":[],"yoast_head":"\nThe OOM Killer : How to Fix Out of Memory Error in Linux? - Ian Carnaghan<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.carnaghan.com\/oom-killer-out-of-memory-error-linux\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"The OOM Killer : How to Fix Out of Memory Error in Linux? - Ian Carnaghan\" \/>\n<meta property=\"og:description\" content=\"Since two weeks, my website was frequently crashing because the MySQL server stopped abruptly at random times of the day. This issue started when I was on a holiday. My site was down for several hours. I configured crontab to start MySQL server when the service had stopped. This didn’t help. I enabled query cache to […]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.carnaghan.com\/oom-killer-out-of-memory-error-linux\/\" \/>\n<meta property=\"og:site_name\" content=\"Ian Carnaghan\" \/>\n<meta property=\"article:published_time\" content=\"2016-05-25T10:49:53+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-11-03T15:57:19+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.carnaghan.com\/wp-content\/uploads\/2016\/05\/OOM-killer-1.jpg\" \/>\n<meta name=\"author\" content=\"Pramod\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@icarnaghan\" \/>\n<meta name=\"twitter:site\" content=\"@icarnaghan\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Pramod\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.carnaghan.com\/oom-killer-out-of-memory-error-linux\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.carnaghan.com\/oom-killer-out-of-memory-error-linux\/\"},\"author\":{\"name\":\"Pramod\",\"@id\":\"https:\/\/www.carnaghan.com\/#\/schema\/person\/f52a97a0d4f7b309922ab0381d337bbb\"},\"headline\":\"The OOM Killer : How to Fix Out of Memory Error in Linux?\",\"datePublished\":\"2016-05-25T10:49:53+00:00\",\"dateModified\":\"2020-11-03T15:57:19+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.carnaghan.com\/oom-killer-out-of-memory-error-linux\/\"},\"wordCount\":597,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.carnaghan.com\/#\/schema\/person\/c689c24d516c51968a88b628860740a5\"},\"image\":{\"@id\":\"https:\/\/www.carnaghan.com\/oom-killer-out-of-memory-error-linux\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/www.carnaghan.com\/wp-content\/uploads\/2016\/05\/OOM-killer-1.jpg\",\"keywords\":[\"Affiliate\",\"Errors\",\"Linux\",\"MySQL\"],\"articleSection\":[\"Coding\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.carnaghan.com\/oom-killer-out-of-memory-error-linux\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.carnaghan.com\/oom-killer-out-of-memory-error-linux\/\",\"url\":\"https:\/\/www.carnaghan.com\/oom-killer-out-of-memory-error-linux\/\",\"name\":\"The OOM Killer : How to Fix Out of Memory Error in Linux? - Ian Carnaghan\",\"isPartOf\":{\"@id\":\"https:\/\/www.carnaghan.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.carnaghan.com\/oom-killer-out-of-memory-error-linux\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.carnaghan.com\/oom-killer-out-of-memory-error-linux\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/www.carnaghan.com\/wp-content\/uploads\/2016\/05\/OOM-killer-1.jpg\",\"datePublished\":\"2016-05-25T10:49:53+00:00\",\"dateModified\":\"2020-11-03T15:57:19+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.carnaghan.com\/oom-killer-out-of-memory-error-linux\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.carnaghan.com\/oom-killer-out-of-memory-error-linux\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.carnaghan.com\/oom-killer-out-of-memory-error-linux\/#primaryimage\",\"url\":\"https:\/\/www.carnaghan.com\/wp-content\/uploads\/2016\/05\/OOM-killer-1.jpg\",\"contentUrl\":\"https:\/\/www.carnaghan.com\/wp-content\/uploads\/2016\/05\/OOM-killer-1.jpg\",\"width\":620,\"height\":311,\"caption\":\"OOM killer fix out of memory error in linux vps\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.carnaghan.com\/oom-killer-out-of-memory-error-linux\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.carnaghan.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"The OOM Killer : How to Fix Out of Memory Error in Linux?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.carnaghan.com\/#website\",\"url\":\"https:\/\/www.carnaghan.com\/\",\"name\":\"Ian Carnaghan\",\"description\":\"Software Developer, Blogger, Educator\",\"publisher\":{\"@id\":\"https:\/\/www.carnaghan.com\/#\/schema\/person\/c689c24d516c51968a88b628860740a5\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.carnaghan.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.carnaghan.com\/#\/schema\/person\/c689c24d516c51968a88b628860740a5\",\"name\":\"Ian Carnaghan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.carnaghan.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f2aa5baca80c2be728de43a975185d91?s=96&d=retro&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/f2aa5baca80c2be728de43a975185d91?s=96&d=retro&r=g\",\"caption\":\"Ian Carnaghan\"},\"logo\":{\"@id\":\"https:\/\/www.carnaghan.com\/#\/schema\/person\/image\/\"},\"description\":\"I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment.\",\"sameAs\":[\"http:\/\/www.carnaghan.com\",\"https:\/\/x.com\/icarnaghan\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.carnaghan.com\/#\/schema\/person\/f52a97a0d4f7b309922ab0381d337bbb\",\"name\":\"Pramod\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.carnaghan.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/9b9cc255f2495f5394b801428d7d6929?s=96&d=retro&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/9b9cc255f2495f5394b801428d7d6929?s=96&d=retro&r=g\",\"caption\":\"Pramod\"},\"description\":\"My name is Pramod. I\u2019m a software developer (with good knowledge on PHP, JAVA \u2013 Android, JavaScript, CSS), blogger and online marketing professional. I\u2019ve 3 years of experience as a blogger and 2 years of full time experience as a software developer.\",\"url\":\"https:\/\/www.carnaghan.com\/author\/prhost78\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"The OOM Killer : How to Fix Out of Memory Error in Linux? - Ian Carnaghan","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.carnaghan.com\/oom-killer-out-of-memory-error-linux\/","og_locale":"en_US","og_type":"article","og_title":"The OOM Killer : How to Fix Out of Memory Error in Linux? - Ian Carnaghan","og_description":"Since two weeks, my website was frequently crashing because the MySQL server stopped abruptly at random times of the day. This issue started when I was on a holiday. My site was down for several hours. I configured crontab to start MySQL server when the service had stopped. This didn’t help. I enabled query cache to […]","og_url":"https:\/\/www.carnaghan.com\/oom-killer-out-of-memory-error-linux\/","og_site_name":"Ian Carnaghan","article_published_time":"2016-05-25T10:49:53+00:00","article_modified_time":"2020-11-03T15:57:19+00:00","og_image":[{"url":"http:\/\/www.carnaghan.com\/wp-content\/uploads\/2016\/05\/OOM-killer-1.jpg"}],"author":"Pramod","twitter_card":"summary_large_image","twitter_creator":"@icarnaghan","twitter_site":"@icarnaghan","twitter_misc":{"Written by":"Pramod","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.carnaghan.com\/oom-killer-out-of-memory-error-linux\/#article","isPartOf":{"@id":"https:\/\/www.carnaghan.com\/oom-killer-out-of-memory-error-linux\/"},"author":{"name":"Pramod","@id":"https:\/\/www.carnaghan.com\/#\/schema\/person\/f52a97a0d4f7b309922ab0381d337bbb"},"headline":"The OOM Killer : How to Fix Out of Memory Error in Linux?","datePublished":"2016-05-25T10:49:53+00:00","dateModified":"2020-11-03T15:57:19+00:00","mainEntityOfPage":{"@id":"https:\/\/www.carnaghan.com\/oom-killer-out-of-memory-error-linux\/"},"wordCount":597,"commentCount":0,"publisher":{"@id":"https:\/\/www.carnaghan.com\/#\/schema\/person\/c689c24d516c51968a88b628860740a5"},"image":{"@id":"https:\/\/www.carnaghan.com\/oom-killer-out-of-memory-error-linux\/#primaryimage"},"thumbnailUrl":"http:\/\/www.carnaghan.com\/wp-content\/uploads\/2016\/05\/OOM-killer-1.jpg","keywords":["Affiliate","Errors","Linux","MySQL"],"articleSection":["Coding"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.carnaghan.com\/oom-killer-out-of-memory-error-linux\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.carnaghan.com\/oom-killer-out-of-memory-error-linux\/","url":"https:\/\/www.carnaghan.com\/oom-killer-out-of-memory-error-linux\/","name":"The OOM Killer : How to Fix Out of Memory Error in Linux? - Ian Carnaghan","isPartOf":{"@id":"https:\/\/www.carnaghan.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.carnaghan.com\/oom-killer-out-of-memory-error-linux\/#primaryimage"},"image":{"@id":"https:\/\/www.carnaghan.com\/oom-killer-out-of-memory-error-linux\/#primaryimage"},"thumbnailUrl":"http:\/\/www.carnaghan.com\/wp-content\/uploads\/2016\/05\/OOM-killer-1.jpg","datePublished":"2016-05-25T10:49:53+00:00","dateModified":"2020-11-03T15:57:19+00:00","breadcrumb":{"@id":"https:\/\/www.carnaghan.com\/oom-killer-out-of-memory-error-linux\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.carnaghan.com\/oom-killer-out-of-memory-error-linux\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.carnaghan.com\/oom-killer-out-of-memory-error-linux\/#primaryimage","url":"https:\/\/www.carnaghan.com\/wp-content\/uploads\/2016\/05\/OOM-killer-1.jpg","contentUrl":"https:\/\/www.carnaghan.com\/wp-content\/uploads\/2016\/05\/OOM-killer-1.jpg","width":620,"height":311,"caption":"OOM killer fix out of memory error in linux vps"},{"@type":"BreadcrumbList","@id":"https:\/\/www.carnaghan.com\/oom-killer-out-of-memory-error-linux\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.carnaghan.com\/"},{"@type":"ListItem","position":2,"name":"The OOM Killer : How to Fix Out of Memory Error in Linux?"}]},{"@type":"WebSite","@id":"https:\/\/www.carnaghan.com\/#website","url":"https:\/\/www.carnaghan.com\/","name":"Ian Carnaghan","description":"Software Developer, Blogger, Educator","publisher":{"@id":"https:\/\/www.carnaghan.com\/#\/schema\/person\/c689c24d516c51968a88b628860740a5"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.carnaghan.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.carnaghan.com\/#\/schema\/person\/c689c24d516c51968a88b628860740a5","name":"Ian Carnaghan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.carnaghan.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/f2aa5baca80c2be728de43a975185d91?s=96&d=retro&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f2aa5baca80c2be728de43a975185d91?s=96&d=retro&r=g","caption":"Ian Carnaghan"},"logo":{"@id":"https:\/\/www.carnaghan.com\/#\/schema\/person\/image\/"},"description":"I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment.","sameAs":["http:\/\/www.carnaghan.com","https:\/\/x.com\/icarnaghan"]},{"@type":"Person","@id":"https:\/\/www.carnaghan.com\/#\/schema\/person\/f52a97a0d4f7b309922ab0381d337bbb","name":"Pramod","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.carnaghan.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/9b9cc255f2495f5394b801428d7d6929?s=96&d=retro&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9b9cc255f2495f5394b801428d7d6929?s=96&d=retro&r=g","caption":"Pramod"},"description":"My name is Pramod. I\u2019m a software developer (with good knowledge on PHP, JAVA \u2013 Android, JavaScript, CSS), blogger and online marketing professional. I\u2019ve 3 years of experience as a blogger and 2 years of full time experience as a software developer.","url":"https:\/\/www.carnaghan.com\/author\/prhost78\/"}]}},"views":6342,"_links":{"self":[{"href":"https:\/\/www.carnaghan.com\/wp-json\/wp\/v2\/posts\/2093"}],"collection":[{"href":"https:\/\/www.carnaghan.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.carnaghan.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.carnaghan.com\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/www.carnaghan.com\/wp-json\/wp\/v2\/comments?post=2093"}],"version-history":[{"count":0,"href":"https:\/\/www.carnaghan.com\/wp-json\/wp\/v2\/posts\/2093\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.carnaghan.com\/wp-json\/wp\/v2\/media?parent=2093"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.carnaghan.com\/wp-json\/wp\/v2\/categories?post=2093"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.carnaghan.com\/wp-json\/wp\/v2\/tags?post=2093"},{"taxonomy":"post_series","embeddable":true,"href":"https:\/\/www.carnaghan.com\/wp-json\/wp\/v2\/post_series?post=2093"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}