PostgreSQL Correlation Between “max_connections” and “numbackends”

max-connectionspostgresqlpostgresql-9.4

I'm trying to figure out why the field numbackends in pg_stat_database never goes above 16 (and often stays the same even after a restart).

I have max_connections set to 100 and max_locks_per_transaction set to 64. shared_buffers is set to 128MB.

We are in the process of separating the database off the same server as the application, so obviously there's some resource contention going on, but is there any other property or field I should be looking at?

Running PostgreSQL 9.4 on RHEL 6.

I also just cleared the memory cache, and the printout from free -h shows 16G used, 15G free, 139M shared, 39 buffers, and 7.6 cached.

Any help would be greatly appreciated.

Best Answer

max_connections is the upper limit for the number of database connections to all databases in the PostgreSQL cluster.

numbackends is the number of backends connected to a certain database.

The only connection between these numbers is that the former must be greater or equal than the latter.

It seems like you don't have more than 16 connections to the database. This is not a sign to worry; I would take it as an indication that your connection pool is working.

Remark: shared_buffers is very likely set way too low, which will harm performance.