pgboss Failed Jobs Impacting Performance

This query will truncate the pgboss.archivetable and remove old jobs from the pgboss.jobtable and should vastly improve the performance of the policy page.

BEGIN;
SELECT pg_advisory_xact_lock(('x' || md5(current_database() || '.pgboss.pgboss'))::bit(64)::bigint);
TRUNCATE pgboss.archive;
DELETE FROM pgboss.job
    WHERE (state <> 'failed' AND completedOn < (now() - interval '7200 seconds'))
    OR (state = 'failed' AND completedOn < (now() - interval '7200 seconds'))
    OR (state < 'active' AND keepUntil < now());
COMMIT;

Last updated