Hangfire database size


We’re noticing our hangfire database is getting quite large over a relatively short period of time.

We’ve setup hangfire to clean up job history after 24 hours.

  1. It seems that failed Jobs are not cleaned up after 24 hours?
  2. Also the State table is not cleaned up?
  3. Our Counter table als gets really huge. We have about 2 million records here.most of them have Key
    “stats:succeeded” and ExpireAt column is empty.

Is there a way to clean up old entries to keep database size manageble?

Thanks in advance,


Yes, failed jobs do not become expired automatically to allow you to re-queue them without any time pressure. So you should re-run or delete them manually, or apply AutomaticRetry(OnAttemptsExceeded = AttemptsExceededAction.Delete) attribute to a method to delete failed jobs automatically.

Hangfire.State table records have foreign key to a Job table, so they are being removed at the same time with jobs.

Counter table was a real problem, but in the latest pre-release version records are being automatically aggregated.

1 Like