繁体   English   中英

使用语句超时运行 postgres 运算符 airflow dag

[英]Run postgres operator with statement timeout airflow dag

所以我一直在尝试在我的 DAG 上运行 2 个 postgres 运算符,看起来像这样:

default_args = {
    'owner': 'local',
}

log = logging.getLogger(_name_)

TEMP_SETTLEMENT ="""
set statement_timeout to 0;
select function_a();
"""

VACUM_SETTLEMENT="""
vacuum (verbose, analyze) test_table;
"""

try:
    with DAG(
        dag_id='temp-test',
        default_args=default_args,
        schedule_interval=none,
        start_date=datetime(2021, 10, 1),
        max_active_runs=1,
        catchup=False
    ) as dag:

        pg = PostgresOperator(
            task_id="data",
            postgres_conn_id="connection_1",
            database="DB_test",
            autocommit=True,
            sql=TEMP_SETTLEMENT,
        )

        vacum = PostgresOperator(
            task_id="vacum",
            postgres_conn_id="connection_1",
            database="DB_test",
            autocommit=True,
            sql=VACUM_SETTLEMENT,    )

        pg >> vacum 

except ImportError as e:
    log.warning("Could not import DAGs: %s", str(e))

当我尝试运行 temp_settlement 时,我总是收到语句超时,有什么办法可以保持 statement_timeout=0 吗?

谢谢

更新:

启动apache-airflow-providers-postgres>=4.1.0你可以这样做:

PostgresOperator(
...,
runtime_parameters={'statement_timeout': '3000ms'},
)

在解决问题PR中添加了此功能。

原答案:

你没有从你的描述中提到它我假设超时来自 Postgres 而不是来自 Airflow。

目前PostgresOperator不允许覆盖挂钩/连接设置。 要解决您的问题,您需要按照文档中的说明在额外字段中编辑connection_1 ,您需要添加statement_timeout

{'statement_timeout': '3600s'}

我打开https://github.com/apache/airflow/issues/21486作为后续功能请求,以允许直接从操作员设置statement_timeout

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM