Dead-letter queues and replay
A dead-letter entry records a queue delivery that exhausted its configured attempt limit. It retains the message for investigation. Other queues can already have completed the same publication, and a FIFO successor may already have proceeded.
Replay returns work to the original queue. It does not undo prior effects, reset other subscribers, or rewind an ordered stream.
Investigate before replay
Identify the affected queue and messages:
SELECT * FROM postgremq.list_dlq_messages()
WHERE queue_name = 'jobs'
ORDER BY published_at;
SELECT * FROM postgremq.list_queues() WHERE queue_name = 'jobs';
SELECT * FROM postgremq.queue_metrics() WHERE queue_name = 'jobs';
In the DLQ listing, published_at is the time the entry entered the DLQ. retry_count records the attempts associated with retirement. To inspect the original publication and payload, substitute an ID from that listing:
SELECT * FROM postgremq.get_message(123);
Payloads may contain sensitive data. Use the same access and handling controls as application data, and correlate with application logs using message and event identifiers rather than copying payloads into routine metrics.
Determine whether the failure was application validation, a downstream outage, an insufficient processing budget, or a final-attempt worker loss. A final-attempt crash reaches the DLQ through fast maintenance; a final negative acknowledgement can retire it immediately.
Fix the cause and assess scope
Replay operates on every DLQ entry for one queue. There is no built-in selective replay by message ID. If only some entries are safe to retry, preserve the evidence and design a separate recovery procedure rather than treating queue-wide replay as selective.
Before replay, confirm that the queue still exists and is live, compatible consumers are running, and the failure cause has been addressed. Review idempotency: an earlier attempt may have completed an external effect before failing to acknowledge.
Grouped messages retain their original group sequence when replayed. They may become the head of their group again, but newer work may already have completed while the message was dead-lettered. Replay cannot restore historical processing order. Applications with sequence-sensitive state may need reconciliation before consuming replayed work.
Replay and verify
Once all entries for the queue are ready to retry:
SELECT postgremq.requeue_dlq_messages('jobs');
SELECT * FROM postgremq.list_dlq_messages() WHERE queue_name = 'jobs';
SELECT * FROM postgremq.get_queue_statistics('jobs');
Replay moves the queue's DLQ entries back to pending deliveries and resets attempts to zero. Monitor completed progress, failures, and renewed DLQ growth. An empty DLQ immediately after replay establishes only that entries moved, not that processing succeeded.
Consider consumer concurrency and downstream recovery capacity before releasing a large backlog. Replay is not a per-message rate limiter; control processing through consumers or a separately designed recovery process.
Expired Exclusive queues
An expired Exclusive queue cannot be revived by replay or redeclaration. Its DLQ entries can keep it from being physically deleted, but that does not make its backlog consumable.
Requeueing moves those entries out of the DLQ without restoring the subscription. Maintenance can then reap the expired queue and remove its delivery rows. Preserve any required payloads and decide how to recover their effects before doing this. Creating a new subscription receives future publications; it does not automatically transfer the expired backlog.
Discard dead letters
purge_dlq() deletes dead-letter entries across all queues, not just the queue being investigated. It leaves payload collection to retention. The built-in function does not accept a queue argument.
Use it only after reviewing and deciding to discard the complete DLQ scope:
SELECT * FROM postgremq.list_dlq_messages();
-- Run only after approving the complete result set for deletion:
SELECT postgremq.purge_dlq();
SELECT * FROM postgremq.list_dlq_messages();
For the scope of other destructive operations, see Managing topics and queues.