pgmq
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pgmq | 1.11.0 | FEAT | PostgreSQL | SQL |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 2880 | pgmq | No | Yes | No | Yes | Yes | No | pgmq |
| Related | kafka_fdw pg_cron pg_task pg_net pg_background pgagent pg_jobmon |
|---|---|
| Depended By | pg_later vectorize |
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 1.11.0 | 1817161514 | pgmq | - |
| RPM | PIGSTY | 1.11.0 | 1817161514 | pgmq_$v | - |
| DEB | PIGSTY | 1.11.0 | 1817161514 | postgresql-$v-pgmq | - |
| OS / 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 d12.x86_64.pg18 : postgresql-18-pgmq postgresql-18-pgmq_1.11.0-1PIGSTY~bookworm_amd64.deb
| PIGSTY 1.11.0 d12.x86_64.pg17 : postgresql-17-pgmq postgresql-17-pgmq_1.11.0-1PIGSTY~bookworm_amd64.deb
| PIGSTY 1.11.0 d12.x86_64.pg16 : postgresql-16-pgmq postgresql-16-pgmq_1.11.0-1PIGSTY~bookworm_amd64.deb
| PIGSTY 1.11.0 d12.x86_64.pg15 : postgresql-15-pgmq postgresql-15-pgmq_1.11.0-1PIGSTY~bookworm_amd64.deb
| PIGSTY 1.11.0 d12.x86_64.pg14 : postgresql-14-pgmq postgresql-14-pgmq_1.11.0-1PIGSTY~bookworm_amd64.deb
|
| d12.aarch64 | PIGSTY 1.11.0 d12.aarch64.pg18 : postgresql-18-pgmq postgresql-18-pgmq_1.11.0-1PIGSTY~bookworm_arm64.deb
| PIGSTY 1.11.0 d12.aarch64.pg17 : postgresql-17-pgmq postgresql-17-pgmq_1.11.0-1PIGSTY~bookworm_arm64.deb
| PIGSTY 1.11.0 d12.aarch64.pg16 : postgresql-16-pgmq postgresql-16-pgmq_1.11.0-1PIGSTY~bookworm_arm64.deb
| PIGSTY 1.11.0 d12.aarch64.pg15 : postgresql-15-pgmq postgresql-15-pgmq_1.11.0-1PIGSTY~bookworm_arm64.deb
| PIGSTY 1.11.0 d12.aarch64.pg14 : postgresql-14-pgmq postgresql-14-pgmq_1.11.0-1PIGSTY~bookworm_arm64.deb
|
| d13.x86_64 | PIGSTY 1.11.0 d13.x86_64.pg18 : postgresql-18-pgmq postgresql-18-pgmq_1.11.0-1PIGSTY~trixie_amd64.deb
| PIGSTY 1.11.0 d13.x86_64.pg17 : postgresql-17-pgmq postgresql-17-pgmq_1.11.0-1PIGSTY~trixie_amd64.deb
| PIGSTY 1.11.0 d13.x86_64.pg16 : postgresql-16-pgmq postgresql-16-pgmq_1.11.0-1PIGSTY~trixie_amd64.deb
| PIGSTY 1.11.0 d13.x86_64.pg15 : postgresql-15-pgmq postgresql-15-pgmq_1.11.0-1PIGSTY~trixie_amd64.deb
| PIGSTY 1.11.0 d13.x86_64.pg14 : postgresql-14-pgmq postgresql-14-pgmq_1.11.0-1PIGSTY~trixie_amd64.deb
|
| d13.aarch64 | PIGSTY 1.11.0 d13.aarch64.pg18 : postgresql-18-pgmq postgresql-18-pgmq_1.11.0-1PIGSTY~trixie_arm64.deb
| PIGSTY 1.11.0 d13.aarch64.pg17 : postgresql-17-pgmq postgresql-17-pgmq_1.11.0-1PIGSTY~trixie_arm64.deb
| PIGSTY 1.11.0 d13.aarch64.pg16 : postgresql-16-pgmq postgresql-16-pgmq_1.11.0-1PIGSTY~trixie_arm64.deb
| PIGSTY 1.11.0 d13.aarch64.pg15 : postgresql-15-pgmq postgresql-15-pgmq_1.11.0-1PIGSTY~trixie_arm64.deb
| PIGSTY 1.11.0 d13.aarch64.pg14 : postgresql-14-pgmq postgresql-14-pgmq_1.11.0-1PIGSTY~trixie_arm64.deb
|
| u22.x86_64 | PIGSTY 1.11.0 u22.x86_64.pg18 : postgresql-18-pgmq postgresql-18-pgmq_1.11.0-1PIGSTY~jammy_amd64.deb
| PIGSTY 1.11.0 u22.x86_64.pg17 : postgresql-17-pgmq postgresql-17-pgmq_1.11.0-1PIGSTY~jammy_amd64.deb
| PIGSTY 1.11.0 u22.x86_64.pg16 : postgresql-16-pgmq postgresql-16-pgmq_1.11.0-1PIGSTY~jammy_amd64.deb
| PIGSTY 1.11.0 u22.x86_64.pg15 : postgresql-15-pgmq postgresql-15-pgmq_1.11.0-1PIGSTY~jammy_amd64.deb
| PIGSTY 1.11.0 u22.x86_64.pg14 : postgresql-14-pgmq postgresql-14-pgmq_1.11.0-1PIGSTY~jammy_amd64.deb
|
| u22.aarch64 | PIGSTY 1.11.0 u22.aarch64.pg18 : postgresql-18-pgmq postgresql-18-pgmq_1.11.0-1PIGSTY~jammy_arm64.deb
| PIGSTY 1.11.0 u22.aarch64.pg17 : postgresql-17-pgmq postgresql-17-pgmq_1.11.0-1PIGSTY~jammy_arm64.deb
| PIGSTY 1.11.0 u22.aarch64.pg16 : postgresql-16-pgmq postgresql-16-pgmq_1.11.0-1PIGSTY~jammy_arm64.deb
| PIGSTY 1.11.0 u22.aarch64.pg15 : postgresql-15-pgmq postgresql-15-pgmq_1.11.0-1PIGSTY~jammy_arm64.deb
| PIGSTY 1.11.0 u22.aarch64.pg14 : postgresql-14-pgmq postgresql-14-pgmq_1.11.0-1PIGSTY~jammy_arm64.deb
|
| u24.x86_64 | PIGSTY 1.11.0 u24.x86_64.pg18 : postgresql-18-pgmq postgresql-18-pgmq_1.11.0-1PIGSTY~noble_amd64.deb
| PIGSTY 1.11.0 u24.x86_64.pg17 : postgresql-17-pgmq postgresql-17-pgmq_1.11.0-1PIGSTY~noble_amd64.deb
| PIGSTY 1.11.0 u24.x86_64.pg16 : postgresql-16-pgmq postgresql-16-pgmq_1.11.0-1PIGSTY~noble_amd64.deb
| PIGSTY 1.11.0 u24.x86_64.pg15 : postgresql-15-pgmq postgresql-15-pgmq_1.11.0-1PIGSTY~noble_amd64.deb
| PIGSTY 1.11.0 u24.x86_64.pg14 : postgresql-14-pgmq postgresql-14-pgmq_1.11.0-1PIGSTY~noble_amd64.deb
|
| u24.aarch64 | PIGSTY 1.11.0 u24.aarch64.pg18 : postgresql-18-pgmq postgresql-18-pgmq_1.11.0-1PIGSTY~noble_arm64.deb
| PIGSTY 1.11.0 u24.aarch64.pg17 : postgresql-17-pgmq postgresql-17-pgmq_1.11.0-1PIGSTY~noble_arm64.deb
| PIGSTY 1.11.0 u24.aarch64.pg16 : postgresql-16-pgmq postgresql-16-pgmq_1.11.0-1PIGSTY~noble_arm64.deb
| PIGSTY 1.11.0 u24.aarch64.pg15 : postgresql-15-pgmq postgresql-15-pgmq_1.11.0-1PIGSTY~noble_arm64.deb
| PIGSTY 1.11.0 u24.aarch64.pg14 : postgresql-14-pgmq postgresql-14-pgmq_1.11.0-1PIGSTY~noble_arm64.deb
|
Build
You can build the RPM / DEB packages for pgmq using pig build:
pig build pkg pgmq # build RPM / DEB packages
Install
You can install pgmq directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:
pig repo add pgsql -u # Add repo and update cache
Install the extension using pig or apt/yum/dnf:
pig install pgmq; # Install for current active PG version
pig ext install -y pgmq -v 18 # PG 18
pig ext install -y pgmq -v 17 # PG 17
pig ext install -y pgmq -v 16 # PG 16
pig ext install -y pgmq -v 15 # PG 15
pig ext install -y pgmq -v 14 # PG 14
dnf install -y pgmq_18 # PG 18
dnf install -y pgmq_17 # PG 17
dnf install -y pgmq_16 # PG 16
dnf install -y pgmq_15 # PG 15
dnf install -y pgmq_14 # PG 14
apt install -y postgresql-18-pgmq # PG 18
apt install -y postgresql-17-pgmq # PG 17
apt install -y postgresql-16-pgmq # PG 16
apt install -y postgresql-15-pgmq # PG 15
apt install -y postgresql-14-pgmq # PG 14
Create Extension:
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 |
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.