3

Actually , I am running four daemon program. It makes postgres connection, and it disconnects once through with the stuffs. But When I am putting ps aux , there are lot of postgres idle process being run in my system. I just want to know , originator of the each idle postres process. So, that I could find out which process does not close postgres connection properly.

Thanks in Advance .

Pavunkumar
  • 5,147
  • 14
  • 43
  • 69

3 Answers3

4

Use following command

netstat -ntp

It will show the process id and process name of postgres connector creator.

WarrenFaith
  • 57,492
  • 25
  • 134
  • 150
Pavunkumar
  • 5,147
  • 14
  • 43
  • 69
2

If you are using postgresql 9.0, set the "application name" property when you connect so that you can distinguish which client process each server process is talking to. For example (Perl):

$dbh = DBI->connect("dbi:Pg:application_name=test/$$", undef, undef)

This will include the client PID in the application name, which is ugly but effective.

If you are connecting over TCP/IP, then pg_stat_activity includes the client port which you can use with lsof (or netstat -p) to find the client process.

araqnid
  • 127,052
  • 24
  • 157
  • 134
0

See How can you get the active users connected to a postgreSQL database via SQL?

that can get the pid and uid of the connected processes

Community
  • 1
  • 1
Dan D.
  • 73,243
  • 15
  • 104
  • 123
  • I think , table shows me the process id of the postres, not the originator of the postgres process id. – Pavunkumar Nov 30 '10 at 12:34
  • http://stackoverflow.com/questions/464623/how-can-you-get-the-active-users-connected-to-a-postgresql-database-via-sql/464629#464629 seems to say what your asking for – Dan D. Nov 30 '10 at 12:37