Skip to main content

How to Delete a Dag and Its History in Apache Airflow®

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

Deleting a Dag's file doesn't remove the Dag from Apache Airflow®: Airflow keeps the Dag's records and run history in its database. Deleting only the records isn't enough either, because the Dag comes back the next time Airflow reads its file. This guide removes a Dag for good on Airflow 3.4.0, file first and records second.

Syntax​

Syntax
airflow dags delete [-y] <dag id>
PartWhat it means
airflow dags deleteDeletes everything Airflow's database holds about one Dag. The command's help says: "Delete all DB records related to the specified DAG"
<dag id>The ID of the Dag to delete
-yOptional. Skips the question before deleting. The help says: "Do not prompt to confirm. Use with care!"

The command doesn't touch the Dag's file. Airflow's Dags documentation warns: "If the Dag is still in DAGS_FOLDER when you delete the metadata, the Dag will re-appear as the Dag processor will parse the folder, only historical runs information for the Dag will be removed." DAGS_FOLDER is the dags folder Airflow reads Dag files from, and the Dag processor is the part of Airflow that reads them. That's why the file goes first.

The Example​

A Dag called old_report, with one task and one finished run, isn't needed any more. Its file is dags/old_report.py:

dags/old_report.py
from airflow.sdk import dag, task


@dag(schedule=None, tags=["demo"])
def old_report():
@task
def build_report():
print("Building the report")

build_report()


old_report()

Searching for it in the Dags list shows it with its one successful run:

The Dags list searched for old_report: 1 Dag, old_report with the tag demo, its latest run on 2026-12-04 at 10:29:01 with a green check, and 1 successful run.

Prerequisites​

  • Apache Airflow® running, for example with airflow standalone, and a terminal where AIRFLOW_HOME points to its folder.

Step 1: Delete the Dag's File​

In the folder that holds dags, delete the file:

Terminal
rm dags/old_report.py

rm removes the file and prints nothing. The documentation says that when the Dag processor "misses the Dag that it had seen before", it sets the Dag "as deactivated", and "You can't see the deactivated Dags in the UI". Searching the Dags list for old_report less than half a minute later found nothing:

The Dags list searched for old_report after its file was deleted: 0 Dags and No Dags found.

How soon that happens depends on how often Airflow looks at the folder. The configuration reference says that with its default settings, airflow standalone refreshes the Dags folder every bundle_refresh_check_interval seconds, 5 by default, while other setups use [dag_processor] refresh_interval, 300 seconds by default.

If the Dag has a schedule, pause it before this step, so no new run starts while you remove it: the documentation lists pausing as the first step, and How to Pause and Unpause a Dag in Apache Airflow® shows how. old_report has no schedule, so it can't start on its own.

Step 2: Check What Airflow Still Keeps​

Terminal
airflow dags list-runs old_report
Output
dag_id | run_id | state | run_after | logical_date | start_date | end_date
===========+==========================================+=========+==================================+==============+==================================+=================================
old_report | manual__2026-12-04T10:29:01.688773+00:00 | success | 2026-12-04T10:29:01.688773+00:00 | | 2026-12-04T10:29:02.504051+00:00 | 2026-12-04T10:29:04.765188+00:00

The Dags list doesn't show the Dag any more, and its run is still in the database. The documentation explains: "The metadata and history of the Dag is kept for deactivated Dags and when the Dag is re-added to the DAGS_FOLDER it will be again activated and history will be visible."

Every airflow dags command first prints two FileType is deprecated warnings and a Could not import graphviz warning. I left them out of the outputs here: Fixed: FileType is deprecated and Fixed: Could not import graphviz explain them.

Step 3: Delete the Dag's Records​

Terminal
airflow dags delete old_report

The command asks before deleting. Type y and press Enter:

Output
This will drop all existing records related to the specified DAG. Proceed? (y/n)y
2026-12-04T10:44:55.170150Z [info ] Deleting Dag: old_report [airflow.api.common.delete_dag] loc=delete_dag.py:55
Removed 3 record(s)

The terminal after airflow dags delete old_report: the question This will drop all existing records related to the specified DAG. Proceed? (y/n) answered with y, then Deleting Dag: old_report and Removed 3 record(s).

Removed 3 record(s) is the number of database records it deleted for old_report. Afterwards, the database had no Dag, run or task rows left for it.

Step 4: Check That It's Gone​

Terminal
airflow dags list-runs old_report
Output
DAG: old_report does not exist in 'dag' table

The terminal after airflow dags list-runs old_report: DAG: old_report does not exist in 'dag' table.

Airflow no longer knows the Dag at all, and its run went with it.

Common Mistakes​

MistakeWhat happensDo this instead
Deleting the records while the file is still in dagsThe documentation says "the Dag will re-appear", without its history, when the Dag processor reads the folder againDelete the file first
Deleting only the fileThe Dag disappears from the Dags list, but its records stay: airflow dags list-runs still listed its runRun airflow dags delete as well
Running airflow dags delete in a terminal without AIRFLOW_HOMEThe command works on another Airflow folder, ~/airflow by default, not on yoursSet AIRFLOW_HOME first (How to Set AIRFLOW_HOME for Apache Airflow®)

Troubleshooting​

SymptomLikely causeFix
The Dag is back in the Dags list after airflow dags deleteIts file is still in the dags folderDelete the file, then run airflow dags delete again
DAG: <dag id> does not exist in 'dag' tableThe Dag is already deleted, or the ID is misspelledCheck the ID with airflow dags list

FAQ​

Can I delete a Dag from the UI?​

The documentation says the metadata can be deleted "via UI or API", and each Dag's card in the Dags list has a Delete Dag button, the bin icon. As with the command, delete the file first.

Does anything stay behind?​

Airflow's audit log, the record of what was done in Airflow. After the delete, the database still held 7 audit log entries for old_report, among them the delete itself, cli_dag_delete.

Is there a way back?​

No. Answering y deletes the records for good. Keep a copy of the Dag's file if you might need it again; its run history can't be restored.

Conclusion​

rm dags/old_report.py removed the file and hid the Dag from the Dags list, while airflow dags list-runs showed that Airflow still kept its run. airflow dags delete old_report then removed 3 records, after which Airflow reported that the Dag doesn't exist. Always in that order: the file first, the records second.

Additional Resources​

Apache®, Apache Airflow and Airflow® are either registered trademarks or trademarks of The Apache Software Foundation in the United States and/or other countries. No endorsement by The Apache Software Foundation is implied by the use of these marks.