在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_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)
掃描上面二維碼關注我
如果你真心覺得文章寫得不錯,而且對你有所幫助,那就不妨幫忙“推薦"一下,您的“推薦”和”打賞“將是我最大的寫作動力!
本文著作權歸作者所有,歡迎轉載,但未經作者同意必須保留此段宣告,且在文章頁面明顯位置給出原文連接.
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/308511.html
標籤:PostgreSQL
