Postgresql – Postgres shared_buffers and pooled processes

jdbcpostgresql

I have read several articles (including Postgres docs) that suggest setting the shared_buffer's config value to 25% of your total physical memory.

Using my 4 GB memory as an example… If I understand correctly, when postgres starts up, it will request ~1 GB of physical memory from the OS. It will use this for buffering purposes. Thus, when I look at a utility like "top" I see the size/RES of the postgres process to be ~1GB.

So my question is – what happens when I have POOLED connections to Postgres? i.e. A Tomcat server which keeps N number of open, idle connections to postgres? I can see there are N number of postgress processes waiting in the background for requests from Tomcat. Each process is the same size (~1Gb). They're forks of the original process, I suppose. So does that mean Postgres as a whole is taking up N*1GB of memory?? Isn't this a bad thing to make shared_buffer this large??

Best Answer

No, it's still only 1GB of total memory.

The buffer is allocated as shared memory and it only allocated once, but shared between all server processes.

It's basically an "error" in the memory display of the top command, which simply reports the shared memory (that only exists once) for each process.