要查看所有用户,您可以使用以下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、是否具有创建数据库权限、是否是超级用户、用户拥有的模式以及密码过期信息。