paint-brush
How to Regularly Delete Log Instances in DolphinScheduler by@zhoujieguang
411 reads
411 reads

How to Regularly Delete Log Instances in DolphinScheduler

by Zhou Jieguang
Zhou Jieguang HackerNoon profile picture

Zhou Jieguang

@zhoujieguang

Apache DolphinScheduler Committer

June 13th, 2024
Read on Terminal Reader
Read this story in a terminal
Print this story
Read this story w/o Javascript
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

After Apache DolphinScheduler has been running for a period of time, the instance scheduling logs increase significantly and need to be cleaned up regularly.
featured image - How to Regularly Delete Log Instances in DolphinScheduler
1x
Read by Dr. One voice-avatar

Listen to this story

Zhou Jieguang HackerNoon profile picture
Zhou Jieguang

Zhou Jieguang

@zhoujieguang

Apache DolphinScheduler Committer

Learn More
LEARN MORE ABOUT @ZHOUJIEGUANG'S
EXPERTISE AND PLACE ON THE INTERNET.
0-item
1-item

STORY’S CREDIBILITY

Code License

Code License

The code in this story is for educational purposes. The readers are solely responsible for whatever they build with it.

Guide

Guide

Walkthroughs, tutorials, guides, and tips. This story will teach you how to do something new or how to do something better.

After Apache DolphinScheduler has been running for a period of time, the instance scheduling logs increase significantly and need to be cleaned up regularly.


SQL Error [1701] [42000]: Cannot truncate a table referenced in a foreign key constraint (`dolphinscheduler`.`t_ds_task_instance`, CONSTRAINT `foreign_key_instance_id`) How to delete DolphinScheduler instance logs


SQL Error [1701] [42000] indicates an attempt to truncate (delete all rows from) a table that is referenced by a foreign key constraint in another table. In this case, the dolphinscheduler.t_ds_task_instance the foreign key constraint references table foreign_key_instance_id.


To resolve this issue, you can follow these steps:


1. Remove the Foreign Key Constraint:

Before deleting the data from the table, you must remove or disable the foreign key constraint referencing this table. This ensures that the database integrity is not compromised. For example, you can use the following SQL statement to remove the foreign key constraint (adjust the syntax according to your database system):


ALTER TABLE referencing_table DROP FOREIGN KEY foreign_key_instance_id;


Here, referencing_table is the name of the table that references t_ds_task_instance.


2. Truncate the Table:


After removing the foreign key constraint, you can now truncate the table.

TRUNCATE TABLE dolphinscheduler.t_ds_task_instance;


3. Re-add the Foreign Key Constraint:


After truncating the table, if needed, you can re-add the foreign key constraint.

ALTER TABLE referencing_table ADD CONSTRAINT foreign_key_instance_id FOREIGN KEY (instance_id) REFERENCES t_ds_task_instance(id);


Please note that before performing these operations, make sure you have sufficient permissions and understand the impact of these operations on your database. It is recommended to back up the database before operating in a production environment.


Additionally, if you are using a database like MySQL, you can also consider using SET FOREIGN_KEY_CHECKS = 0; to temporarily disable foreign key constraints, then perform the truncate operation, and finally re-enable the foreign key constraints:


Final Solution

SET FOREIGN_KEY_CHECKS = 0;TRUNCATE TABLE dolphinscheduler.t_ds_task_instance;SET FOREIGN_KEY_CHECKS = 1;


But note that this method temporarily violates database integrity, so use it with caution. The community recommends using the open API to safely delete workflow instances and task instances. The open API can delete the running logs of task instances.

L O A D I N G
. . . comments & more!

About Author

Zhou Jieguang HackerNoon profile picture
Zhou Jieguang@zhoujieguang
Apache DolphinScheduler Committer

TOPICS

THIS ARTICLE WAS FEATURED IN...

Permanent on Arweave
Read on Terminal Reader
Read this story in a terminal
 Terminal
Read this story w/o Javascript
Read this story w/o Javascript
 Lite
X REMOVE AD