PGMQ puts an SQS shaped queue inside your own Postgres schema
A lightweight message queue. Like AWS SQS and RSMQ but on Postgres.
At a glance
- What is it?
- PGMQ is a lightweight message queue made of Postgres SQL objects, with SQS style reads, FIFO queues and topic routing. The parts that bite are the visibility timeout and the rows you have to clean up yourself.
- Who is it for?
- PGMQ suits teams that already run Postgres and want queue semantics, delayed sends and SQS shaped reads without adding a broker to the stack. It does not suit a design that needs delivery guarantees lasting past a visibility timeout, or a pipeline that nobody is willing to delete rows from.
- Can I use it commercially?
- Yes. PostgreSQL is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 6 days ago.
- What is it written in?
- Mainly Rust, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 23, 2026, and from our analysis. They are not legal advice.
Star history
- pgmq/pgmq5,412 ★ · +120
| Repository | 2026-09-23 | 2026-11-23 |
|---|---|---|
| pgmq/pgmq | 5.3k | 5.4k |
120 Stars in the last 61 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
Every queue is a table named q_ inside the pgmq schema
Queue creation is one SQL call, and what it leaves behind is a table.
Sends are inserts that hand back the message id, and the body is JSON:
-- creates the queue
SELECT pgmq.create('my_queue');-- messages are sent as JSON
SELECT * from pgmq.send(
queue_name => 'my_queue',
msg => '{"foo": "bar1"}'
);The optional `delay` argument is the one scheduling primitive in the walkthrough. A message sent with `delay => 5` sits on the queue and cannot be consumed for five seconds. Nothing sweeps it in the meantime, because the delay belongs to the row rather than to a timer, so a delayed message survives a consumer restart and costs nothing while it waits.
Because the queue is a table rather than a row in some catalog, queue names are Postgres identifiers. Two queues cannot share a name, a name that collides with an existing object is a problem you resolve at the database level, and every queue you create adds a table to the schema your backups already carry.
The visibility timeout is where the exactly once promise ends
`pgmq.read` takes that window as `vt` and the batch size as `qty`:
SELECT * FROM pgmq.read(
queue_name => 'my_queue',
vt => 30,
qty => 2
);The columns it returns tell you what the timeout physically is. `vt` holds an absolute timestamp rather than a countdown, `read_ct` counts how many times a row has been handed out, and `enqueued_at` and `last_read_at` sit next to them:
msg_id | read_ct | enqueued_at | last_read_at | vt | message | headers
--------+---------+-------------------------------+-------------------------------+-------------------------------+-----------------+---------
1 | 1 | 2026-01-23 20:27:21.7741-06 | 2026-01-23 20:27:31.605236-06 | 2026-01-23 20:28:01.605236-06 | {"foo": "bar1"} |
2 | 1 | 2026-01-23 20:27:26.505063-06 | 2026-01-23 20:27:31.605252-06 | 2026-01-23 20:28:01.605252-06 | {"foo": "bar2"} |Here the two messages were sent about five seconds apart, both were read within the same moment, and both stay locked until 20:28:01. If a worker fails before deleting or archiving them, they become visible again after the timeout and another consumer can read them, and the next read reports a higher `read_ct`.
So exactly once describes the read inside the window, not the side effects your handler performs. A handler that charges a card or writes a row will run twice if it dies after the side effect and before the delete. Size `vt` from the slowest handler you have, and write handlers that are safe to repeat.
An empty read returns headers and no rows
An idle queue is not an error, and it looks exactly like a busy one. Reading `my_queue` again while both messages are invisible returns the column headers and nothing else:
SELECT * FROM pgmq.read(
queue_name => 'my_queue',
vt => 30,
qty => 1
); msg_id | read_ct | enqueued_at | last_read_at | vt | message | headers
--------+---------+-------------+--------------+----+---------+---------That is the shape of an empty queue, and it is also the shape you get when every message is currently invisible, which the project states as one case rather than two. `qty` is a request, not a promise: ask for one row while two sit locked in another worker's window and you get zero.
For a consumer loop this matters twice over. Reading the empty result as a failure turns a quiet queue into an exception storm. Reading it as work to do produces a tight polling loop against the database. And since visibility is stored on the row, a queue whose workers all died mid job is indistinguishable from a queue nobody ever wrote to, so a consumer that stops on an empty result stops making progress during exactly the incident you built it for.
The quickstart image is tagged v1.10.0 while releases reach v1.13.0
The container is a single line, and the tag in it deserves a second look:
Two details sit in that string. The image name says pg18, which is the top of the supported range. The version says v1.10.0, while the recent releases are v1.13.1 from 2026-10-20, v1.13.0 from 2026-09-07 and v1.12.0 from 2026-07-14, and the last push was on 2026-10-20.
Run the command as written and you install an extension several releases behind the newest tag, while the documentation on the project homepage describes the newer one. Anything added in between, including the FIFO queues and topic routing covered below, is not in that container. Pin the tag you mean to run, then enable the extension on the session you connect to:
psql postgres://postgres:postgres@localhost:5432/postgresCREATE EXTENSION pgmq;Version changes do not ride along with the container. The repository carries an `UPDATING.md` at the top level, and moving between versions means following that file.
The SQL only path loads the objects without the extension mechanism
When the instance cannot host the extension, the repository ships the SQL as a file you apply yourself. Cloning and running one file puts the objects into the pgmq schema:
git clone https://github.com/pgmq/pgmq.git
cd pgmq
The project points at this route for places that do not natively support the PGMQ extension.
What you give up is the extension mechanism itself. `CREATE EXTENSION` records a version for the objects it creates and `ALTER EXTENSION UPDATE` moves between them. Load the file by hand and the database holds no version stamp to compare against, so upgrading follows `UPDATING.md` as a manual procedure, and two installations can drift apart without the database objecting. The repository documents no rollback for either route, so find your way back before you load either one.
Nothing expires a message, so the queue table only shrinks when you say so
The retention model is a promise that the queue will not clean up after you. Messages stay in the queue until explicitly removed, and they can be archived instead of deleted, which the feature list connects to long-term retention and replayability. Both operations are yours to call. Nothing in the design expires an acknowledged message, and no retention window or maximum queue length appears anywhere in the repository.
Because each queue is a table, the consequence shows up in ordinary SQL. A worker that reads and never deletes or archives leaves every message it ever consumed inside the queue, invisible rows and archived rows included, and that table then carries the write volume of the whole pipeline. The walkthrough covers the full lifecycle for that reason, from creating a queue through sending, reading, popping, archiving, deleting and dropping, with each step left as a call you make.
The rows that surprise people are the ones that come back rather than the ones that stay. A message locked by a worker that never finished returns to the queue after the timeout, and a delayed message sits in the table counting down rather than sitting in a timer wheel. Budget for the pgmq schema in your backup and vacuum policy, and decide who owns the delete or archive call before the first message is sent.
The repository root manifest builds the documentation site
The language mix in this repository is unusual for a project whose product is SQL. The primary language is Rust, and the Rust client sits in this tree at pgmq-rs, next to the SQL objects in pgmq-extension.
What the Python manifest in this repository describes is the documentation site:
[project]
name = "pgmq"
version = "0.1.0"
description = "Dependencies for PGMQ MkDocs"
requires-python = ">=3.10"Its dependencies are documentation tooling, including mkdocs, mkdocstrings, mike and semver, and the top level of the tree holds mkdocs.yml and a docs directory beside the SQL. Installing from this pyproject.toml gets you a static site generator rather than a queue client, and its version 0.1.0 does not track the extension releases. Anyone reaching for a PGMQ package inside this repository needs to know which artifact they are installing before comparing its version against v1.13.0.
FIFO queues and topic patterns live on their own documentation pages
The two capabilities that go past SQS semantics are documented outside the README. The examples directory carries SQL for both: `examples/grouped_rr_example.sql`, `examples/grouped_sqs_style_comparison.sql` and `examples/topics.sql`.
The README stops at the queue lifecycle. Its claim of API parity with AWS SQS and RSMQ describes the basic shape of send, read, pop, archive, delete and drop, and the walkthrough never reaches group keys or wildcard patterns. If your design needs ordering across several consumers, or needs one write to fan out to many subscribers, the functions you need are on those two pages and not in the quickstart.
Two things follow for anyone sizing this. The topics route is a second delivery path laid over the same SQL objects, not a replacement for the queue, so a design that uses both has to reason about a message reaching a worker twice by two different routes.
Editorial conclusion
PGMQ suits teams that already run Postgres and want queue semantics, delayed sends and SQS shaped reads without adding a broker to the stack. It does not suit a design that needs delivery guarantees lasting past a visibility timeout, or a pipeline that nobody is willing to delete rows from. Before adopting, check two things against your own setup: your handlers can safely repeat their side effects because a message returns once vt expires, and someone owns the delete or archive call. The last push landed on 2026-10-20, the day v1.13.1 shipped.
Frequently asked questions
How do you use Postgres as a queue with PGMQ?
PGMQ makes each queue a table in the pgmq schema. `SELECT pgmq.create('my_queue')` creates `pgmq.q_my_queue`, `pgmq.send` inserts a JSON body and returns the message id, and `pgmq.read` takes a visibility timeout and a batch size, which hides the rows it returns until that timeout passes.
Can PostgreSQL be used as a message broker, and what does PGMQ add?
That is the shape PGMQ targets. There is no background worker and no external dependency, only Postgres SQL objects, so a queue is a table, a send is an insert and a consumer is a SQL query. The repository describes it as a lightweight message queue like AWS SQS and RSMQ but on Postgres.
Does PGMQ need a background worker or a separate service running?
No. The feature list names the absence of a background worker and of external dependencies as the point of the project, with everything implemented as Postgres SQL objects. A message locked by a consumer that never came back becomes visible again when its visibility timeout expires, with nothing running to retry it.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/pgmq-pgmq)Star history chart for your README
[](https://hysenlabs.com/projects/pgmq-pgmq)Was this useful?