Find Large Objects on my IBM i System – Use SQL to find those FAT LIBRARIES

  • Home
  • /
  • Blog
  • /
  • Find Large Objects on my IBM i System – Use SQL to find those FAT LIBRARIES

February 24, 2026

Welcome back to another dieting adventure in IBM-i land. Ever wondered why your IBM i disk space is disappearing faster than expected? Those fat libraries are usually the culprits. Follow my Fat Stuff Blogs on how to use SQL to find the large objects on our IBM-i systems.

Here is a quick and practical lesson on using SQL to find large objects and spot the biggest space hogs on your system.

Fire up Run SQL Scripts in ACS or the terminal in Code for IBM i and try these two statements. They are simple, fast to run, and super effective.

1. Total size of the USER data system (excluding Operating System)

This query gives you the grand total of all storage used by every object on your IBM i, shown in bytes:

with LibrarySizes as (
  select OBJLIB, count(*) as OBJ_CNT, sum(OBJSIZE) as LIB_SIZE
    from table (QSYS2.OBJECT_STATISTICS('*ALLUSR', '*ALL')) as X
    group by OBJLIB
)
select 
    count(*) as TOTAL_LIBRARIES,
    sum(OBJ_CNT) as TOTAL_OBJECTS,
    sum(LIB_SIZE) as TOTAL_SIZE
  from LibrarySizes

Run it once and you will know exactly how much space your whole system is consuming.

2. List all these libraries in descending order

This one groups everything by library, counts the objects, and sorts by size so the fattest libraries appear first:

select OBJLIB as LIBRARY_NAME,
       count(*) as OBJECT_COUNT,
       sum(OBJSIZE) as LIBRARY_SIZE
  from table (
      QSYS2.OBJECT_STATISTICS('*ALLUSR', '*ALL')
    ) as X
  group by OBJLIB
  order by LIBRARY_SIZE desc

You will instantly see which libraries are eating the most space. On a large system these queries scan a lot of objects, so they can take some time. Obviously run this when the machine is not at peak busy time.

If you just want the top 20 fattest libraries, add this line at the end:

FETCH FIRST 20 ROWS ONLY;

Run these regularly as part of your housekeeping routine and you will keep your IBM i running lean and fast.

That is all there is to it!

NickLitten


IBM i Software Developer, Digital Dad, AS400 Anarchist, RPG Modernizer, Shameless Trekkie, Belligerent Nerd, Englishman Abroad and Passionate Eater of Cheese and Biscuits.

Nick Litten Dot Com is a mixture of blog posts that can be sometimes serious, frequently playful and probably down-right pointless all in the space of a day.

Enjoy your stay, feel free to comment and remember: If at first you don't succeed then skydiving probably isn't a hobby you should look into.

Nick Litten

related posts:

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Subscribe NOW
7-day free trial

Take This Course with ALL ACCESS

Unlock your Learning Potential with instant access to every course and all new courses as they are released.
 [ For Serious Software Developers only ]

Online Learning for IBM i Software Technology Professionals

“The more that you read, the more things you will know. The more that you learn, the more places you’ll go.” – Dr. Seuss

>