importdatetimeimportosimportairflowfromairflow.providers.postgres.operators.postgresimportPostgresOperatorSQL_DATABASE=os.environ["SQL_DATABASE"]withairflow.DAG("airflow_db_connection_example",start_date=datetime.datetime(2024,1,1),schedule_interval=None,catchup=False)asdag:PostgresOperator(task_id="run_airflow_db_query",dag=dag,postgres_conn_id="airflow_db",database=SQL_DATABASE,sql="SELECT * FROM dag LIMIT 10;",)
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-04-10。"],[[["This page details how to connect to and run SQL queries on the Airflow database of your Cloud Composer 1 environment."],["Directly accessing the Airflow database is discouraged; the Airflow REST API or Airflow CLI commands are the recommended alternatives."],["Connecting to the Airflow database involves creating and uploading a DAG that utilizes the `PostgresOperator` to specify and run the SQL query."],["Avoid adding custom tables or modifying the schema of the existing Airflow database to prevent complications."],["Backing up the environment's data should be done with snapshots instead of dumping the database."]]],[]]