给定角色名称someone
,如何使用子句
COMMENT ON ROLE someone IS 'THIS IS A ROLE COMMENT';
答案 0 :(得分:7)
查找如何检索此类信息的一种好方法是检查psql
的帮助并找到显示此信息的命令。
在这种情况下,它是dg+
命令。
一旦知道该命令,就可以启用psql
工具的内部SQL查询打印,以了解它如何检索该信息。这是通过使用psql
参数启动-E
来完成的。
如果你这样做,你会看到:
psql (9.4.5)
Type "help" for help.
postgres=# \dg+
********* QUERY **********
SELECT r.rolname, r.rolsuper, r.rolinherit,
r.rolcreaterole, r.rolcreatedb, r.rolcanlogin,
r.rolconnlimit, r.rolvaliduntil,
ARRAY(SELECT b.rolname
FROM pg_catalog.pg_auth_members m
JOIN pg_catalog.pg_roles b ON (m.roleid = b.oid)
WHERE m.member = r.oid) as memberof
, pg_catalog.shobj_description(r.oid, 'pg_authid') AS description
, r.rolreplication
FROM pg_catalog.pg_roles r
ORDER BY 1;
**************************
List of roles
Role name | Attributes | Member of | Description
---------------+-----------------------------------+-----------+-----------------------
someone | | {} | THIS IS A ROLE COMMENT
从你的问题中不清楚你是否只想要一些方法来查看评论,那么dg+
就足够了。否则,您可以根据需要调整psql
使用的SQL查询,例如:
SELECT pg_catalog.shobj_description(r.oid, 'pg_authid') AS description
FROM pg_catalog.pg_roles r
where r.rolname = 'someone';
答案 1 :(得分:3)
角色在群集中的所有数据库上共享。有关这些共享对象的注释包含在pg_shdescription
系统目录中。你可以得到像这样的角色的评论:
SELECT rolname, description AS comment
FROM pg_roles r
JOIN pg_shdescription c ON c.objoid = r.oid;
答案 2 :(得分:0)
简化接受的答案的查询:
select r.rolname, psd.description
from pg_catalog.pg_shdescription psd
inner join pg_roles r ON r.oid = psd.objoid
inner join pg_class c ON c.relname = 'pg_authid'
inner join pg_namespace n ON n.oid = c.relnamespace AND n.nspname = 'pg_catalog';
答案 3 :(得分:0)
大致使用psql
的{{1}}输出:
\du+
您可以在\du+ someone
Role name | Attributes | Member of | Description
-----------+-------------------------------+-----------+------------------------
someone | Password valid until infinity | {} | THIS IS A ROLE COMMENT
列中阅读评论。