且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何通过SQL将活动用户连接到PostgreSQL数据库?

更新时间:2022-11-30 09:39:05

(问题)您没有获得该信息

(question) Don't you get that info in


pg_user ;

或使用视图 pg_stat_activity

select * from pg_stat_activity;

已添加:

视图显示:


每个服务器进程一行,显示数据库OID,数据库名称,进程ID,用户OID,用户名,当前查询,查询的等待状态,当前查询开始执行的时间,进程开始的时间以及客户端的地址和端口号。除非已关闭参数stats_command_string,否则将显示报告当前查询数据的列。此外,只有在检查视图的用户是超级用户或与拥有正在报告该过程的用户的用户相同时,这些列才可见。

One row per server process, showing database OID, database name, process ID, user OID, user name, current query, query's waiting status, time at which the current query began execution, time at which the process was started, and client's address and port number. The columns that report data on the current query are available unless the parameter stats_command_string has been turned off. Furthermore, these columns are only visible if the user examining the view is a superuser or the same as the user owning the process being reported on.

您无法过滤并获取该信息吗?那将是数据库的当前用户,例如,您可以使用开始执行时间来获取最近5分钟内的所有查询...

can't you filter and get that information? that will be the current users on the Database, you can use began execution time to get all queries from last 5 minutes for example...

类似的东西。