Cloud Composer 1 è in modalità post-manutenzione. Google non rilascia ulteriori aggiornamenti a Cloud Composer 1, incluse nuove versioni di Airflow, correzioni di bug e aggiornamenti della sicurezza. Ti consigliamo di pianificare la migrazione a Cloud Composer 2.
Questa pagina spiega come connettersi a un'istanza Cloud SQL che esegue il database Airflow del tuo ambiente Cloud Composer ed eseguire query SQL.
Ad esempio, potresti voler eseguire query direttamente sul database Airflow, eseguire il backup del database, raccogliere statistiche in base ai contenuti del database o recuperare altre informazioni personalizzate dal database.
Prima di iniziare
Esegui una query SQL sul database Airflow
Per connetterti al database Airflow:
Crea un DAG con uno o più operatori PostgresOperator. Per iniziare,
puoi utilizzare il DAG di esempio.
Nel parametro sql dell'operatore, specifica la query SQL.
Ad esempio, puoi attivare il DAG manualmente o attendere che venga eseguito in base a una pianificazione.
DAG di esempio:
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;",)
Esegui il dump dei contenuti del database e trasferiscili in un bucket
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-04-15 UTC."],[[["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."]]],[]]