pgq
Overview
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 2650 | pgq | No | Yes | No | Yes | No | No | pg_catalog |
| Related | pgmq pgmb ulak pgmqtt redis kafka_fdw wal2json decoderbufs tcn pg_durable |
|---|
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PGDG | 3.5.2 | 1817161514 | pgq | - |
| RPM | PGDG | 3.5.1 | 1817161514 | pgq_$v | - |
| DEB | PGDG | 3.5.1 | 1817161514 | postgresql-$v-pgq3 | - |
Install
You can install pgq directly. First, make sure the PGDG repository is added and enabled:
Install the extension using pig or apt/yum/dnf:
Create Extension:
Usage
Sources:
- PgQ 3.5.2 README
- Control and installation privileges
- Batch acquisition API
- Batch events API
- Retry API
- Version 3.5.2 release
PgQ is a PostgreSQL extension that provides a generic, high-performance lockless queue with a simple SQL function API. It uses a producer-consumer model with batch-based event processing.
Core Concepts
- Queue: A named event stream. Events are inserted by producers and consumed in batches.
- Consumer: A named subscriber registered to a queue. Each consumer tracks its own position.
- Batch: A group of events retrieved together. Consumers process events batch by batch.
- Ticker: A background process that creates batch boundaries (ticks) at regular intervals.
Queue Management
Consumer Registration
Producing Events
Consuming Events
Typical Consumer Loop
Maintenance
PgQ requires a ticker daemon (pgqd) to run in the background for creating batch boundaries and performing maintenance tasks like table rotation and retry event processing.
Key Functions
| Function | Description |
|---|---|
pgq.create_queue(name) | Create a new queue |
pgq.drop_queue(name) | Remove a queue |
pgq.register_consumer(queue, consumer) | Register a consumer |
pgq.unregister_consumer(queue, consumer) | Unregister a consumer |
pgq.insert_event(queue, type, data, ...) | Insert an event |
pgq.next_batch(queue, consumer) | Get next batch ID |
pgq.get_batch_events(batch_id) | Get events from a batch |
pgq.event_retry(batch_id, event_id, seconds) | Schedule event retry |
pgq.finish_batch(batch_id) | Mark batch as processed |
pgq.get_queue_info([name]) | Get queue statistics |
pgq.get_consumer_info(queue) | Get consumer statistics |
Version and Access Boundaries
Upstream 3.5.2 supports PostgreSQL 10 through 19; the 3.5.2 release adds PostgreSQL 19 support without a documented SQL API change. The catalog currently tracks package version 3.5.1, so verify installed files before selecting an extension update target. The control file requires superuser installation and is non-relocatable. The API uses the pgq schema; review queue-management and consumer privileges for each application role.
A consumer advances only after pgq.finish_batch succeeds. Make event processing and acknowledgement atomic when possible, and handle repeated delivery when external side effects cannot share the database transaction.
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)