Re: [GENERAL] Running out of memory the hard way ... - Mailing list pgsql-general

From Bill Moran
Subject Re: [GENERAL] Running out of memory the hard way ...
Date
Msg-id 20170209093309.ac3d36c76e637b2001ae015e@potentialtech.com
Whole thread Raw
In response to Re: [GENERAL] Running out of memory the hard way ...  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: [GENERAL] Running out of memory the hard way ...  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
On Wed, 08 Feb 2017 10:44:24 -0500
Tom Lane <tgl@sss.pgh.pa.us> wrote:

> Albe Laurenz <laurenz.albe@wien.gv.at> writes:
> > Bill Moran wrote:
> >> What I feel is the best way to mitigate the situation, is to have some
> >> setting that limits the maximum RAM any backend can consume.
>
> > I'd delegate that problem to the operating system which, after all,
> > should know best of all how much memory a process uses.
>
> I've had some success using ulimit in the past, although it does have
> the disadvantage that you have to impose the same limit on every PG
> process.  (You set it before starting the postmaster and it inherits
> to every child process.)  If memory serves, limiting with the -v switch
> works better than -d or -m on Linux; but I might be misremembering.
> Conceivably we could add code to let the ulimit be set per-process,
> if the use-case were strong enough.

Thanks, Tom. I'm not sure why I didn't think to use this. Although part
of the problem may be that most of the links that come up from a google
search on this topic don't seem to have this suggestion.

Hopefully having this in the list archives will make the search easier
for the next person who has this issue. Does anyone know if there are
any suggestions to this effect in the official documentation? If not,
I'll try to make some time to submit a patch.

> To implement a limit inside PG, we'd have to add expensive bookkeeping
> to the palloc/pfree mechanism, and even that would be no panacea because
> it would fail to account for memory allocated directly from malloc.
> Hence, you could be pretty certain that it would be wildly inaccurate
> for sessions using third-party code such as PostGIS or Python.  An
> OS-enforced limit definitely sounds better from here.

Unfortunate but understandable.

--
Bill Moran <wmoran@potentialtech.com>


pgsql-general by date:

Previous
From: Thomas Güttler
Date:
Subject: Re: [GENERAL] PostgreSQL on eMMC - Corrupt file system
Next
From: Benoit Lobréau
Date:
Subject: Re: [GENERAL] clarification about standby promotion