绑定完请刷新页面
取消
刷新

分享好友

×
取消 复制
Greenplum分区表查询
2022-06-08 14:43:37

分区表相关数据字典和视图

pg_partition

pg_partition_rule

pg_class

pg_partition_columns 系统视图被用来显示一个分区表的分区键列;

  1. --列出所有分区表对应的分区键信息

  2. select * from pg_partition_columns;

pg_partitions 系统视图被用于显示分区表的结构;

  1. --列出所有分区表对应的子表的约束条件和分区名和分区类型等信息

  2. select * from pg_partitions;

分区表常用查询

把所有的业务表列出来(包括分区表和非分区表,但是不要子表出现)

  1. select

  2. n.nspname schemaname,

  3. c.relname tablename

  4. from

  5. pg_class c left join pg_namespace n on n.oid = c.relnamespace

  6. left join pg_partition_rule r on c.oid = r.parchildrelid

  7. where c.relkind='r'

  8. and c.relstorage in ('a','h','c')

  9. and r.parchildrelid is null --去除子表

  10. and n.nspname <> 'pg_catalog'

  11. and n.nspname <> 'information_schema'

  12. and n.nspname <> 'pg_toast' and n.nspname <> 'dba'

  13. and not n.nspname like 'pg_temp%';

找出所有有分区的业务表

  1. --方法一

  2. select parrelid::regclass from pg_partition; --只会存储父表(该表存在分区表)

  3. --方法二

  4. select

  5. n.nspname schemaname,

  6. c.relname tablename

  7. from

  8. pg_class c left join pg_namespace n on n.oid = c.relnamespace

  9. inner join pg_partition p on p.parrelid = c.oid

  10. where c.relkind='r'

  11. and c.relstorage in ('a','h','c')

  12. and n.nspname <> 'pg_catalog'

  13. and n.nspname <> 'information_schema'

  14. and n.nspname <> 'pg_toast' and n.nspname <> 'dba'

  15. and not n.nspname like 'pg_temp%';

找出所有的子表

  1. --方法一

  2. select parchildrelid::regclass from pg_partition_rule; --只会存储子表

  3. select p.parrelid::regclass,parchildrelid::regclass from pg_partition p left join pg_partition_rule r1 on p.oid=r1.paroid;

  4. --方法二

  5. select

  6. n.nspname schemaname,

  7. c.relname tablename

  8. from

  9. pg_class c left join pg_namespace n on n.oid = c.relnamespace

  10. inner join pg_partition_rule p on p.parchildrelid = c.oid

  11. where c.relkind='r'

  12. and c.relstorage in ('a','h','c')

  13. and n.nspname <> 'pg_catalog'

  14. and n.nspname <> 'information_schema'

  15. and n.nspname <> 'pg_toast' and n.nspname <> 'dba'

  16. and not n.nspname like 'pg_temp%';

找出所有有分区的表及其包含的子表名

  1. select

  2. n.nspname schemaname,

  3. c.relname tablename

  4. from

  5. pg_class c left join pg_namespace n on n.oid = c.relnamespace

  6. inner join pg_partition p on p.parrelid = c.oid

  7. UNION

  8. select

  9. n.nspname schemaname,

  10. c.relname tablename

  11. from

  12. pg_class c left join pg_namespace n on n.oid = c.relnamespace

  13. inner join pg_partition_rule q on q.parchildrelid = c.oid

  14. where c.relkind='r'

  15. and c.relstorage in ('a','h','c')

  16. and n.nspname <> 'pg_catalog'

  17. and n.nspname <> 'information_schema'

  18. and n.nspname <> 'pg_toast' and n.nspname <> 'dba'

  19. and not n.nspname like 'pg_temp%';


来源 https://www.modb.pro/db/51356

分享好友

分享这个小栈给你的朋友们,一起进步吧。

Greenplum
创建时间:2022-04-08 15:36:19
Greenplum
展开
订阅须知

• 所有用户可根据关注领域订阅专区或所有专区

• 付费订阅:虚拟交易,一经交易不退款;若特殊情况,可3日内客服咨询

• 专区发布评论属默认订阅所评论专区(除付费小栈外)

技术专家

查看更多
  • itt0918
    专家
戳我,来吐槽~