Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

For some reason postgres is spawning >700 postmaster processes for handling database requests and the postgres log file if full of 'unexpected EOF on client connection', 'incomplete startup packet' and 'sorry, too many clients already'. netstat tells me that all the open connections are local and I'm pretty sure are coming from postgres internally. This particular instance has been running just fine for the last 230 days or so and nothing has changed configuration wise. Any thoughts on where I should be looking to try and resolve this issue?

This is my first time diagnosing a problem like this so if there is any steps I can take to help narrow down the cause that would be helpful as well.

UPDATE: Turns out there was an instance of tomcat running on a remote machine that was trying to connect to postgres through a ssh tunnel causing all hell to break loose.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Postgres spawns a postmaster for every connection. This is the way it's supposed to work. If you're spawning a ton of postmaster processes you have something initiating a ton of connections, and if that's not what you expect you probably have a broken/badly-behaved application creating a mess (a common example: One that keeps re-initializing the DB connection, but never closes it. You'll leak a session for every connection initialization).

If this is recent, start with "What Changed?" If not, start looking at all your apps that talk to Postgres (roughly in order of usage volume) and see if you can find the bad apple.

Re: your log messages --

  • unexpected EOF on client connection
    Something caused an established Postgres connection to die without properly closing (the postmaster may hang around for a while cleaning up the resulting mess). Find out what caused the connection to die (did the process initiating it crash? Is the application poorly-written and exiting before cleaning up its DB handles?) and fix it

  • incomplete startup packet
    Something connected to Postgres and didn't initiate a proper Postgres handshake/startup. Usually the resulting postmaster goes away in a few seconds.
    Find what's doing this and fix it. (This could be your monitoring system, someone port-scanning your network, or a badly written application somewhere)

  • sorry, too many clients already
    I think this one is self-explanatory. Fix the above and it will probably go away, otherwise consider increasing max_connections in postgresql.conf.
share|improve this answer
1  
For anyone else coming here, something to think about if you're hitting client limits: Rather than increasing max_connections, consider putting a connection pool in place. You can often get better performance by lowering max_connections and using a pool. Pools can be inside your app or appserver (common for Tomcat, Java EE servers, etc) or between your app and the Pg server (common for PHP/Apache, Rails, etc). A popular intermediary pool is PgBouncer. See The Pg Wiki. –  Craig Ringer Aug 6 '12 at 8:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.