I use hangfire for more than a year now, with hangfire console, and some tables seem to have old information on it, from expired jobs
I created some scripts to clean the Set table, but it doesn't seem right, I mean, there were millions of records
declare @total int = 0
declare @count int = 1
while(@count>0)
begin
delete from [HangFire].[Set] where [key] in (
SELECT top 10000 [key]
FROM [HangFire].[Set]
left join hangfire.job on job.Id = SUBSTRING([Key], 19, LEN([Key]) - 19)
WHERE [Key] LIKE 'console:%'
and job.id is null
)
set @count = @@ROWCOUNT
set @total = @total + @count
print @total
end
And the table Hash has milions of records too.
Did I miss some configuration on hangfire to delete all of these records after the job is suceeded?
this is the size of my database, almost 2GB for 3k jobs

As of late April 2023, Hangfire now exposes a new
SqlServerStorageOptionsoption calledInactiveStateExpirationTimeout. It's aTimeSpanthat is used to find and delete old entries in theStatetable.GitHub src
The query looks like this:
Where
@expireMinis defined as(long)_stateExpirationTimeout.Negate().TotalMinutes, and_stateExpirationTimeoutis set fromInactiveStateExpirationTimeoutYou can set this option during configuration of a .NET Core application like so: