Skip to main content
AI & Machine Learning

Apache Airflow CLI & DAG Syntax

Advanced

Production Airflow CLI commands, TaskFlow API decorators, DAG scheduling, testing task instances, and database migrations.

Instant Copy & SearchProduction Flagged SyntaxCurrent Flag Reference

Apache Airflow CLI & DAG Syntax Interactive Command Directory

Browse, search, and copy battle-tested commands & syntax recipes (17 Total Commands).

17+ Verified Recipes
DAG Management--output table
airflow dags list --output table

List all registered DAGs found in the configured Airflow DAGs directory.

DAG Triggering--conf
airflow dags trigger <dag_id> --conf '{"batch_id": 1042}'

Trigger an immediate DAG execution run passing JSON runtime configuration.

Pause / Unpauseunpause, pause
airflow dags unpause <dag_id> && airflow dags pause <dag_id>

Resume or pause automatic scheduling triggers for a specific DAG pipeline.

Testing Task Instancestasks test <dag> <task> <date>
airflow tasks test <dag_id> <task_id> 2026-01-01

Execute and debug a specific task instance locally without recording state in the metadata DB.

Task Run--local
airflow tasks run <dag_id> <task_id> 2026-01-01 --local

Run a single task instance directly on current worker node.

DAG Run Statedags state
airflow dags state <dag_id> 2026-01-01

Query the execution state (success, failed, running) of a specific DAG run.

Database Migrationsdb migrate
airflow db migrate

Apply database schema migrations to the Airflow metadata store.

Connection Managementconnections add
airflow connections add pg_analytics --conn-type postgres --conn-host localhost --conn-login app --conn-password secret

Create an external service connection securely in the Airflow metadata store.

Webserver Daemon--port, -D
airflow webserver --port 8080 -D

Start the Airflow web application UI server daemon in background.

Scheduler Daemonscheduler -D
airflow scheduler -D

Start the Airflow scheduler monitoring DAG directories and triggering task instances.

TaskFlow API DAG@dag, @task
@dag(schedule="@daily", start_date=datetime(2026, 1, 1), catchup=False) def etl_pipeline(): @task def extract() -> list[dict]: return [{"id": 1}] @task def transform(data: list[dict]): return len(data) transform(extract())

Define modern Airflow 2.0+ pipeline using Python decorators with automated XCom passing.

Historic Backfillingbackfill, --reset-dagruns
airflow dags backfill <dag_id> --start-date 2026-01-01 --end-date 2026-01-10 --reset-dagruns

Trigger historic batch DAG backfills across target date window clearing prior execution states.

Task State Resetclear, --downstream
airflow tasks clear <dag_id> --task-regex '.*process.*' --start-date 2026-01-01 --downstream

Clear failed task states matching regex pattern including all downstream dependent tasks.

Concurrency Poolspools set
airflow pools set heavy_gpu_pool 4 'Limit concurrent GPU intensive tasks'

Define worker slot execution pools to throttle resource-intensive tasks across DAG runs.

Dynamic Variablesvariables set --json
airflow variables set app_config '{"max_workers": 8, "env": "prod"}' --json

Store structured JSON configuration parameters securely in Airflow metadata database.

Executor Verificationconfig get-value
airflow config get-value core executor

Inspect currently active task execution backend (CeleryExecutor, KubernetesExecutor, or LocalExecutor).

Non-Blocking Sensorsmode='reschedule'
from airflow.sensors.filesystem import FileSensor wait_file = FileSensor(task_id='wait', filepath='/data/*.csv', poke_interval=30, mode='reschedule')

Implement file sensor in reschedule mode yielding worker slots while awaiting files.

Zero Setup100% In-Browser Execution

Companion Developer Tools & Playgrounds

Accelerate command execution and syntax debugging with HelloAIHub suite of interactive tools.

Explore all developer tools

Apache Airflow CLI & DAG Syntax: Command Groups & Quick Index

17 indexed entries across 17 sections
DAG Management1 items
DAG Triggering1 items
Pause / Unpause1 items
Testing Task Instances1 items
Task Run1 items
DAG Run State1 items
Database Migrations1 items
Connection Management1 items
Webserver Daemon1 items
Scheduler Daemon1 items
TaskFlow API DAG1 items
Historic Backfilling1 items
Task State Reset1 items
Concurrency Pools1 items
Dynamic Variables1 items
Executor Verification1 items
Non-Blocking Sensors1 items

Highlighted Flags & Syntax Examples in Apache Airflow CLI & DAG Syntax

airflow dags list --output table

List all registered DAGs found in the configured Airflow DAGs directory.

Flags: --output table
airflow dags trigger <dag_id> --conf '{"batch_id": 1042}'

Trigger an immediate DAG execution run passing JSON runtime configuration.

Flags: --conf
airflow dags unpause <dag_id> && airflow dags pause <dag_id>

Resume or pause automatic scheduling triggers for a specific DAG pipeline.

Flags: unpause, pause
airflow tasks test <dag_id> <task_id> 2026-01-01

Execute and debug a specific task instance locally without recording state in the metadata DB.

Flags: tasks test <dag> <task> <date>

Frequently Asked Questions

Expert recommendations, common traps, and production best practices for Apache Airflow CLI & DAG Syntax.

How does the modern TaskFlow API compare to legacy Airflow operators?

Airflow 2.0+ TaskFlow API uses Python decorators (@dag, @task) to define DAGs and tasks natively in pure Python. It automatically manages XCom serialization and data dependencies between tasks, eliminating boilerplate PythonOperator definitions and manual xcom_push / xcom_pull calls.

Why is catchup=False recommended for most production DAGs?

If catchup=True (default), Airflow will execute a DAG run for every missed interval between start_date and the current date when the DAG is unpaused. Setting catchup=False prevents backfill stampedes on newly deployed DAGs.

How does 'airflow tasks test' differ from 'airflow tasks run'?

'airflow tasks test' runs a task locally in an isolated test harness without checking upstream task dependencies or saving execution state to the metadata DB. 'airflow tasks run' executes within the actual Airflow scheduler orchestration framework.

What is the difference between poke mode and reschedule mode in Airflow sensors?

In 'poke' mode (default), the sensor occupies a worker slot and thread continuously until the condition evaluates to true or times out, starving the cluster of worker capacity. In 'reschedule' mode, if the condition is not met, the sensor yields its worker slot back to the pool and sleeps until the next poke_interval, maximizing cluster concurrency.

What is the difference between CeleryExecutor and KubernetesExecutor?

CeleryExecutor uses a static pool of pre-allocated Celery worker nodes consuming tasks from Redis/RabbitMQ, making task startup fast but requiring capacity scaling. KubernetesExecutor dynamically spins up a dedicated Kubernetes pod for each individual task and terminates the pod upon completion, offering perfect isolation and elastic resource scaling at the cost of pod spin-up latency.

How does XCom work in Airflow and what are the size limits?

XCom (Cross-Communication) enables tasks to share small metadata payloads (like file paths or record IDs) via the Airflow metadata database. XCom payloads are serialized in SQL tables: PostgreSQL limits individual XComs to 1GB, MySQL to 64KB, and SQLite to 2GB. Never use XCom to transmit large dataframes; store large datasets in object storage (S3/GCS) and share only URI references via XCom.

Cross-Hub Skill Acceleration

Combine command lookups with active coding interviews and complete career paths.

Need More Cheat Sheets?

Explore developer cheat sheets and syntax guides on HelloAIHub.

Browse All Cheat Sheets