zOs/SQL/GBGRX1
-- table Space und Details History / Zeitreihe
set current path oa1p;
set current application compatibility 'V11R1';
with dr (d,l) as
(
select current date, 0
from sysibm.sysDummy1
union all select d - 1 month, l+1
from dr
where l < 99 and d >= current date - 0 months
)
, d as
(
select * from dr fetch first 100 rows only
)
, t1 as
(
select rz, dbSys, dbName, name, instance, partition
from oa1p.tqz006GbGrTsSTats
where rz = 'RZ2' and dbSys = 'DBOF'
-- and dbName like 'MF%'
-- and name like 'A002%'
group by rz, dbSys, dbName, name, instance, partition
)
, t2 as
(
select d.d, t1.*, (select max(loadTs) from oa1p.tqz006GbGrTsSTats r
where t1.rz = r.rz and t1.dbSys = r.dbSys
and t1.dbName = r.dbName
and t1.name = r.name
and t1.instance = r.instance
and t1.partition = r.partition
and loadTs < timestamp(d.d + 1 day)
) loadTs
from t1, d
)
, t as
(
select d, r.*
from t2
join oa1p.tqz006GbGrTsSTats r
on t2.loadTS is not null and r.state <> 'd'
and t2.rz = r.rz
and t2.dbSys = r.dbSys
and t2.dbName = r.dbName
and t2.name = r.name
and t2.instance = r.instance
and t2.partition = r.partition
and t2.loadTs = r.loadTS
)
, g as
(
select d, rz, dbSys, dbName
, sum(value(real(nActive) * pgSize * 1024, 0)) used
, sum(value(totalRows, 0)) rows
, count(*) cnt
from t
group by d,rz, dbSys, dbName
)
, j as
(
select value(h.rz, v.rz) rz, value(h.dbSys, v.dbSys) dbSys
, value(h.dbName, v.dbName) dbName
, h.used hUsed
, v.used vUsed
, h.rows hRows
, v.rows vRows
, h.cnt hCnt
, v.cnt vCnt
from (select * from g where d = current date) h
full outer join (select * from g where d < current date) v
on h.rz = v.rz and h.dbSys = v.dbSys and h.dbName = v.dbName
)
, jg as
(
select rz, dbSys, dbName
, sum(hUsed - vUsed) diffUsed
, sum(hUsed) hUsed
, sum(vUsed) vUsed
, sum(hRows - vRows) diffRows
, sum(hRows) hRows
, sum(vRows) vRows
, sum(hCnt) hCnt
, sum(vCnt) vCnt
from j
group by grouping sets (rollup(rz, dbSys, dbName))
)
select * from jg
where hCnt + vCnt > 0
order by case when dbName is null then 0 else 1 end
, diffUsed desc