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)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM