본문 바로가기

Qlik Sense 개발가이드

Qlik Sense 에서 AWS RDS for PostgreSQL Table Size 시각화

SonarTableSize:
Load *;
select a.table_schema schema_nm, a.table_enm table_enm
     , sum(a.table_size_byte) table_size_byte
     , sum(a.total_size_byte) total_size_byte
     , max(b.last_upd_dtm) last_upd_dtm
  from
  (select table_schema, table_enm_pt, table_size, total_size, table_enm
    , case
      when position(' bytes' in table_size) - 1 > 0
      then cast(substr(table_size, 1, position(' bytes' in table_size) - 1) as numeric)
      when position(' kB'    in table_size) - 1 > 0
      then cast(substr(table_size, 1, position(' kB'    in table_size) - 1) as numeric) * 1024
      when position(' MB'    in table_size) - 1 > 0
      then cast(substr(table_size, 1, position(' MB'    in table_size) - 1) as numeric) * 1024 * 1024
      when position(' GB'    in table_size) - 1 > 0
      then cast(substr(table_size, 1, position(' GB'    in table_size) - 1) as numeric) * 1024 * 1024 * 1024
      when position(' TB'    in table_size) - 1 > 0
      then cast(substr(table_size, 1, position(' TB'    in table_size) - 1) as numeric) * 1024 * 1024 * 1024 * 1024
      end  table_size_byte
    , case
      when position(' bytes' in total_size) - 1 > 0
      then cast(substr(total_size, 1, position(' bytes' in total_size) - 1) as numeric)
      when position(' kB'    in total_size) - 1 > 0
      then cast(substr(total_size, 1, position(' kB'    in total_size) - 1) as numeric) * 1024
      when position(' MB'    in total_size) - 1 > 0
      then cast(substr(total_size, 1, position(' MB'    in total_size) - 1) as numeric) * 1024 * 1024
      when position(' GB'    in total_size) - 1 > 0
      then cast(substr(total_size, 1, position(' GB'    in total_size) - 1) as numeric) * 1024 * 1024 * 1024
      when position(' TB'    in total_size) - 1 > 0
      then cast(substr(total_size, 1, position(' TB'    in total_size) - 1) as numeric) * 1024 * 1024 * 1024 * 1024
      end  total_size_byte
 from
(select nspname table_schema
     , relname as table_enm_pt
     , pg_size_pretty(pg_relation_size(c.oid))       as table_size
     , pg_size_pretty(pg_total_relation_size(c.oid)) as total_size
     , case
   when position('_20' in relname)     - 1 > 0
   then substr(relname, 1, position('_20' in relname)     - 1)
   when position('_others' in relname) - 1 > 0
   then substr(relname, 1, position('_others' in relname) - 1)
   else relname
       end  table_enm
  from pg_class c
       left join pg_namespace n
       on n.oid = c.relnamespace
 where 1=1
    --and relname like 'hddpi_cgo_wtl%'
    and c.relkind <> 'i'
    and nspname !~ '^pg_toast') a ) a
left join
(select schema_nm, table_enm
  , max(etl_end_dtm) last_upd_dtm
from cmmdb.etl_job_log
  group by schema_nm, table_enm) b
on  b.schema_nm = a.table_schema
and b.table_enm = a.table_enm
 where 1=1
   and a.table_schema not in ('cron','hint_plan','information_schema','pg_catalog','public')
   and a.table_enm not like 'v\_%'
   --and table_enm = 'hddpi_cgo_wtl'
 group by a.table_schema, a.table_enm
 order by table_size_byte desc
;

// created by Yang

 

시각화 결과