Skip to content

Apache Dolphinscheduler

删除历史记录

::: tabs

@tab Mysql

drop table if exists tmp_t_ds_process_instance_1;
create table tmp_t_ds_process_instance_1 as
SELECT id process_instance_id
FROM t_ds_process_instance
WHERE DATE(end_time) < CURDATE() - INTERVAL 90 DAY
union
select id process_instance_id
from t_ds_process_instance
where DATE(start_time) < CURDATE() - INTERVAL 90 DAY;
drop table if exists tmp_t_ds_process_instance_2;
create table tmp_t_ds_process_instance_2 asFq
select  
a.id as task_instance_id
from t_ds_task_instance a, tmp_t_ds_process_instance_1 b
where a.process_instance_id = b.process_instance_id;

DELETE  a from t_ds_process_instance a  where exists (
select 1 from tmp_t_ds_process_instance_1 b where a.id = b.process_instance_id
);

SET SQL_SAFE_UPDATES = 0;
delete a from t_ds_task_instance a where exists (
select 1 from tmp_t_ds_process_instance_2 b where a.id = b.task_instance_id
);



delete a from t_ds_relation_process_instance a where exists ( select  1 from tmp_t_ds_process_instance_1 b where a.parent_process_instance_id = b.process_instance_id
);
delete a from t_ds_relation_process_instance a where exists ( select  1 from tmp_t_ds_process_instance_1 b where a.process_instance_id = b.process_instance_id
);
delete a from t_ds_relation_process_instance a where exists (select 1 from tmp_t_ds_process_instance_2 b where a.parent_task_instance_id = b.task_instance_id
);

drop table if exists tmp_t_ds_process_instance_1; drop table if exists tmp_t_ds_process_instance_2;

@tab Postgresql

drop table if exists tmp_t_ds_process_instance_1;
create table tmp_t_ds_process_instance_1 as
SELECT id process_instance_id
FROM t_ds_process_instance
WHERE end_time::date < CURRENT_DATE - INTERVAL '7 days'
union
select id process_instance_id
from t_ds_process_instance
where start_time::date < CURRENT_DATE - INTERVAL '7 days'
drop table if exists tmp_t_ds_process_instance_2;
create table tmp_t_ds_process_instance_2 as
select  
a.id as task_instance_id
from t_ds_task_instance a, tmp_t_ds_process_instance_1 b
where a.process_instance_id = b.process_instance_id;

DELETE FROM t_ds_process_instance a
USING tmp_t_ds_process_instance_1 b
WHERE a.id = b.process_instance_id;

DELETE FROM t_ds_task_instance a
USING tmp_t_ds_process_instance_2 b
WHERE a.id = b.task_instance_id;



DELETE FROM t_ds_relation_process_instance a
USING tmp_t_ds_process_instance_1 b
WHERE a.parent_process_instance_id = b.process_instance_id;


DELETE FROM t_ds_relation_process_instance a
USING tmp_t_ds_process_instance_1 b
WHERE a.process_instance_id = b.process_instance_id;


DELETE FROM t_ds_relation_process_instance a
USING tmp_t_ds_process_instance_2 b
WHERE a.parent_task_instance_id = b.task_instance_id;
DELETE FROM t_ds_process_instance;
DELETE FROM t_ds_task_instance;
DELETE FROM t_ds_relation_process_instance;

:::

服务重启后如何停止历史任务调度

  • 查看调度任务下次触发时间
SELECT job_name,
  FROM_UNIXTIME(NEXT_FIRE_TIME / 1000, '%Y-%m-%d %H:%i:%s') AS next_fire_time_fmt
FROM QRTZ_TRIGGERS;
  • 将下次触发时间改为将来时间
SET SQL_SAFE_UPDATES = 0;
UPDATE QRTZ_TRIGGERS
SET NEXT_FIRE_TIME = (
    UNIX_TIMESTAMP(
        CONCAT(
            DATE_ADD(CURDATE(), INTERVAL 1 DAY), 
            ' ', 
            TIME(FROM_UNIXTIME(NEXT_FIRE_TIME / 1000))
        )
    ) * 1000
);
SET SQL_SAFE_UPDATES = 1;

update t_ds_task_instance set state = 6 where state != 7 update t_ds_process_instance set state = 6 where state != 7

Warning

yyyy-MM-dd HH:mm:ss 必须改为将来时间

UPDATE QRTZ_TRIGGERS
SET NEXT_FIRE_TIME = (EXTRACT(EPOCH FROM TIMESTAMP 'yyyy-MM-dd HH:mm:ss') * 1000)::BIGINT;
  • mysql

通过将NEXT_FIRE_TIME 改为当前时间来停止历史任物

查看是否有调度

select * FROM dolphinscheduler.QRTZ_CRON_TRIGGERS;

job_name  是 t_ds_schedules  表的id 加 job_
update QRTZ_TRIGGERS set  NEXT_FIRE_TIME = UNIX_TIMESTAMP('2025-11-08 10:30:00') * 1000
  • pgsql SELECT job_name, TO_TIMESTAMP(NEXT_FIRE_TIME / 1000) AS next_fire_time_fmt FROM QRTZ_TRIGGERS;

UPDATE QRTZ_TRIGGERS SET NEXT_FIRE_TIME = (EXTRACT(EPOCH FROM TIMESTAMP '2025-11-08 10:30:00') * 1000)::BIGINT;

update t_ds_task_instance set state = 6 where state != 7 update t_ds_process_instance set state = 6 where state != 7

t_ds_process_instance

state 流程实例状态:0 提交成功,1 正在运行,2 准备暂停,3 暂停,4 准备停止,5 停止,6 失败,7 成功,8 需要容错,9 kill,10 等待线程,11 等待依赖完成

t_ds_task_instance state 任务实例状态:0 提交成功,1 正在运行,2 准备暂停,3 暂停,4 准备停止,5 停止,6 失败,7 成功,8 需要容错,9 kill,10 等待线程,11 等待依赖完成

update set state = '9' t_ds_process_instance where state not in ('5','6','7')

变量

时间

上一小时

$[HH-1/24]

http

Note

日志中打印的变量并不会替换

${变量名}

Q&A

  • python 没有配置正确也会报Permission denied