If I see an entry in pg_stat_activity for a client_addr:client_port combination where there is no process bound to that port on the indicated client, what does that mean? Just that the client process exited before the query completed?

2 Answers 2


You are probably correct that this simply means that the client process exited. If it exits without cleaning up the connection while its back-end server process is working on a query, then the server process will not notice until it tries to send a message to the client and finds that no one is there.

If it takes a long time to return a tuple (because it has to sort or aggregate before it sends the first one, for example) then the server process can be a dead man walking for a long time.

There was discussion about fixing this, but finding a way to do it in a performant and cross-platform way is not easy.

  • Can a server process stay alive waiting on a lock even when the client process has exited?
    – gcbenison
    Oct 3, 2014 at 17:35
  • Yes. If you need to kill a psql session while it is waiting on a lock, do it with SIGINT or by hitting Ctrl-C from the tty. Don't kill it with SIGTERM or SIGKILL. With the first method, psql sends a cancel message to its server so it knows to cancel the lock wait.
    – jjanes
    Oct 3, 2014 at 21:55

It's hard to say given the lack of specifics here, but most likely it's just timing differences - the backend exited moments after you looked at pg_stat_activity and before you looked at ps or netstat or whatever you were using to look at it at the OS level.

pg_stat_activity gets cleaned up when the postmaster notices the child process exiting, so if the postmaster is extremely busy it might take a moment after the backend actually exits. However, you'd usually see a short-lived "zombie" process still there until the postmaster notices it. It may or may not retain its socket.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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