PostgreSQL查看当前用户

 

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=> c
You are now connected to database "kerrydb" as user "test".

 

conninfo

 

eg

postgres=# conninfo
You are connected to database "postgres" as user "postgres" on host "127.0.0.1" at port "5432".

 

 

 

方法4

 

 

current_userthe current user identifier

session_userthe current session user identifier

 

postgres=# SELECT session_user, current_user;
 session_user | current_user 
--------------+--------------
 postgres     | postgres
(1 row)
扫描上面二维码关注我
如果你真心觉得文章写得不错,而且对你有所帮助,那就不妨帮忙“推荐"一下,您的“推荐”和”打赏“将是我最大的写作动力!
本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接.
原文地址:https://www.cnblogs.com/kerrycode/p/14918021.html