Airflow: how to delete a DAG?

前端 未结 16 969
感动是毒
感动是毒 2020-11-28 23:45

I have started the Airflow webserver and scheduled some dags. I can see the dags on web GUI.

How can I delete a particular DAG from being run and shown in web GUI? I

相关标签:
16条回答
  • 2020-11-29 00:04

    versions >= 1.10.0:

    I have airflow version 1.10.2 and I tried executing airflow delete_dag command but the command throws following error:

    bash-4.2# airflow delete_dag dag_id

    [2019-03-16 15:37:20,804] {settings.py:174} INFO - settings.configure_orm(): Using pool settings. pool_size=5, pool_recycle=1800, pid=28224 /usr/lib64/python2.7/site-packages/psycopg2/init.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: http://initd.org/psycopg/docs/install.html#binary-install-from-pypi. """) This will drop all existing records related to the specified DAG. Proceed? (y/n)y Traceback (most recent call last): File "/usr/bin/airflow", line 32, in args.func(args) File "/usr/lib/python2.7/site-packages/airflow/utils/cli.py", line 74, in wrapper return f(*args, **kwargs) File "/usr/lib/python2.7/site-packages/airflow/bin/cli.py", line 258, in delete_dag raise AirflowException(err) airflow.exceptions.AirflowException: Server error

    Though I am able to delete through Curl command. Please let me know if anyone have idea about this command's execution, is this known or I am doing something wrong.

    versions <= 1.9.0:

    There is not a command to delete a dag, so you need to first delete the dag file, and then delete all the references to the dag_id from the airflow metadata database.

    WARNING

    You can reset the airflow meta database, you will erase everything, including the dags, but remember that you will also erase the history, pools, variables, etc.

    airflow resetdb and then airflow initdb

    0 讨论(0)
  • 2020-11-29 00:07

    Not sure why Apache Airflow doesn't have an obvious and easy way to delete a DAG

    Filed https://issues.apache.org/jira/browse/AIRFLOW-1002

    0 讨论(0)
  • 2020-11-29 00:07

    There is nothing inbuilt in Airflow that does that for you. In order to delete the DAG, delete it from the repository and delete the database entries in the Airflow metastore table - dag.

    0 讨论(0)
  • 2020-11-29 00:07

    Remove the dag(you want to delete) from the dags folder and run airflow resetdb.

    Alternatively, you can go into the airflow_db and manually delete those entries from the dag tables(task_fail, xcom, task_instance, sla_miss, log, job, dag_run, dag, dag_stats).

    0 讨论(0)
  • 2020-11-29 00:09

    DAG-s can be deleted in Airflow 1.10 but the process and sequence of actions must be right. There's an "egg and chicken problem" - if you delete DAG from frontend while the file is still there the DAG is reloaded (because the file is not deleted). If you delete the file first and refresh the page then DAG cannot be deleted from web gui any more. So the sequence of actions that let me delete a DAG from frontend was:

    1. delete the DAG file (in my case delete from pipeline repository and deploy to airflow servers, esp the scheduler)
    2. DO NOT refresh web GUI.
    3. In the web GUI in the DAGs view (normal frontpage) click on "Delete dag" -> the red icon on the far right.
    4. It cleans up all the remains of this DAG from the database.
    0 讨论(0)
  • 2020-11-29 00:09

    Based on the answer of @OlegYamin, I'm doing the following to delete a dag backed by postgres, where airflow uses the public schema.

    delete from public.dag_pickle where id = (
        select pickle_id from public.dag where dag_id = 'my_dag_id'
    );
    delete from public.dag_run where dag_id = 'my_dag_id';
    delete from public.dag_stats where dag_id = 'my_dag_id';
    delete from public.log where dag_id = 'my_dag_id';
    delete from public.sla_miss where dag_id = 'my_dag_id';
    delete from public.task_fail where dag_id = 'my_dag_id';
    delete from public.task_instance where dag_id = 'my_dag_id';
    delete from public.xcom where dag_id = 'my_dag_id';
    delete from public.dag where dag_id = 'my_dag_id';
    

    WARNING: The effect/correctness of the first delete query is unknown to me. It is just an assumption that it is needed.

    0 讨论(0)
提交回复
热议问题