我有一台安装了Hangfire的服务器。我还没有检查过一段时间,似乎一个经常性的工作已经变得流氓。它停止工作,然后它重叠了重试,导致看起来完全锁定。
我想清除我的数据库并重新开始。我可以删除所有表中的数据,还是应该删除表,让Hangfire为我重新创建它们?这样做会冒任何风险吗?
答案 0 :(得分:20)
我最后放弃了这些表,起初查询根本不起作用,它只是继续进行而没有发生任何事情。然后我使用TRUNCATE TABLE [HangFire].[State]
,这一切都像一个魅力之后。以下是Hangfire 1.5.6
UseSqlServerStorage
使用的脚本:
GO
PRINT N'Dropping [HangFire].[FK_HangFire_State_Job]...';
GO
ALTER TABLE [HangFire].[State] DROP CONSTRAINT [FK_HangFire_State_Job];
GO
PRINT N'Dropping [HangFire].[FK_HangFire_JobParameter_Job]...';
GO
ALTER TABLE [HangFire].[JobParameter] DROP CONSTRAINT [FK_HangFire_JobParameter_Job];
GO
PRINT N'Dropping [HangFire].[Schema]...';
GO
DROP TABLE [HangFire].[Schema];
GO
PRINT N'Dropping [HangFire].[Job]...';
GO
DROP TABLE [HangFire].[Job];
GO
PRINT N'Dropping [HangFire].[State]...';
GO
DROP TABLE [HangFire].[State];
GO
PRINT N'Dropping [HangFire].[JobParameter]...';
GO
DROP TABLE [HangFire].[JobParameter];
GO
PRINT N'Dropping [HangFire].[JobQueue]...';
GO
DROP TABLE [HangFire].[JobQueue];
GO
PRINT N'Dropping [HangFire].[Server]...';
GO
DROP TABLE [HangFire].[Server];
GO
PRINT N'Dropping [HangFire].[List]...';
GO
DROP TABLE [HangFire].[List];
GO
PRINT N'Dropping [HangFire].[Set]...';
GO
DROP TABLE [HangFire].[Set];
GO
PRINT N'Dropping [HangFire].[Counter]...';
GO
DROP TABLE [HangFire].[Counter];
GO
PRINT N'Dropping [HangFire].[Hash]...';
GO
DROP TABLE [HangFire].[Hash];
GO
PRINT N'Dropping [HangFire].[AggregatedCounter]...';
GO
DROP TABLE [HangFire].[AggregatedCounter];
GO
PRINT N'Dropping [HangFire]...';
GO
DROP SCHEMA [HangFire];
GO
PRINT N'Update complete.';
GO
答案 1 :(得分:1)
我看到了一个非常有趣的解决方案here
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'
这基本上会截断所有表并重置Job表的种子(重置作业ID)
我认为值得一提的是,停止运行应用程序并确保在运行任何脚本之前已清除服务器上的工作进程是一种明智的做法
答案 2 :(得分:0)
对于Hangfire Postgresql,您可以运行以下命令。为了重建表,必须重新启动应用程序
ALTER TABLE hangFire.state DROP CONSTRAINT state_jobid_fkey;
ALTER TABLE hangFire.jobParameter DROP CONSTRAINT jobparameter_jobid_fkey;
DROP TABLE hangFire.Schema;
DROP TABLE hangFire.Job;
DROP TABLE hangFire.State;
DROP TABLE hangFire.jobParameter;
DROP TABLE hangFire.jobQueue;
DROP TABLE hangFire.Server;
DROP TABLE hangFire.list;
DROP TABLE hangFire.set;
DROP TABLE hangFire.lock;
DROP TABLE hangFire.counter;
DROP TABLE hangFire.hash;
DROP SCHEMA hangFire Cascade;
答案 3 :(得分:0)
您可以通过截断所有 hangfire 表并重置 Job 表的种子来清除所有 hangfire 作业。 (重置作业 ID)
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'
上找到了这个解决方案