Clean Hangfire logs

Hi!

We have millions of records in tables “Counter” and “State”. What is the safest way to remove those records? Is TRUNCATE TABLE good for it?

Thanks

1 Like

Any resolution here? I want to clear stuff out rather quickly, as well as manually (after I’ve viewed that things are OK).

DELETE FROM HangFire.Hash
DELETE FROM HangFire.Counter
DELETE FROM HangFire.Job
DELETE FROM HangFire.JobParameter
DELETE FROM HangFire.JobQueue
DELETE FROM HangFire.List
–DELETE FROM [HangFire.Schema]
DELETE FROM HangFire.Server
–DELETE FROM [HangFire.Set]
–DELETE FROM [HangFire.State]

State table records will be deleted after expiring a job (by default, 24 hours). However, Counter table is leaky a bit. I’ve created a GitHub issue and scheduled it to the 1.4.0:

Is this possible through code aswell. I want to make check that delete the entries which are older then one week from all haangfire tables .

I also have this issue, do not like the long ids… I’m still in development phase, and my id’s is already 6 digits long.
Here is what I did, and it works fine:

TRUNCATE TABLE [HangFire].[AggregatedCounter]
TRUNCATE TABLE [HangFire].[Counter]
TRUNCATE TABLE [HangFire].[JobParameter]
TRUNCATE TABLE [HangFire].[JobQueue]
TRUNCATE TABLE [HangFire].[List]
TRUNCATE TABLE [HangFire].[State]
DELETE FROM [HangFire].[Job]
DBCC CHECKIDENT (’[HangFire].[Job]’, reseed, 0)
UPDATE [HangFire].[Hash] SET Value = 1 WHERE Field = ‘LastJobId’