---
title: How To Purge Background Jobs on Postgresql
slug: user-guide-10x/how-to-purge-background-jobs-on-postgresql
docTags: 
createdAt: 2025-12-09T12:10:45.248Z
---

**Steps to Purge Hangfire Jobs When the the following Feature Management Flag is enabled:&#x20;**

:::BlockQuote
HangfirePostgresqlJobStorage
:::

1. Set the namespace:

:::BlockQuote{indent="1"}
export ns=\<ENTER YOUR NAMESPACE>
:::

:::Paragraph{indent="1"}
Note: For embedded cluster, it will be *export ns=default*
:::

2. Stop the Swimlane API and Task Services:

:::BlockQuote{indent="1"}
kubectl -n $ns scale deploy swimlane-api swimlane-tasks --replicas=0
:::

3. Clear all Hangfire jobs and associated resources:

:::BlockQuote{indent="1"}
kubectl -n $ns exec -it postgresql-0 -- psql postgres\://swimlane:@localhost:5432/swimlane -c 'drop schema hangfire cascade;'
:::

4. Re-start the Swimlane API and Task Services:
   **NOTE:** Scale the replicas back to their original settings (e.g., 1, 3, 5, etc.).

:::BlockQuote{indent="1"}
kubectl -n $ns scale deploy swimlane-api swimlane-tasks --replicas=\<ORIGINAL-SETTINGS>
:::

5. Verify that Hangfire resources have been successfully re-created:

:::BlockQuote{indent="1"}
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>'
:::

:::Paragraph{indent="1"}

Other helpful commands:
:::

:::BlockQuote{indent="1"}
kubectl -n $ns exec -it postgresql-0 -- psql postgres\://swimlane:@localhost:5432/swimlane -c '\dt hangfire.\*'
:::

