pgmq
pgmq : A lightweight message queue. Like AWS SQS and RSMQ but on Postgres.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 2880 | pgmq
|
pgmq
|
1.11.0 |
FEAT
|
PostgreSQL
|
SQL
|
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--s-d--
|
No
|
Yes
|
No
|
Yes
|
no
|
no
|
| Relationships | |
|---|---|
| Schemas | pgmq |
| Need By | pg_later
vectorize
|
| See Also | kafka_fdw
pg_cron
pg_task
pg_net
pg_background
pgagent
pg_jobmon
|
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PIGSTY
|
1.11.0 |
18
17
16
15
14
|
pgmq |
- |
| RPM | PIGSTY
|
1.11.0 |
18
17
16
15
14
|
pgmq_$v |
- |
| DEB | PIGSTY
|
1.11.0 |
18
17
16
15
14
|
postgresql-$v-pgmq |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
el8.x86_64
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
el8.aarch64
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
el9.x86_64
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
el9.aarch64
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
el10.x86_64
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
el10.aarch64
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
d12.x86_64
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
d12.aarch64
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
d13.x86_64
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
d13.aarch64
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
u22.x86_64
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
u22.aarch64
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
u24.x86_64
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
u24.aarch64
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
PIGSTY 1.11.0
|
Source
pig build pkg pgmq; # build rpm/debInstall
Make sure PGDG and PIGSTY repo available:
pig repo add pgsql -u # add both repo and update cacheInstall this extension with pig:
pig install pgmq; # install via package name, for the active PG version
pig install pgmq -v 18; # install for PG 18
pig install pgmq -v 17; # install for PG 17
pig install pgmq -v 16; # install for PG 16
pig install pgmq -v 15; # install for PG 15
pig install pgmq -v 14; # install for PG 14Create this extension with:
CREATE EXTENSION pgmq;Usage
PGMQ is a lightweight message queue built on PostgreSQL, providing guaranteed “exactly once” delivery within a visibility timeout, FIFO queues, topic-based routing, and message archival.
CREATE EXTENSION pgmq;Create a Queue
SELECT pgmq.create('my_queue');Send Messages
-- Send a single message (returns msg_id)
SELECT * FROM pgmq.send(
queue_name => 'my_queue',
msg => '{"foo": "bar"}'
);
-- Send with delay (invisible for 5 seconds)
SELECT * FROM pgmq.send(
queue_name => 'my_queue',
msg => '{"foo": "bar"}',
delay => 5
);
-- Send a batch of messages
SELECT pgmq.send_batch(
queue_name => 'my_queue',
msgs => ARRAY['{"a":1}','{"b":2}','{"c":3}']::jsonb[]
);Read Messages
Read messages and make them invisible for a visibility timeout (in seconds):
SELECT * FROM pgmq.read(
queue_name => 'my_queue',
vt => 30, -- visibility timeout in seconds
qty => 2 -- number of messages to read
);Pop a Message
Read and immediately delete a message:
SELECT * FROM pgmq.pop('my_queue');Delete a Message
SELECT pgmq.delete('my_queue', 6);Archive a Message
Move a message from the queue to the archive table for long-term retention:
SELECT pgmq.archive(queue_name => 'my_queue', msg_id => 2);
-- Archive multiple messages
SELECT pgmq.archive(queue_name => 'my_queue', msg_ids => ARRAY[3, 4, 5]);Inspect archived messages:
SELECT * FROM pgmq.a_my_queue;Drop a Queue
SELECT pgmq.drop_queue('my_queue');Visibility Timeout
Messages become invisible after being read for the duration of the visibility timeout (vt). If not deleted or archived within that time, they become visible again for other consumers. Set vt greater than the expected processing time.
Key Functions
| Function | Description |
|---|---|
pgmq.create(queue_name) |
Create a new queue |
pgmq.send(queue_name, msg, [delay]) |
Send a message |
pgmq.send_batch(queue_name, msgs) |
Send multiple messages |
pgmq.read(queue_name, vt, qty) |
Read messages with visibility timeout |
pgmq.pop(queue_name) |
Read and delete a message atomically |
pgmq.delete(queue_name, msg_id) |
Delete a message |
pgmq.archive(queue_name, msg_id/msg_ids) |
Archive message(s) |
pgmq.drop_queue(queue_name) |
Delete a queue |