Removing old or non-used messages from queues in large or test MQ environments is a real problem for admins.
Especially, when the number of queues reaches hundreds and thousands. The best way to solve this problem is use dmpmqmsg utility (aka qload, MO03 SupportPac) and write shell script. Qload is now (from MQ v8) part of the product, renamed to dmpmqmsg.
Here is dmpmqmsg utility usage instructions and simple examples:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
mqm@testmqserv1:~ $ dmpmqmsg 5724-H72 (C) Copyright IBM Corp. 1994, 2016. IBM MQ Queue Load/Unload Utility Usage: dmpmqmsg <Optional flags as below> [-a <File access mode for fopen()> a Append b Binary [-b <initial buffer size in Kb>] [-c Connect in client mode] [-C [A][I][a][i][d][n] Context] A Set all context (default) I Set identity context a Pass all context i Pass identity context d Default context n No context [-d <Display Options>] a Add ASCII columns to HEX file A Write output file in ASCII lines rather than HEX c Output ApplData MQMD fields as char C Display Correlation Id in summary H Don't write file header i Write message index p Write output file in printable characters format s Display queue summary M Display Message Ids in summary N Don't write MQMD to file t Write output file in text lines T Display time on queue w<Length> Data width [-D <Delay>] +ve fixed delay in milliseconds -ve random delay in milliseconds r[time%] relative delay [-f <File Name> or -f <stdout>] [-F <File Name> (forcing overwrite)] [-g [x][c][m][g] <Id> Get by Id x Id is in Hex m Id is Message Id c Id is Correlation Id g Id is Group Id [-h Strip headers [-i <Input Queue> (Browse)] [-I <Input Queue> (Get)] [-m <Queue Manager name>] [-o <Output Queue>] [-p Purge source queue] [-P <CCSID>[:X'Encoding'] CodePage conversion] [-q Quiet] [-r <Message Range>] x Message x only x..y Message x to message y x#y y messages starting at message x #x First x messages [-t <Transaction Message Limit>] [-T <Time on queue (Age) selection> [[[DD:]HH:]MM ][,[[DD:]HH:]MM] [-s <Ascii Search String>] [-S <Ascii Not Search String>] [-e <Ebcdic Search String>] [-E <Ebcdic Not Search String>] [-w <MQGET Wait interval(seconds)] [-x <Hex Search String>] [-X <Hex Not Search String>] Examples -------- Unload a queue to a file : dmpmqmsg -iQ1 -fmyfile Load a queue from a file : dmpmqmsg -oQ1 -fmyfile Copy a queue from Q1 to Q2 : dmpmqmsg -iQ1 -oQ2 Move a queue from Q1 to Q2 : dmpmqmsg -IQ1 -oQ2 Move old messages from Q1 to Q2 : dmpmqmsg -IQ1 -oQ2 -T1440 Provide Summary of messages : dmpmqmsg -iQ1 -ds |
Look at “-T
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#!/bin/bash echo '---------------------------------------------------------' echo ' This script move messages older then 2 days' echo ' from all queues (except SYSTEM) to files ' echo '---------------------------------------------------------' QMgr=QM1 echo 'dis q(*) where(CURDEPTH gt 0)' | runmqsc $QMgr | tr ')' '\n' | grep "QUEUE(" | tr "(" "\n" | grep -v "\sQUEUE$" | grep -v "SYSTEM" | { while read QName; do Cmd="dmpmqmsg -m $QMgr -I$QName -T02:00:00 \ -F/home/mqm/${QMgr}_${QName}_%c_%HH%M%S.txt" echo '============================================================' echo $QName eval $Cmd done } |
To delete all messages, without backuping messages to files, you need to use command (without “-T” & “-F” keys):
dmpmqmsg -m $QMgr -I$QName
Can we purge message from the queue which are older than 2 days without writing into a file?