Tuesday, September 16, 2025

Db2 LASTUSED column: What it is and how it helps in program cleanup

Recently, I was assigned a code review task where I had to validate the changes made by a colleague. The impacted elements were:

  • A COBOL-Db2 program

  • A procedure division copybook

  • A couple of DECLs

Since I was already part of the testing effort, I was familiar with these changes. Once we finalized the impacted list, a colleague raised an important question that I had overlooked.

Did you add the programs that use the procedure division copybook? They need recompilation too.

That struck me. I had completely missed including those programs in the impacted list. Unfortunately, it was already too late to officially modify the list. We quickly checked and found that only one other program was using this copybook.

The next challenge was to confirm if this program was really in use. 

After searching the job library and the Proc library, we couldn’t find a job that invoked it. But I wanted to be doubly sure. That’s when I started exploring if there was a way in Db2 to verify whether the program (or rather, its plan/package) was used recently.

That’s when I came across the LASTUSED column in the Db2 catalog tables:

  • SYSIBM.SYSPLAN

  • SYSIBM.SYSPACKAGE

When I queried the SYSIBM.SYSPACKAGE table for a few known programs, I noticed that the LASTUSED column was storing the date when the package was last executed. I confirmed this with our Db2 DBAs—and it opened up an interesting perspective.

The LASTUSED column in Db2 is similar to WhatsApp's Last Seen 😀—showing the last time it was accessed, not the details of how it was used.
The LASTUSED column records the date when the package/plan was last executed. IBM introduced this to help with package/plan cleanup—so teams can identify unused ones before freeing storage. 

How Db2 Updates LASTUSED

The LASTUSED column is defined as a DATE data type with NOT NULL and DEFAULT parameters in Db2 catalog tables (SYSIBM.SYSPACKAGE, SYSIBM.SYSPLAN). Here’s what happens under the hood:
When the package is initially created, LASTUSED is set to:
  • TIMESTAMP—Timestamp indicating when the package was created 
  • BINDTIME—Timestamp indicating when the package was last bound. 
  • LASTUSED—The last date that the package was used. 

When a package is created:

  • LASTUSED is initially set to 0001-01-01.

  • The value is updated the first time the package is allocated, i.e., when an application program that references it is executed.

A few nuances worth knowing:

  • The LASTUSED value is not always updated immediately. Sometimes there can be a delay of one or more days.
  • The following commands preserve the existing LASTUSED value:
        BIND REPLACE (of the same package version)
        REBIND
  • If a package contains only certain static SQL statements (like COMMIT or ROLLBACK), it can be used without being allocated, which means the LASTUSED column is not updated.

What LASTUSED can (and cannot) do

Useful for obsolescence decisions

  • If a package hasn’t been executed for years, the LASTUSED column gives you confidence that it might be safe to retire.

  • This is especially handy when cleaning up old programs and freeing up resources.

⚠️ Not a Replacement for Dependency-based Recompilation

  • If a copybook changes, all programs that use it must still be recompiled—regardless of their LASTUSED date.

  • LASTUSED only tells you the history of execution, not whether recompilation is required.

Key Takeaways

For me, this experience was a reminder that impact analysis is not just about identifying dependencies but also about validating real-world usage. And sometimes, a small curiosity-driven search can open up a whole new way of doing things smarter.

Closing CTA (Call to Action)

Have you used LASTUSED in your Db2 projects? Share your experience in the comments below! 

This blog post was written collaboratively with ChatGPT to refine structure and clarity.