How To
How To Purge Background Jobs on Postgresql
4 min
steps to purge hangfire jobs when the the following feature management flag is enabled hangfirepostgresqljobstorage set the namespace export ns=\<enter your namespace> note for embedded cluster, it will be export ns=default stop the swimlane api and task services kubectl n $ns scale deploy swimlane api swimlane tasks replicas=0 clear all hangfire jobs and associated resources kubectl n $ns exec it postgresql 0 psql postgres\ //swimlane @localhost 5432/swimlane c 'drop schema hangfire cascade;' re start the swimlane api and task services note scale the replicas back to their original settings (e g , 1, 3, 5, etc ) kubectl n $ns scale deploy swimlane api swimlane tasks replicas=\<original settings> verify that hangfire resources have been successfully re created export ns=\<your namespace> \# log into postgresql cli kubectl n $ns exec it postgresql 0 psql postgres\ //swimlane $(kubectl n $ns get secrets swimlane postgresql credentials postgresql acid zalan do o jsonpath="{ data password}" | base64 d)@localhost 5432/swimlane \# list of relations for hangfire schema \dt hangfire \# total number of records for each table within the hangfire schema select table name, (select n live tup from pg stat user tables where relname = table name) as row count from information schema tables where table schema = 'hangfire'; \# select all records given the state status (enqueued, processing, succeeded, deleted) select from hangfire job where statename='\<enter state status>' other helpful commands kubectl n $ns exec it postgresql 0 psql postgres\ //swimlane @localhost 5432/swimlane c '\dt hangfire '