要查看所有用戶,您可以使用以下SQL查詢:
SELECT u.usename AS username,
u.usesysid AS user_id,
u.usecreatedb AS create_database,
u.usesuper AS is_superuser,
ARRAY(SELECT n.nspname
FROM pg_catalog.pg_namespace n
WHERE n.nspowner = u.usesysid) AS user_schemas,
pg_catalog.array_to_string(u.valuntil, ' ') AS password_expiration
FROM pg_catalog.pg_user u
ORDER BY 1;
這將返回所有用戶的用戶名、用戶ID、是否具有創建數據庫權限、是否是超級用戶、用戶擁有的模式以及密碼過期信息。