cleanup_unreferenced_messages
SQL 0.1.1 · Source cbff27b8a34e1384384018680e46c20d5c610cc9.
Signature
postgremq.cleanup_unreferenced_messages(p_older_than_hours integer DEFAULT 24, p_batch_size integer DEFAULT 1000)
RETURNS integer
The signature, defaults, and result above were extracted from the installed PostgreSQL catalog.
Collect payloads with no delivery or DLQ references
Deletes up to the batch limit of payloads older than the retention age by publication time, only when no queue delivery or DLQ entry references them. Prunes newly unused group state. Returns the payload count. Publications with no subscribers and payloads left by queue deletion are eligible.
Transactions and errors
PMQ03: negative age or nonpositive batch. NULL age selects nothing; NULL batch is unbounded. Uses SKIP LOCKED candidates and transaction-scoped changes. Group pruning can raise 40001 at stronger isolation. Called automatically by completed-delivery cleanup.
All calls require the applicable caller privileges. See SQL errors for driver failures and uncertain outcomes.
Example
SELECT postgremq.cleanup_unreferenced_messages(24, 1000);
A payload retained for a slow subscriber or DLQ remains regardless of age.
Related: Maintenance, SQL conventions.