IBM MQ - Purge messages in a queue using clear queue

by
Jeremy Canfield |
Updated: September 29 2021
| IBM MQ articles
Before using the clear queue command to remove all of the messages in a queue, you may want to use the display queue command to display the number of messages in the queue.
echo "display queue (QUEUE01) CURDEPTH" | runmqsc MANAGER01
In this example, the current depth of queue01 is 10.
QUEUE(queue01) TYPE(QLOCAL)
CURDEPTH(10)
The clear queue command can be used to remove all of the messages in the queue.
echo "clear qlocal (QUEUE01)" | runmqsc MANAGER01
If AMQ8148E: IBM MQ object in use is returned, the messages will not be cleared. In this scenario, you can try using the amqsget command to get the messages off the queue.
AMQ8148E: IBM MQ object in use.
One MQSC command read.
No commands have a syntax error.
One valid MQSC command could not be processed.
If the queue is successfully cleared, something like this should be displayed.
AMQ8022I: IBM MQ queue cleared.
One MQSC command read.
No commands have a syntax error.
All valid MQSC commands were processed.
Reissuing the display queue command should show that the current depth of the queue is now 0.
QUEUE(queue01) TYPE(QLOCAL)
CURDEPTH(0)
Did you find this article helpful?
If so, consider buying me a coffee over at