Skip to content

Instantly share code, notes, and snippets.

@forstie
Created December 4, 2020 18:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save forstie/b611c7bf921512ff15c56879899953ba to your computer and use it in GitHub Desktop.
Save forstie/b611c7bf921512ff15c56879899953ba to your computer and use it in GitHub Desktop.
For this gist, I was asked to provide a query that would find jobs that have been stuck on Message Wait (MSGW) status for > 90 minutes. There's a 3 part progression to reach the solution.
--
-- Find active jobs (in QBATCH) that are in message wait status
--
with msgw_jobs (jn) as (
select job_name
from table (
qsys2.active_job_info(subsystem_list_filter => 'QBATCH')
) x
where job_status = 'MSGW'
)
select *
from msgw_jobs;
stop;
--
-- Find active jobs (in QBATCH) that are in message wait status, and find the message that they're waiting on
--
with msgw_jobs (jn) as (
select job_name
from table (
qsys2.active_job_info(subsystem_list_filter => 'QBATCH')
) x
where job_status = 'MSGW'
)
select from_job as job, from_user as user_name,
message_timestamp, message_id, message_type, message_text,
severity, message_key
from msgw_jobs, lateral (select * from qsys2.message_queue_info a
where from_job = jn
order by message_timestamp asc
limit 1);
stop;
--
-- Find active jobs (in QBATCH) that are in message wait status, and find the message that they're waiting on
-- note: Only return those jobs that have been waiting on a response for > 90 minutes
--
with msgw_jobs (jn) as (
select job_name
from table (
qsys2.active_job_info(subsystem_list_filter => 'QBATCH')
) x
where job_status = 'MSGW'
)
select from_job as job, from_user as user_name,
message_timestamp, message_id, message_type, message_text,
severity, message_key
from msgw_jobs, lateral (select * from qsys2.message_queue_info a
where from_job = jn
order by message_timestamp asc
limit 1)
where message_timestamp < current timestamp - 90 minutes;
@carlosir
Copy link

carlosir commented Dec 4, 2020

Thanks Scott
It is in my Scott’s tool now
Have a great weekend

@AjaykulkarniIBMi
Copy link

Cool tool, Scott, you continue to make life easy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment