linux:查找 postgres 空闲进程发起者
实际上,我正在运行四个守护程序。它建立 postgres 连接,并在完成后断开连接。但是当我输入 ps aux 时,我的系统中有很多 postgres 空闲进程正在运行。我只是想知道,每个空闲帖子进程的发起者。这样,我就可以找出哪个进程没有正确关闭 postgres 连接。
提前致谢 。
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 .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用以下命令
它将显示 postgres 连接器创建者的进程 ID 和进程名称。
Use following command
It will show the process id and process name of postgres connector creator.
如果您使用的是 postgresql 9.0,请在连接时设置“应用程序名称”属性,以便您可以区分每个服务器进程正在与哪个客户端进程通信。例如(Perl):
这将在应用程序名称中包含客户端 PID,这虽然丑陋但有效。
如果您通过 TCP/IP 连接,则
pg_stat_activity
包含客户端端口,您可以将其与lsof
(或netstat -p
)一起使用来查找客户端进程。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):
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 withlsof
(ornetstat -p
) to find the client process.请参阅你怎么能让活动用户通过 SQL 连接到 postgreSQL 数据库?
可以获取连接进程的 pid 和 uid
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