Apache Airflow Postgres Provider
The Apache Airflow Postgres Provider offers a comprehensive set of operators, hooks, and sensors for seamless interaction with PostgreSQL databases within Airflow DAGs. It enables tasks such as executing SQL queries, transferring data, and managing database connections. The current version is 6.6.2, and it follows a frequent release cadence to support new Airflow features and address issues.
Warnings
- breaking Provider version 6.5.0 and later require Apache Airflow 2.11.0 or newer. Older Airflow versions will not be able to install or run these provider versions.
- breaking In provider version 6.6.2 (released March 28, 2026), the `schema` argument in Postgres hooks (e.g., `PostgresHook`) has been renamed to `database`. Using `schema` will now raise an error.
- breaking Beginning with provider version 4.0.0, the `get_uri()` method of `PostgresHook` returns a URI with the `postgresql://` prefix instead of the older `postgres://` prefix. This aligns with SQLAlchemy 1.4.0+ requirements.
- deprecated The `runtime_parameters` argument in `PostgresOperator` was deprecated in favor of passing options via `hook_params` in provider version 5.5.2.
- gotcha Python 3.7 support was dropped in provider version 5.5.1. The current provider version requires Python >=3.10.
Install
-
pip install apache-airflow-providers-postgres
Imports
- PostgresOperator
from airflow.providers.postgres.operators.postgres import PostgresOperator
- PostgresHook
from airflow.providers.postgres.hooks.postgres import PostgresHook
Quickstart
import datetime
from airflow import DAG
from airflow.providers.postgres.operators.postgres import PostgresOperator
with DAG(
dag_id="postgres_example_dag",
start_date=datetime.datetime(2023, 1, 1),
schedule_interval="@once",
catchup=False,
tags=["postgres", "example"]
) as dag:
create_pet_table = PostgresOperator(
task_id="create_pet_table",
postgres_conn_id="postgres_default",
sql="""
CREATE TABLE IF NOT EXISTS pet (
pet_id SERIAL PRIMARY KEY,
name VARCHAR NOT NULL,
pet_type VARCHAR NOT NULL,
birth_date DATE NOT NULL,
owner VARCHAR NOT NULL
);
"""
)
populate_pet_table = PostgresOperator(
task_id="populate_pet_table",
postgres_conn_id="postgres_default",
sql="""
INSERT INTO pet (name, pet_type, birth_date, owner)
VALUES ('Fido', 'Dog', '2020-01-01', 'Alice'),
('Whiskers', 'Cat', '2019-05-15', 'Bob');
"""
)
create_pet_table >> populate_pet_table