When a consumer encounters a processing failure,Documentation Index
Fetch the complete documentation index at: https://mintlify.com/NikolayS/PgQue/llms.txt
Use this file to discover all available pages before exploring further.
pgque.nack() schedules the message for redelivery after a configurable delay. Once a message has been nacked more times than the queue’s max_retries setting, it is routed to the dead letter queue (pgque.dead_letter) instead of being retried. This guide covers the full failure-handling lifecycle.
The nack and retry flow
The key pattern: callnack() for each failed message, then call ack() to close the batch. Both are required.
pgque.maint_retry_events() (scheduled every 30 seconds by pgque.start()) moves due rows back into the main event stream. The next tick then makes them visible to consumers.
The
maint_retry_events() → ticker() → receive() chain must run in separate transactions, just like the normal send/tick/receive flow. The snapshot rule applies here too.Configuring max retries
Setmax_retries per queue using set_queue_config:
retry_count field on received messages is NULL on first delivery and increments on each retry. When nack() is called and ev_retry >= max_retries, the message goes to pgque.dead_letter instead of the retry queue.
Dead letter queue
Inspecting the DLQ
Replaying DLQ entries
Replay a single entry by itsdl_id — it re-enters the main queue with a fresh event id:
dlq_replay_all isolates per-event failures — one bad row does not abort the rest. Failed entries are counted in failed; first_error carries the first failure’s details.
Purging the DLQ
The dead_letter table schema
| Column | Type | Notes |
|---|---|---|
dl_id | bigserial | Primary key |
dl_queue_id | int4 | FK to pgque.queue |
dl_consumer_id | int4 | FK to pgque.consumer |
dl_time | timestamptz | When the message was dead-lettered |
dl_reason | text | Reason passed to nack() |
ev_id | bigint | Original event id |
ev_time | timestamptz | Original event creation time |
ev_txid | xid8 | Transaction id of the original insert |
ev_retry | int4 | Retry count when dead-lettered |
ev_type | text | Event type |
ev_data | text | Event payload |
ev_extra1..4 | text | Extra columns |
pgque_reader has select on this table; pgque_admin has full access.