Re: Getting OOM errors from PostgreSQL

From: Kevin Grittner <kgrittn(at)gmail(dot)com>
To: Chris Lajoie <chris(at)etriptrader(dot)com>
Cc: "pgsql-admin(at)postgresql(dot)org" <pgsql-admin(at)postgresql(dot)org>
Subject: Re: Getting OOM errors from PostgreSQL
Date: 2016-03-05 16:12:40
Message-ID: CACjxUsNYmhsMXfNfEFh7qNTr7fOYPVfxsXLWnQ4Axcjjrqn9OA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On Fri, Mar 4, 2016 at 3:23 PM, Chris Lajoie <chris(at)etriptrader(dot)com> wrote:
> In my log I have been getting errors that look like this:
> LOG: could not fork new process for connection: Cannot allocate memory
>
> This seems to only happen during periods of high activity.
> Shortly after the last one occurred I checked the free mem and got
> this:
> # free -h
> total used free shared buff/cache available
> Mem: 9.4G 737M 283M 2.1G 8.4G 6.3G
> Swap: 2.0G 8.3M 2.0G
>
> From this I see the vast majority of the 10GB of memory is being
> used by the OS cache. If I understand how it works correctly, this
> means it is basically free memory because if an application needs
> it the kernel will free some of it for use... is my understanding
> correct?

That depends. In general, this report is light on useful detail;
you might want to review this page and fill in some of the missing
info, like OS version:

https://wiki.postgresql.org/wiki/Guide_to_reporting_problems

The most important missing information can be captured by running
these shell statements:

cat /proc/sys/vm/overcommit_memory
cat /proc/sys/vm/overcommit_ratio

If overcommit_memory is 2, you will get "out of memory" when an
allocation would push allocated memory past swap space (2GB in your
case) plus the percentage of machine RAM indicated by
overcommit_ratio. Effectively, the difference between
overcommit_ratio and 100 is the percentage of RAM you are reserving
for the OS to keep things memory-resident (like buffers and cache).
A value of 20, for example, would mean that an allocation that
would reduce OS memory-resident pages below 80% of machine RAM will
trigger an "out of memory" error; so when you set
vm.overcommit_memory = 2 (which is generally a very good thing to
do when running PostgreSQL on the machine) you should raise
vm.overcommit_ratio = 80 or 90. You don't want to totally blow
away OS cache, but you probably want to survive other demands on
RAM that bring it down quite a bit.

--
Kevin Grittner
EDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Nagy László Zsolt 2016-03-06 09:13:27 How to setup a good collation?
Previous Message Chris Lajoie 2016-03-04 21:23:02 Getting OOM errors from PostgreSQL