So, my friend says swap is an old concept and shouldn't be needed on new systems as long as you have enough RAM. But then I heard suggestions that swap might actually be required when using Postgres on Linux or even Unix because malloc
/free
will not return memory to the system. I'm told this is a feature, not a bug, and I should use swap because system will use swap for the freed memory... Is this correct or am I missing something? Can someone confirm this and maybe shed more light on it?
My setup for context:
- PGSQL config:
shared_buffers
+ (temp_buffers
+work_mem
) *max_connections
= 20 GB; - PGSQL is version 16, the server in on Ubuntu 22.
- The server has 50 GB of RAM and 0 swap. ZFS ARC is maxed out at 8 GB.
- I'm actually seeing 20 GB surpassed after a few hours.
- I see bumps in RAM usage each day. 50 GB is reached within 5-7 days (drops to 0 on PGSQL restart).
That's the context. Essentially, the question is: do I need to, or should I, have swap for a VM with Postgres server or not?
It’s actually safer to have some swap space so that when the system runs out of physical memory, it will experience a slowdown instead of immediately killing processes. In short, in modern systems, swap space acts as insurance you’ll probably never need.
A similar discussion with many arguments can be found here:
https://community.nethserver.org/t/linux-swap-needed-or-not/23655