greenplum列出所有表并显示表的相关信息

列出greenplum中public下所有表,并显示最近的DDL与DML操作,以及显示表所占用空间大小以及表行数

select 
tables.*,
po.last_staactionname,
po.last_statime,
po1.first_staactionname,
po1.first_statime,
reltuples
from 
(select  
schemaname,SPLIT_PART(tablename, '_1', 1) as tablename,tableowner,tablespace,hasindexes,hasrules,hastriggers,
round(sum(pg_total_relation_size(schemaname||'.'||SPLIT_PART(tablename, '_1', 1)))/1024/1024,2) as  tablesize_KB
from pg_tables where schemaname in ('public')
 group by 1,2 ,3,4,5,6,7 order by tablesize_KB desc
)tables
left join 
(select objid,last_staactionname ,last_statime from (select objid,staactionname as last_staactionname,statime  as last_statime,
ROW_NUMBER()OVER(PARTITION by objid order by statime desc) as ind from pg_stat_last_operation where staactionname not in ('ANALYZE' ,'VACUUM','PRIVILEGE'))a where ind = 1) po
on tables.tablename::regclass = po.objid
left join
(select objid,first_staactionname ,first_statime  from (select objid,staactionname as first_staactionname,statime as first_statime,
ROW_NUMBER()OVER(PARTITION by objid order by statime) as ind from pg_stat_last_operation where staactionname not in ('ANALYZE' ,'VACUUM','PRIVILEGE'))a where ind = 1) po1
on tables.tablename::regclass = po1.objid
left join 
(SELECT SPLIT_PART(relname, '_1', 1) as relname, sum(reltuples) as reltuples
FROM pg_class r 
JOIN pg_namespace n
ON (relnamespace = n.oid)
WHERE relkind = 'r' AND n.nspname = 'public'
GROUP BY 1
)nsp 
on  tables.tablename = nsp.relname
;

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值