I searched a lot about how to calculate memory usage of PostgreSQL process on Linux. I read article about how to calculate Memory usage for a generic process but I think that PostgreSQL has some peculiarity. For example, it has some basic processes:logger, checkpointer, bg writer, etc. But Linux creates also a process for each client connection on the master node.
The easy way to calculate the memory usage is with ps command listing the RSS of each process:
ps -aux | grep -v grep | grep postgres | awk '{ print $6 }'
and then sum it. But this doesn't work since the result is larger than the total memory. Some articles suggest the use of:
/proc/PID/smaps
but as said above I have more PID and I am unable to find a website that shows a script that let me easily calculate this information.
I found this interesting article, but it's not clear to me how to convert it into a working script. https://www.depesz.com/2012/06/09/how-much-ram-is-postgresql-using/
Does anyone know which is the best approach to solve this issue?