Skip to main content

cleanup_completed_messages

SQL 0.1.1 · Source cbff27b8a34e1384384018680e46c20d5c610cc9.

Signature​

postgremq.cleanup_completed_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 completed delivery history​

Deletes up to the batch limit of completed delivery rows whose completion time is older than the retention age. Then invokes cleanup_unreferenced_messages with the same parameters. Returns only the number of delivery rows removed, not the payload count.

Transactions and errors​

PMQ03: negative age or nonpositive batch. Explicit NULL age selects nothing; NULL batch removes the limit. Candidate row locks use SKIP LOCKED; this is not a guarantee against DDL or other lock waits. Runs in caller transaction. Pending/processing rows are never age-expired by this function.

All calls require the applicable caller privileges. See SQL errors for driver failures and uncertain outcomes.

Example​

SELECT postgremq.cleanup_completed_messages(24, 1000);

A full 1,000-row result suggests more eligible history may remain. Zero does not prove the job failed.

Related: Maintenance, SQL conventions.