CREATE QUEUE

更新时间:
复制 MD 格式

Creates a queue in the current database.

Syntax

CREATE QUEUE name QUEUE TABLE queue_table_name
    [ ( { option_name option_value } [, ...] ) ]

Options:

TYPE     [ normal_queue | exception_queue ]
RETRIES  INTEGER
RETRYDELAY DOUBLE PRECISION
RETENTION  DOUBLE PRECISION

Prerequisites

To run CREATE QUEUE, you must be either:

  • A superuser, or

  • A user with the aq_administrator_role privilege

Parameters

ParameterDescription
nameThe name of the queue. The name can be schema-qualified. Must be unique within the schema.
queue_table_nameThe name of the queue table to associate with the queue. The queue must reside in the same schema as its queue table.
option_name option_valueOne or more options for the queue. If the same option name appears more than once, the server returns an error.

Options

TYPE `normal_queue` | `exception_queue`

Sets the queue type.

  • normal_queue: supports both enqueue and dequeue operations.

  • exception_queue: supports dequeue operations only.

RETRIES `INTEGER`

The maximum number of attempts to delete a message from the queue.

RETRYDELAY `DOUBLE PRECISION`

The number of seconds the server waits after a rollback before retrying the message.

RETENTION `DOUBLE PRECISION`

The number of seconds a message is kept in the queue table after being dequeued.

Usage notes

If the queue name is schema-qualified, the queue is created in the specified schema. Otherwise, it is created in the current schema. A queue can only reside in the same schema as its queue table.

PolarDB for PostgreSQL (Compatible with Oracle) also supports creating queues through the DBMS_AQADM package, which provides additional options beyond this SQL syntax.

Example

Create a queue named work_order associated with the queue table work_order_table, with a maximum of five retry attempts and a two-second delay between retries:

CREATE QUEUE work_order
    QUEUE TABLE work_order_table
    (RETRIES 5, RETRYDELAY 2);

What's next

  • Use DROP QUEUE to delete a queue.