Exposing the cgroup memory limit to SQL?

Поиск
Список
Период
Сортировка
Искать

Exposing the cgroup memory limit to SQL?

От:
Joao Detomini <joao.detomini@enterprisedb.com>
Дата:
Hi,

When Postgres runs in a container with a memory limit, the server knows 
nothing about it.  I recently posted a docs patch about how the cgroup
OOM killer behaves , and while testing that I tried the obvious
case: postgres:17 (17.11) with -m 512m and no swap, and six sessions
each sorting 3M rows with work_mem = 300MB.  One backend got SIGKILL,
the postmaster restarted everything, and all six sessions lost their
connection.  Nobody got an out-of-memory error, since the allocations
themselves succeeded.  The server had started with the usual
shared_buffers = 128MB and max_connections = 100, so nothing in it
reflected the 512MB limit.

I couldn't find any code in the tree that looks at cgroups, nor an
earlier discussion in the archives, though I may have missed one.

What I have in mind is small: a SQL function that returns the memory
limit of the cgroup the server runs in (NULL if there is none, or not
on Linux), so tools and operators don't have to parse /sys/fs/cgroup
themselves.  It would not change any defaults or behavior.

Does that seem worth having in core, or would you rather see it in
contrib or left to external tools?  I'd only look at cgroup v2 at
first.  If the idea sounds reasonable, I'm happy to write a patch.

Thanks,
João Marcelo

Re: Exposing the cgroup memory limit to SQL?

От:
Umar Hayat <postgresql.wizard@gmail.com>
Дата:
Hi,
There is the PostgreSQL wiki page "Cgroups"[1] explaining the problem
statement and also potential issues for implementation.
Seems like nobody proposed any implementation for cgroups yet

Regards
Umar Hayat

[1] https://wiki.postgresql.org/wiki/Cgroups


Re: Exposing the cgroup memory limit to SQL?

От:
Joe Conway <mail@joeconway.com>
Дата:
On 10/1/26 23:05, Umar Hayat wrote:
> Hi,
> There is the PostgreSQL wiki page "Cgroups"[1] explaining the problem
> statement and also potential issues for implementation.
> Seems like nobody proposed any implementation for cgroups yet
> 
> Regards
> Umar Hayat
> 
> [1] https://wiki.postgresql.org/wiki/Cgroups


This is not in the postgres tree, but I think it does what you are 
looking for (plus a lot more): https://github.com/pgnodemx/pgnodemx

-- 
Joe Conway
PostgreSQL Contributors Team
Amazon Web Services: https://aws.amazon.com


Re: Exposing the cgroup memory limit to SQL?

От:
Joao Detomini <joao.detomini@enterprisedb.com>
Дата:
Hi, 
Thanks, I hadn't come across pgnodemx. cgroup_scalar_bigint('memory.max') 
covers what I had in mind, so I'll drop the idea of a function in core.

Em dom., 4 de out. de 2026 às 15:58, Joe Conway <mail@joeconway.com> escreveu:
On 10/1/26 23:05, Umar Hayat wrote:
> Hi,
> There is the PostgreSQL wiki page "Cgroups"[1] explaining the problem
> statement and also potential issues for implementation.
> Seems like nobody proposed any implementation for cgroups yet
>
> Regards
> Umar Hayat
>
> [1] https://wiki.postgresql.org/wiki/Cgroups


This is not in the postgres tree, but I think it does what you are
looking for (plus a lot more): https://github.com/pgnodemx/pgnodemx

--
Joe Conway
PostgreSQL Contributors Team
Amazon Web Services: https://aws.amazon.com
FAQ