Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear a queue in Oracle AQ

Tags:

I've been testing Oracle AQ for the first time. I have managed to create 2000 rows of test inserts into the queue I created.

Now, I'd like to clear those out. As I was teaching myself, I set the expiry time to be a month. I can't wait that long. And I don't think I should just delete them from the queue table.

What's the best way to do this?

like image 294
jeph perro Avatar asked Nov 23 '10 22:11

jeph perro


People also ask

How do I purge a queue in Oracle?

You can use the DBMS_aqadm. purge_queue_table procedure. – Ev. Rei.

What is enqueue and dequeue in Oracle?

When two messages are enqued with the same priority, the message which was enqued earlier will be dequeued first. However, if two messages are of different priorities, the message with the lower value (higher priority) will be dequeued first.

What is DBMS_AQ in Oracle?

The DBMS_AQ package provides an interface to Oracle Advanced Queuing (AQ).


2 Answers

You can use the DBMS_aqadm.purge_queue_table procedure.


SOLUTION

The SQL looks something like this :

-- purge queue DECLARE  po_t dbms_aqadm.aq$_purge_options_t; BEGIN   dbms_aqadm.purge_queue_table('MY_QUEUE_TABLE', NULL, po_t); END; 
like image 164
erbsock Avatar answered Oct 08 '22 17:10

erbsock


Just do a delete on the queue table.

Never mind, just did a check and that's not right:

Oracle Streams AQ does not support data manipulation language (DML) operations on queue tables or associated index-organized tables (IOTs), if any. The only supported means of modifying queue tables is through the supplied APIs. Queue tables and IOTs can become inconsistent and therefore effectively ruined, if DML operations are performed on them.


So, you'll have to create a little PL/SQL routine to pull the items off.

Use the dbms_aq package. Check the example from the documentation: Dequeuing Messages. Scroll down a little bit and there's a complete example.

like image 30
JOTN Avatar answered Oct 08 '22 18:10

JOTN