Обсуждение: Invoke OOM killer

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

Invoke OOM killer

От
kaido vaikla
Дата:
Hi, 

How to invoke OOM killer for pg process?
Some easy "hack" for test purpose.

OS
Rocky Linux release 9.2 (Blue Onyx)
pg
15.2

br
Kaido


Re: Invoke OOM killer

От
Ron
Дата:
On 7/6/23 11:27, kaido vaikla wrote:
Hi, 

How to invoke OOM killer for pg process?
Some easy "hack" for test purpose.

OS
Rocky Linux release 9.2 (Blue Onyx)
pg
15.2

https://www.percona.com/blog/out-of-memory-killer-or-savior/

I'd run "wapoff -a", set vm.overcommit_memory=2, and then run a simple C program that mallocs a lot of memory, mlocks it and then fills it with FF bits.

--
Born in Arizona, moved to Babylonia.

Re: Invoke OOM killer

От
Joe Conway
Дата:
On 7/6/23 12:27, kaido vaikla wrote:
> Hi,
> 
> How to invoke OOM killer for pg process?
> Some easy "hack" for test purpose.
> 
> OS
> Rocky Linux release 9.2 (Blue Onyx)
> pg
> 15.2

If you are running postgres under systemd, you can add a cgroup memory 
limit to the unit file. Something like (depending on cgroup version and 
systemd version the params might be slightly different -- cannot 
remember off the top of my head):
-------
MemoryAccounting=yes
MemoryMax=256M
-------
Don't forget to
-------
systemctl daemon-reload
systemctl restart postgresql@15
#or whatever version
-------


That will cause an OOM killer strike at 256M of total cgroup usage (all 
of the postgres processes combined).

 From there it is pretty easy to trigger by doing something like, e.g.
-------
-- attempt to create a ~500M string
select repeat('X', 500000000);
-------


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




Re: Invoke OOM killer

От
Jeff Janes
Дата:
On Thu, Jul 6, 2023 at 12:27 PM kaido vaikla <kaido.vaikla@gmail.com> wrote:
Hi, 

How to invoke OOM killer for pg process?
Some easy "hack" for test purpose.

For most purposes, you can just pick a backend process ID, and send it a `kill -9`.  From the PostgreSQL perspective, that is just what the OOM killer does. 

If it needs to happen 'naturally', you could do something like:

set work_mem=50GB;
select * from generate_series(1,100000000) order by random();

Where the numbers may need to be adjusted based on your RAM.

Cheers,

Jeff