在PostgreSQL中,我们如何查看当前连接或会话的用户信息呢?下面总结了几种方法:
方法1:
select * from current_user;
eg:
kerrydb=> select * from current_user; current_user -------------- test(1 row)
方法2:
select user;
eg:
kerrydb=> select user; user ------ test(1 row)kerrydb=>
方法3:
\c
此方法只适用于psql命令
eg:
kerrydb=> \cYou are now connected to database "kerrydb" as user "test".
\conninfo
eg:
postgres=# \conninfoYou are connected to database "postgres" as user "postgres" on host "127.0.0.1" at port "5432".
方法4:
current_user是the current user identifier session_user是the current session user identifier。
postgres=# SELECT session_user, current_user;
session_user | current_user
--------------+--------------
postgres | postgres
(1 row)
文章转载自DBA闲思杂想录,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




