The library total:
SELECT OBJECT_COUNT, LIBRARY_SIZE / 1024 / 1024 AS MB, LIBRARY_SIZE_COMPLETE
FROM TABLE(QSYS2.LIBRARY_INFO('PRODLIB'))
LIBRARY_SIZE is in bytes and includes the objects and the library itself; above a billion
bytes it is rounded. If LIBRARY_SIZE_COMPLETE is NO, some objects were left out because
they were locked or you have no authority to them. IBM warns that on a library with many
objects the calculation can take time.
But the total is of little use: what matters is who is taking the space.
SELECT OBJNAME, OBJTYPE,
OBJSIZE / 1024 / 1024 AS MB,
LAST_USED_TIMESTAMP
FROM TABLE(QSYS2.OBJECT_STATISTICS('PRODLIB', '*ALL'))
ORDER BY OBJSIZE DESC
FETCH FIRST 20 ROWS ONLY
The largest libraries on the system, when you do not know where to start:
SELECT L.OBJNAME AS LIBRARY, I.LIBRARY_SIZE / 1024 / 1024 AS MB
FROM TABLE(QSYS2.OBJECT_STATISTICS('QSYS', '*LIB')) L,
TABLE(QSYS2.LIBRARY_INFO(L.OBJNAME)) I
ORDER BY I.LIBRARY_SIZE DESC
FETCH FIRST 20 ROWS ONLY
It computes the size of every library on the system, so it is slow: run it when you have the
time. Sorting libraries by the OBJSIZE of OBJECT_STATISTICS does not help, because that is
the size of the library object, not of its contents.
Example: the library that grows and nobody knows why
Knowing that PRODLIB takes 40 GB says nothing. Knowing it took 28 six months ago, and which objects took the 12 GB difference, says everything.
One snapshot a month, in a table created from the query itself:
CREATE TABLE MYLIB/SIZEHIST AS (
SELECT CURRENT DATE AS TAKEN_AT, OBJNAME, OBJTYPE, OBJSIZE
FROM TABLE(QSYS2.OBJECT_STATISTICS('PRODLIB', '*ALL'))
) WITH NO DATA
Then the comparison between two snapshots, which is the query that earns its keep:
SELECT o.OBJNAME, o.OBJTYPE,
n.OBJSIZE - o.OBJSIZE AS GROWTH
FROM MYLIB/SIZEHIST o
JOIN MYLIB/SIZEHIST n
ON n.OBJNAME = o.OBJNAME AND n.OBJTYPE = o.OBJTYPE
WHERE o.TAKEN_AT = '2026-02-01'
AND n.TAKEN_AT = '2026-08-01'
ORDER BY GROWTH DESC
FETCH FIRST 20 ROWS ONLY
The answer may be, for instance, an application log file nobody empties, or a work table that was meant to be temporary.
Tip
LAST_USED_TIMESTAMP together with size is the pair that actually helps. A large
object used yesterday stays; a large one unused for three years is the first candidate.
Releases. OBJECT_STATISTICS and LIBRARY_INFO are in IBM's 7.5 documentation. If either
answers SQL0204 on an older release, a library's total also comes from RTVLIBD, of which
LIBRARY_INFO is the SQL equivalent.
Comments
No comments yet. Be the first to comment!
You need an account to comment. Log in · Sign up