Postgresql RAM optimization for containers and kubernetes

  containers, database, docker, kubernetes, postgresql

I wondered how to optimize the RAM usage of my PostgreSQL database deployed in Kubernetes.

Particularly I’m interested in configuring the shared_buffers and effective_cache_size values.

Typically the recommendation stated by various sources is to use:

  • If you have a system with 1GB or more of RAM, a reasonable starting value for shared_buffers is 1/4 of the memory in your system. If you have less RAM you’ll have to account more carefully for how much RAM the OS is taking up; closer to 15% is more typical there. There are some workloads where even larger settings for shared_buffers are effective, but given the way PostgreSQL also relies on the operating system cache, it’s unlikely you’ll find using more than 40% of RAM to work better than a smaller amount. (PostgreSQL Website)

  • The value should be set to 15% to 25% of the machine‚Äôs total RAM (EDB website)

  • No more than 50% of the available RAM (EDB PostgreSQL tuning)

Since containers use by design much less background RAM what would be a good recommendation for setting the shared_buffers value?

Right now the value is set to 25% (1GB of 4GB total container limit) and I notive that it get’s filled up quite quickly.

Source: Docker Questions

LEAVE A COMMENT