ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum IndexGeneral IBM MQ SupportClearing all the local Queues

Post new topicReply to topic Goto page 1, 2  Next
Clearing all the local Queues View previous topic :: View next topic
Author Message
vicks_mq
PostPosted: Fri May 10, 2019 4:16 am Post subject: Clearing all the local Queues Reply with quote

Disciple

Joined: 03 Oct 2017
Posts: 161

Hi All, is there a command to clear all the local queues at one go,

I tried using wildcard, but it didn't work

Code:
Runmqsc
CLEAR QL(london.*)
DIDN'T WORK
Back to top
View user's profile Send private message
bruce2359
PostPosted: Fri May 10, 2019 5:34 am Post subject: Reply with quote

Poobah

Joined: 05 Jan 2008
Posts: 8432
Location: US: west coast, almost. Otherwise, enroute.

DIDNT WORK is not an error produced by any MQ internal code or supplied utility. What error did you receive? What does it mean? What research did you do?
_________________
There are two types of people in this world:
1) Those that can extrapolate from incomplete data
Back to top
View user's profile Send private message
vicks_mq
PostPosted: Fri May 10, 2019 5:41 am Post subject: Reply with quote

Disciple

Joined: 03 Oct 2017
Posts: 161

bruce2359 wrote:
DIDNT WORK is not an error produced by any MQ internal code or supplied utility. What error did you receive? What does it mean? What research did you do?


I got this error - "AMQ8147: WebSphere MQ object London.* not found."


IBM Documentation doesn't mention a way to clear the queues.
https://www.ibm.com/support/knowledgecenter/en/SSFKSJ_9.0.0/com.ibm.mq.adm.doc/q020780_.htm
Back to top
View user's profile Send private message
abhi_thri
PostPosted: Fri May 10, 2019 7:01 am Post subject: Reply with quote

Master

Joined: 17 Jul 2017
Posts: 293
Location: UK

vicks_mq wrote:

I got this error - "AMQ8147: WebSphere MQ object London.* not found."


Clear ql will only work for one queue at a time using the full queue name,

http://www.mqseries.net/phpBB/viewtopic.php?p=168563&sid=ee6d01da2952ede60f234b966011dffc

Also please note the below,
Quote:
If an application has this queue open, or has a queue open that eventually resolves to this queue, the command fails. The command also fails if this queue is a transmission queue, and any queue that is, or resolves to, a remote queue that references this transmission queue, is open.
Back to top
View user's profile Send private message
RogerLacroix
PostPosted: Fri May 10, 2019 2:05 pm Post subject: Reply with quote

Jedi Knight

Joined: 15 May 2001
Posts: 3121
Location: London, ON Canada

As abhi_thri mentioned, the "CLEAR QL" command only works on a single object at a time. Secondly and equally important, if any application has the queue open for either input or output then the "CLEAR QL" command immediately fails.

<Vendor_Plug>

MQ Batch Toolkit is great tool for doing all kinds of maintenance work on MQ. It has 45 separate functions, one of which is called ClearQ. The ClearQ function first checks if IPPROCS and OPPROCS are zero. If they are then it will issue a PCF CLEARQ command otherwise it will destructively get all messages from the queue. It takes the queue name as a parameter but MQ Batch Toolkit is designed to be used in a script or batch file.

Here's a ClearQ.bat file:

Code:
@echo off
setlocal

if [%1]==[] echo Queue Manager Profile was not specified && goto Usage
if [%2]==[] echo Queue Name was not specified && goto Usage

cd /D C:\Capitalware\MQBT\
mqbt.exe QLIST -p %1 -k %2 -t L -f qdepth.txt -D
FOR /F "tokens=1,2" %%A in (qdepth.txt) DO (

   if %%B GTR 0 (
      mqbt.exe ClearQ -p %1 -q %%A
   )
)
del qdepth.txt
goto :DONE

:Usage
echo Usage: %0 QMgr_Profile_Name Queue_Name
goto :DONE

:DONE
endlocal


You would call the batch file as follows:
Code:
CLearQ.bat MQWT1 LONDON.*


Here's what the script does:
(1) First it gets a list of queue names with the current queue depth outputted into a file called qdepth.txt
(2) The FOR loop simply extracts 1 line at a time from the file and breaks the line into 2 tokes: queue name and queue depth
(3) If the queue depth is great than 0 then call MQBT's CLEARQ command
(4) Delete the temporary qdepth.txt file.

</Vendor_Plug>

Regards,
Roger Lacroix
Capitalware Inc.
_________________
Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter
Back to top
View user's profile Send private message Visit poster's website
Andyh
PostPosted: Sat May 11, 2019 1:38 am Post subject: Reply with quote

Disciple

Joined: 29 Jul 2010
Posts: 165

Be very careful about deleting messages from "ALL" local queues.
For example this would be a very dangerous thing to do for almost any SYSTEM.* queue.
Back to top
View user's profile Send private message
PaulClarke
PostPosted: Sat May 11, 2019 1:21 pm Post subject: Reply with quote

Guardian

Joined: 17 Nov 2005
Posts: 942
Location: New Zealand

I agree with Andy that you have to be very careful about clearing system queues. It is rarely a good idea. With that in mind here is the script to clear any queue in MQSCX where we make sure that the queue is not a SYSTEM queue before we clear it.
Code:
func clearq(q)

foreach(DISPLAY Q(<@q>))

  if (! (queue == "SYSTEM.*"))
    @thisq = QUEUE
    print "Clearing queue",@thisq
    CLEAR QLOCAL(<@thisq>)
  endif

endfor

endfunc

clearq("*TEST*")

The script defines a simple function which is then called from the last line. You can see how easy it is to issue an MQ command and process the results in MQSCX. Note that the script allows wildcards anywhere in the name. To do what you want you would just say
Code:
clearq("london.*")


Cheers,
Paul.
_________________
Paul Clarke
MQGem Software
www.mqgem.com
Back to top
View user's profile Send private message Visit poster's website
gbaddeley
PostPosted: Sun May 12, 2019 4:02 pm Post subject: Reply with quote

Padawan

Joined: 25 Mar 2003
Posts: 1989
Location: Melbourne, Australia

Andyh wrote:
Be very careful about deleting messages from "ALL" local queues.
For example this would be a very dangerous thing to do for almost any SYSTEM.* queue.

That's the reason why MQ does not allow CLEAR QLOCAL with a wildcarded queue name. It's too easy to make a blunder.
_________________
Glenn
Back to top
View user's profile Send private message
St!n0
PostPosted: Thu Jun 06, 2019 11:18 pm Post subject: Reply with quote

Novice

Joined: 02 Jan 2019
Posts: 14

I have a one-line linux command that can get all queues and clear them, assuming that your queues have a naming standard, like for example, all queues start with Q.

Code:
echo "DISPLAY QL(Q*) WHERE(CURDEPTH GT 0)" | runmqsc <Qmgr> | grep -o -P "(?<=QUEUE)\(.+?\)" | sed -e 's/[(|)]//g' | xargs -n 1 | xargs -I {} echo "CLEAR QL('{}')" | runmqsc <Qmgr>


replace the <qmgr> with your queue manager's name

first the command gets all queues that start with 'Q' and that have messages on them.
Then grep looks for the value between brackets after the word QUEUE.
Then sed removes the round brackets and keeps only the queue name.
Then xargs is used to take in each line seperatly and a second xargs is used to pipe the queue name into the clear ql command and then that gets piped into runmqsc.

You can also transform this command to suspend the queue manager from all its clusters, to stop/start all channels and so much more bulk actions that are otherwise not possible with just using runmqsc.
Back to top
View user's profile Send private message
PaulClarke
PostPosted: Fri Jun 07, 2019 12:52 am Post subject: Reply with quote

Guardian

Joined: 17 Nov 2005
Posts: 942
Location: New Zealand

There's no doubt you can get clever with GREP, AWK, SED and lots of other tools. However, the complication mounts quickly. Even in this real simple example I would say your script is far from easy to understand and therefore prone to human error and a maintenance headache. I appreciate that I am biased but I can't help thinking that many real world examples would be far more complicated. Even a very simple change like you needed to clear queues that were *.PRD rather than Q.* would add complication. Suppose you now said that the queue must not be a transmission queue and you only wanted to attempt the CLEAR QL command if the IPPROC and OPPROC values were zero. With a scripting language such as MQSCX such things are trivial to add and don't impact the readability of the script. Doing what you are doing it is either impossible or you end up with something that is virtually unmaintainable. And why ? An Emerald licence of MQSCX is a mere $100 and the per seat price of a Diamond licence can be far, far less. You only have to save yourself a few hours work all year and the thing pays for itself.

Just by two cents and, as I said, I am biased.

Cheers,

Paul.
_________________
Paul Clarke
MQGem Software
www.mqgem.com
Back to top
View user's profile Send private message Visit poster's website
Vitor
PostPosted: Fri Jun 07, 2019 4:13 am Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 25776
Location: Ohio, USA

St!n0 wrote:
assuming that your queues have a naming standard, like for example, all queues start with Q.


That's a heck of an assumption. Ours (for example) start with the SKU code of the application which uses them, for the benefit of our support staff.

Also I agree with my worth associate. I have intermediate skills in grep, sed & awk and it took me a few minutes to figure out what you were doing. While my previous boss would have gone "ok, right...", (he could do a single line command that would edit War & Peace into Anne of Green Gables), the majority of my staff would go "erm.....", do their best and to quote the best IBM documentation:

Quote:
the results of this operation are undefined


Don't get me wrong, it's good, you've got skills, but it's based on a two risky assumptions:

- a simplistic naming standard
- the next guy is as clever as you
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
RogerLacroix
PostPosted: Fri Jun 07, 2019 9:30 am Post subject: Reply with quote

Jedi Knight

Joined: 15 May 2001
Posts: 3121
Location: London, ON Canada

Well, that sucks. I don't have any idea what the grep and sed are doing. I have been using Linux and Unix for years, so I don't know if that means I need more training or that command is just way too complex.

On the flip side, I agree everyone's comments about the "all" or "system" queues not being cleared. So, for the next release of MQBT, I will make the default behavior for QLIST function to not return the system queues. I will add a parameter "-S" that the user will need to explicitly specify to get the system queues.

Regards,
Roger Lacroix
Capitalware Inc.
_________________
Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter
Back to top
View user's profile Send private message Visit poster's website
bruce2359
PostPosted: Fri Jun 07, 2019 1:29 pm Post subject: Reply with quote

Poobah

Joined: 05 Jan 2008
Posts: 8432
Location: US: west coast, almost. Otherwise, enroute.

To circle back on the OP, what is the business requirement to clear all local queues?

I've had developers ask for admin authority in DEV-TEST to deal with badly crafted messages. When I ask 'how will you deal with this issue in PROD?, dev folks usually respond that they'll create an app to discard/purge/delete these messages. Create it in DEV-TEST, then percolate it to PROD as you would any other app.

I wholeheartedly agree with Vitor regarding home-grown utilities - they are useful until the author departs or the underlying software changes.
_________________
There are two types of people in this world:
1) Those that can extrapolate from incomplete data
Back to top
View user's profile Send private message
gbaddeley
PostPosted: Mon Jun 10, 2019 4:19 pm Post subject: Reply with quote

Padawan

Joined: 25 Mar 2003
Posts: 1989
Location: Melbourne, Australia

bruce2359 wrote:
To circle back on the OP, what is the business requirement to clear all local queues?

Indeed. 'all' is a bit too dramatic. It would be better to have the command / script driven by a list of queue names, or careful wild-card(s). Also, the CLEAR QLOCAL command will not clear any queues that have open handles.
_________________
Glenn
Back to top
View user's profile Send private message
bruce2359
PostPosted: Mon Jun 10, 2019 8:06 pm Post subject: Reply with quote

Poobah

Joined: 05 Jan 2008
Posts: 8432
Location: US: west coast, almost. Otherwise, enroute.

gbaddeley wrote:
bruce2359 wrote:
To circle back on the OP, what is the business requirement to clear all local queues?

... Also, the CLEAR QLOCAL command will not clear any queues that have open handles.

Which is why I push back for developers to write an app which can destructively consume affected messages.
_________________
There are two types of people in this world:
1) Those that can extrapolate from incomplete data
Back to top
View user's profile Send private message
Display posts from previous:
Post new topicReply to topic Goto page 1, 2  Next Page 1 of 2

MQSeries.net Forum IndexGeneral IBM MQ SupportClearing all the local Queues
Jump to:



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP


Theme by Dustin Baccetti
Powered by phpBB 2001, 2002 phpBB Group

Copyright MQSeries.net. All rights reserved.