Skip to content
pgmq

pgmq

pgmq : A lightweight message queue. Like AWS SQS and RSMQ but on Postgres.

Overview

ID Extension Package Version Category License Language
2660
pgmq
pgmq
1.12.0
FEAT
PostgreSQL
SQL
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
----d--
No
No
No
Yes
no
no
Relationships
Schemas pgmq
Need By
fsm_core
pg_later
vectorize
See Also
kafka_fdw
pg_task
pg_net
pg_background
pgagent
pg_jobmon

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT
PIGSTY
1.12.0
18
17
16
15
14
pgmq -
RPM
PIGSTY
1.12.0
18
17
16
15
14
pgmq_$v -
DEB
PIGSTY
1.12.0
18
17
16
15
14
postgresql-$v-pgmq -
Linux / PG PG18 PG17 PG16 PG15 PG14
el8.x86_64
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
el8.aarch64
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
el9.x86_64
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
el9.aarch64
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
el10.x86_64
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
el10.aarch64
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
d12.x86_64
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
d12.aarch64
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
d13.x86_64
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
d13.aarch64
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
u22.x86_64
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
u22.aarch64
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
u24.x86_64
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
u24.aarch64
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
u26.x86_64
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
u26.aarch64
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
PIGSTY 1.12.0
Package Version OS ORG SIZE File URL
pgmq_18 1.12.0 el8.x86_64 pigsty 43.0 KiB pgmq_18-1.12.0-1PIGSTY.el8.x86_64.rpm
pgmq_18 1.12.0 el8.x86_64 pgdg 55.8 KiB pgmq_18-1.12.0-1PGDG.rhel8.10.noarch.rpm
pgmq_18 1.11.0 el8.x86_64 pgdg 54.0 KiB pgmq_18-1.11.0-1PGDG.rhel8.10.noarch.rpm
pgmq_18 1.10.1 el8.x86_64 pgdg 44.5 KiB pgmq_18-1.10.1-1PGDG.rhel8.10.noarch.rpm
pgmq_18 1.12.0 el8.aarch64 pigsty 43.0 KiB pgmq_18-1.12.0-1PIGSTY.el8.aarch64.rpm
pgmq_18 1.12.0 el8.aarch64 pgdg 55.8 KiB pgmq_18-1.12.0-1PGDG.rhel8.10.noarch.rpm
pgmq_18 1.11.0 el8.aarch64 pgdg 53.9 KiB pgmq_18-1.11.0-1PGDG.rhel8.10.noarch.rpm
pgmq_18 1.10.1 el8.aarch64 pgdg 44.4 KiB pgmq_18-1.10.1-1PGDG.rhel8.10.noarch.rpm
pgmq_18 1.12.0 el9.x86_64 pigsty 41.0 KiB pgmq_18-1.12.0-1PIGSTY.el9.x86_64.rpm
pgmq_18 1.12.0 el9.x86_64 pgdg 53.2 KiB pgmq_18-1.12.0-1PGDG.rhel9.8.noarch.rpm
pgmq_18 1.11.1 el9.x86_64 pgdg 52.6 KiB pgmq_18-1.11.1-1PGDG.rhel9.8.noarch.rpm
pgmq_18 1.11.0 el9.x86_64 pgdg 51.4 KiB pgmq_18-1.11.0-1PGDG.rhel9.7.noarch.rpm
pgmq_18 1.11.0 el9.x86_64 pgdg 51.4 KiB pgmq_18-1.11.0-1PGDG.rhel9.6.noarch.rpm
pgmq_18 1.10.1 el9.x86_64 pgdg 42.7 KiB pgmq_18-1.10.1-1PGDG.rhel9.7.noarch.rpm
pgmq_18 1.10.1 el9.x86_64 pgdg 42.7 KiB pgmq_18-1.10.1-1PGDG.rhel9.6.noarch.rpm
pgmq_18 1.12.0 el9.aarch64 pigsty 41.0 KiB pgmq_18-1.12.0-1PIGSTY.el9.aarch64.rpm
pgmq_18 1.12.0 el9.aarch64 pgdg 53.1 KiB pgmq_18-1.12.0-1PGDG.rhel9.8.noarch.rpm
pgmq_18 1.11.1 el9.aarch64 pgdg 52.6 KiB pgmq_18-1.11.1-1PGDG.rhel9.8.noarch.rpm
pgmq_18 1.11.0 el9.aarch64 pgdg 51.3 KiB pgmq_18-1.11.0-1PGDG.rhel9.7.noarch.rpm
pgmq_18 1.11.0 el9.aarch64 pgdg 51.3 KiB pgmq_18-1.11.0-1PGDG.rhel9.6.noarch.rpm
pgmq_18 1.10.1 el9.aarch64 pgdg 42.6 KiB pgmq_18-1.10.1-1PGDG.rhel9.7.noarch.rpm
pgmq_18 1.10.1 el9.aarch64 pgdg 42.6 KiB pgmq_18-1.10.1-1PGDG.rhel9.6.noarch.rpm
pgmq_18 1.12.0 el10.x86_64 pigsty 41.1 KiB pgmq_18-1.12.0-1PIGSTY.el10.x86_64.rpm
pgmq_18 1.12.0 el10.x86_64 pgdg 53.3 KiB pgmq_18-1.12.0-1PGDG.rhel10.2.noarch.rpm
pgmq_18 1.11.1 el10.x86_64 pgdg 52.8 KiB pgmq_18-1.11.1-1PGDG.rhel10.2.noarch.rpm
pgmq_18 1.11.0 el10.x86_64 pgdg 51.6 KiB pgmq_18-1.11.0-1PGDG.rhel10.1.noarch.rpm
pgmq_18 1.11.0 el10.x86_64 pgdg 51.9 KiB pgmq_18-1.11.0-1PGDG.rhel10.0.noarch.rpm
pgmq_18 1.10.1 el10.x86_64 pgdg 42.8 KiB pgmq_18-1.10.1-1PGDG.rhel10.1.noarch.rpm
pgmq_18 1.10.1 el10.x86_64 pgdg 43.2 KiB pgmq_18-1.10.1-1PGDG.rhel10.0.noarch.rpm
pgmq_18 1.12.0 el10.aarch64 pigsty 41.1 KiB pgmq_18-1.12.0-1PIGSTY.el10.aarch64.rpm
pgmq_18 1.12.0 el10.aarch64 pgdg 53.3 KiB pgmq_18-1.12.0-1PGDG.rhel10.2.noarch.rpm
pgmq_18 1.11.1 el10.aarch64 pgdg 52.7 KiB pgmq_18-1.11.1-1PGDG.rhel10.2.noarch.rpm
pgmq_18 1.11.0 el10.aarch64 pgdg 51.5 KiB pgmq_18-1.11.0-1PGDG.rhel10.1.noarch.rpm
pgmq_18 1.11.0 el10.aarch64 pgdg 51.5 KiB pgmq_18-1.11.0-1PGDG.rhel10.0.noarch.rpm
pgmq_18 1.10.1 el10.aarch64 pgdg 42.8 KiB pgmq_18-1.10.1-1PGDG.rhel10.1.noarch.rpm
pgmq_18 1.10.1 el10.aarch64 pgdg 42.8 KiB pgmq_18-1.10.1-1PGDG.rhel10.0.noarch.rpm
postgresql-18-pgmq 1.12.0 d12.x86_64 pigsty 26.6 KiB postgresql-18-pgmq_1.12.0-1PIGSTY~bookworm_amd64.deb
postgresql-18-pgmq 1.12.0 d12.aarch64 pigsty 26.6 KiB postgresql-18-pgmq_1.12.0-1PIGSTY~bookworm_arm64.deb
postgresql-18-pgmq 1.12.0 d13.x86_64 pigsty 26.6 KiB postgresql-18-pgmq_1.12.0-1PIGSTY~trixie_amd64.deb
postgresql-18-pgmq 1.12.0 d13.aarch64 pigsty 26.6 KiB postgresql-18-pgmq_1.12.0-1PIGSTY~trixie_arm64.deb
postgresql-18-pgmq 1.12.0 u22.x86_64 pigsty 27.1 KiB postgresql-18-pgmq_1.12.0-1PIGSTY~jammy_amd64.deb
postgresql-18-pgmq 1.12.0 u22.aarch64 pigsty 27.1 KiB postgresql-18-pgmq_1.12.0-1PIGSTY~jammy_arm64.deb
postgresql-18-pgmq 1.12.0 u24.x86_64 pigsty 27.0 KiB postgresql-18-pgmq_1.12.0-1PIGSTY~noble_amd64.deb
postgresql-18-pgmq 1.12.0 u24.aarch64 pigsty 27.0 KiB postgresql-18-pgmq_1.12.0-1PIGSTY~noble_arm64.deb
postgresql-18-pgmq 1.12.0 u26.x86_64 pigsty 27.1 KiB postgresql-18-pgmq_1.12.0-1PIGSTY~resolute_amd64.deb
postgresql-18-pgmq 1.12.0 u26.aarch64 pigsty 27.1 KiB postgresql-18-pgmq_1.12.0-1PIGSTY~resolute_arm64.deb

Source

pig build pkg pgmq;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install 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 14

Create this extension with:

CREATE EXTENSION pgmq;

Usage

Sources:

pgmq implements durable message queues as PostgreSQL tables and SQL functions. It supports delayed delivery, visibility timeouts, FIFO groups, message headers, polling, topics, and archival. Use it when queue transactions should be coordinated with relational changes in the same database.

Create a Queue and Send

CREATE EXTENSION pgmq;
SELECT pgmq.create('jobs');

SELECT *
FROM pgmq.send(
  queue_name => 'jobs',
  msg        => '{"task":"refresh"}'::jsonb,
  delay      => 0
);

send returns the message identifier. send_batch inserts multiple JSONB messages. Headers can carry routing or tracing metadata separately from the body where the selected overload supports them.

Read with a Visibility Timeout

SELECT *
FROM pgmq.read(
  queue_name => 'jobs',
  vt         => 30,
  qty        => 10
);

Reading hides each message for vt seconds. On success, delete or archive it:

SELECT pgmq.delete('jobs', 42);
SELECT pgmq.archive('jobs', 43);

If processing fails or the consumer disappears, an unacknowledged message becomes visible again. Consumers must therefore be idempotent; pgmq does not make arbitrary application side effects globally exactly once.

pop reads and deletes immediately and is appropriate only when losing a message after the call is acceptable.

FIFO Group Head Polling

Version 1.12.0 adds a polling read for the head message of multiple FIFO groups:

SELECT *
FROM pgmq.read_grouped_head_with_poll(
  queue_name          => 'jobs',
  vt                  => 30,
  qty                 => 10,
  max_poll_seconds    => 5,
  poll_interval_ms    => 100
);

It selects head-of-group messages while polling for up to max_poll_seconds. This preserves per-group order while allowing different groups to be processed concurrently.

Queue Administration Index

  • pgmq.create(queue_name): create queue and archive structures.
  • pgmq.send and pgmq.send_batch: enqueue JSONB messages, optionally delayed.
  • pgmq.read: claim visible messages for a visibility timeout.
  • pgmq.read_grouped_head_with_poll: poll FIFO group heads.
  • pgmq.pop: read and immediately delete.
  • pgmq.delete: acknowledge by removing a message.
  • pgmq.archive: move a message to the queue archive table.
  • pgmq.drop_queue: remove queue objects.
  • pgmq.metrics and related helpers: inspect queue depth and age where available.

For queue jobs, archive rows are stored in pgmq.a_<queue_name>. Treat those tables as extension-managed objects.

Operational Notes

  • Set vt longer than normal processing time and design for redelivery after timeouts.
  • Queue and archive tables consume ordinary PostgreSQL WAL, storage, vacuum, and backup capacity.
  • Archive or delete completed messages and enforce an archive-retention policy.
  • Long polling holds a database connection. Size connection pools and polling intervals for the number of consumers.
  • Keep queue names within pgmq’s identifier rules; call the API rather than constructing table names from untrusted input.
Last updated on