在使用ALTER SEQUENCE之后,如何在Postgres中查看新的序列所有权信息?

时间:2012-03-28 02:26:32

标签: postgresql postgresql-9.1 postgresql-9.2

我正在使用“ALTER SEQUENCE sequence OWNED by table.column”来改变Postgres中的序列关联。有没有办法使用\ ds或类似的东西查看这些新信息? \ ds仍然将表所有者显示为序列所有者。

2 个答案:

答案 0 :(得分:3)

OWNED BY table.column更改关联列; OWNER TO newowner更改拥有序列的角色。所有者角色是\ds中显示的内容。我不知道psql命令来查看序列的链接列。 OWNED BY主要用于在删除引用列时级联删除相关序列。

您可以通过构建针对系统目录表pg_classpg_dependpg_attribute的查询来了解所拥有的列。我不确定pg_depend的所有确切语义,但是这个查询应该显示序列的列依赖性:

select tab.relname as tabname, attr.attname as column
from pg_class as seq
join pg_depend as dep on (seq.relfilenode = dep.objid)
join pg_class as tab on (dep.refobjid = tab.relfilenode)
join pg_attribute as attr on (attr.attnum = dep.refobjsubid and attr.attrelid = dep.refobjid)
where seq.relname = 'sequence';

答案 1 :(得分:3)

SELECT c.relname,u.usename 
  FROM pg_class c, pg_user u
 WHERE c.relowner = u.usesysid and c.relkind = 'S'
   AND relnamespace IN (
                        SELECT oid
                          FROM pg_namespace
                         WHERE nspname NOT LIKE 'pg_%'
                           AND nspname != 'information_schema'
                        );