2

we are running a very connection-heavy, insert-heavy postgres database (to the point that we should've done some connection pooling, but there's no time now).

when doing some troubleshooting, i was using netstat to show me how many connections there were to postgres. i would commonly see more than what i had specified in the postgres.conf file (via max_connections).

i would see 1400-1600 connections via netstat even though i had max_connections set to 1000.

anyone have any clue what is going on? how exactly can this happen?

any insight on this would be great.

okie.floyd
  • 231
  • 5
  • 17

2 Answers2

2

Is it possible that those connections were already closed? Windows for example doesn't immediately close the connection, but it changes it state to "TIME_WAITING.

So the connections show up in netsat but are actually closed.

Only those that show up as "ESTABLISHED" are "live" connections.

Btw: you can simply put a connection pooler in front of your PostgreSQL server without changing your application. pgPool (or pgBouncer) will pretend they are a real PostgreSQL server to the application and will do the pooling "behind its back"

0

Use a connectionpool. More than a 1000 connections will slow down the database significantly and even for a 1000 connections you need some $$$$$ hardware with a lot of cores and RAM. Using a connectionpool is much more efficient.

Frank Heikens
  • 117,544
  • 24
  • 142
  • 135
  • i know. fortunately, this is a serious piece of server hardware with 32GB of RAM, 16 cores, and some extra beef applied. it ships out to production next week, so we can't make any big code changes. will have to do in a version update. learned our lesson though. problem was that testing & requirements changed a bit at the end. thought we were going to be at about 150 connections. – okie.floyd Sep 03 '10 at 18:35
  • 1
    As I have already written: with pgPool or pgBouncer you don't need to change anything in your code to use the connection pool –  Sep 04 '10 at 21:57