写点什么

DolphinScheduler 6 个高频 SQL 操作技巧

作者:白鲸开源
  • 2025-07-01
    天津
  • 本文字数:1804 字

    阅读完需:约 6 分钟

DolphinScheduler 6 个高频 SQL 操作技巧

摘要: Apache DolphinScheduler 系列 4-后台 SQL 经验分享


关键词: 大数据、数据质量、数据调度

整体说明

在调研了 DolphinScheduler 之后,在项目上实际使用了一段时间,有了一些后台 SQL 实际经验,分享如下。


进入 DolphinScheduler 后台数据库,我这里使用的是 MySQL 数据库。


以任务名称包含“ods_xf_act” 的任务为例。

一、修改任务组操作

UPDATE t_ds_task_definition ajoin t_ds_task_definition_log b on a.`code`=b.`code`and a.version=b.versionset a.task_group_id = 19,b.task_group_id=19where a.name like'%ods_xf_act%'
复制代码

二、批量修改任务执行类型

UPDATE t_ds_process_definition ajoin t_ds_process_definition_log b on a.code=b.code and a.version=b.versionset a.execution_type = 1,b.execution_type=1where a.name like'%ods_xf_act%';
复制代码

三、查看定时器配置情况

根据此来选择配置定时器


select crontab,count(*) from t_ds_schedulesgroupby crontaborderbycount(*) desc
复制代码

四、批量更改定时器

定时器,在前台页面修改很麻烦,一个个改很慢,所以想着从后台批量修改。


  1. 确定需要更新的定时器列表


select t1.id,t1.process_definition_code,crontab,t2.name from t_ds_schedules t1join t_ds_process_definition t2on t1.process_definition_code = t2.`code`wherenamelike'%ods_xf_act%'and crontab like'%0 0 5 *%'
复制代码


  1. 更新成需要的 crontab 定时器


update t_ds_schedules t1join t_ds_process_definition t2on t1.process_definition_code = t2.`code`set t1.crontab = '0 0 11 * * ? *'wherenamelike'%ods_xf_act%'and crontab like'%0 0 5 *%'
复制代码


  1. 更新成需要的 crontab 定时器触发表 由于定时器已经 5 -> 11 修改完成, 所以后面的 where 条件都是 11


update qrtz_cron_triggers t1set t1.CRON_EXPRESSION = '0 0 11 * * ? *'where t1.TRIGGER_NAME in (selectconcat("job_",t1.id) from t_ds_schedules t1join t_ds_process_definition t2on t1.process_definition_code = t2.`code`wherenamelike'%ods_xf_act%'and crontab like'%0 0 11 *%')
复制代码


  1. 更新成最新 crontab 定时触发时间的起始时间 由于NEXT_FIRE_TIME有更新时差,所以往前推 8 小时


update qrtz_triggers t1set t1.NEXT_FIRE_TIME = round(UNIX_TIMESTAMP(date_sub("2024-07-23 11:00:00", INTERVAL8HOUR) )*1000)where t1.TRIGGER_NAME in (selectconcat("job_",t1.id) from t_ds_schedules t1join t_ds_process_definition t2on t1.process_definition_code = t2.`code`wherenamelike'%ods_xf_act%'and crontab like'%0 0 11 *%')
复制代码

五、通知策略修改为“都不发”,仍然告警

现象: 原先选择“失败发”,后面修改为“都不发”



原因: 原先有告警组,然后修改为都不发,原告警组后台并没有修改,是一个 bug。


临时解决方案:


select t1.*from t_ds_schedules t1join t_ds_process_definition t2on t1.process_definition_code = t2.`code`wherenamelike'%ods_xf_act%'
复制代码


把 warning_type = 0 的,对应 warning_group_id 都修改为 0


六、任务组队列,页面没有任务,已用资源却占满

查看任务组列表


select * from t_ds_task_grouporderby create_time desc
复制代码


如果遇到任务组是满的,页面查询却没有任务,可以手动修改字段值图片



查看任务组队列列表,找出没有完成,修改成已完成,就是修改值为 2。


-- t_ds_task_group_queue.`status` tinyint(4) DEFAULT '-1' COMMENT '-1: waiting  1: running  2: finished'
select * from t_ds_task_group_queuewhere1=1andstatus <> 2 -- finished 完成orderby create_time desc
复制代码


查看任务列表,找出没有完成,修改成已完成,就是修改值为 7。


-- t_ds_task_instance.`state` tinyint(4) DEFAULT NULL COMMENT 'Status: 0 commit succeeded, 1 running, 2 prepare to pause, 3 pause, 4 prepare to stop, 5 stop, 6 fail, 7 succeed, 8 need fault tolerance, 9 kill, 10 wait for thread, 11 wait for dependency to complete'
-- id 是上面t_ds_task_group_queue的task_id
select * from t_ds_task_instancewhere state <> 7-- successandidin (selectidfrom t_ds_task_group_queuewhere1=1andstatus <> 2-- finished 完成orderby create_time desc)orderby submit_time desclimit100
复制代码


转载自鹏说大数据

原文链接:Apache DolphinScheduler 系列 4-后台 SQL 经验分享

用户头像

白鲸开源

关注

一家开源原生的DataOps商业公司。 2022-03-18 加入

致力于打造下一代开源原生的DataOps 平台,助力企业在大数据和云时代,智能化地完成多数据源、多云及信创环境的数据集成、调度开发和治理,以提高企业解决数据问题的效率,提升企业分析洞察能力和决策能力。

评论

发布
暂无评论
DolphinScheduler 6 个高频 SQL 操作技巧_sql_白鲸开源_InfoQ写作社区