Cloud Composer 1 berada dalam mode pascapemeliharaan. Google tidak merilis update lebih lanjut ke Cloud Composer 1, termasuk Airflow versi baru, perbaikan bug, dan update keamanan. Sebaiknya rencanakan migrasi ke Cloud Composer 2.
Halaman ini menjelaskan cara terhubung ke instance Cloud SQL yang menjalankan
database Airflow dari lingkungan Cloud Composer
Anda dan menjalankan kueri SQL.
Misalnya, Anda mungkin ingin menjalankan kueri langsung di database Airflow,
membuat cadangan database, mengumpulkan statistik berdasarkan konten database, atau
mengambil informasi kustom lainnya dari database.
Sebelum memulai
Menjalankan kueri SQL di database Airflow
Untuk terhubung ke database Airflow:
Buat DAG dengan satu atau beberapa operator PostgresOperator. Untuk memulai,
Anda dapat menggunakan contoh DAG.
Di parameter sql operator, tentukan kueri SQL Anda.
Memicu DAG, misalnya, Anda dapat melakukannya
secara manual atau menunggu hingga berjalan sesuai jadwal.
Contoh DAG:
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;",)
Membuat dump konten database dan mentransfernya ke bucket
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-03-10 UTC."],[[["This page explains how to connect to and run SQL queries on the Cloud SQL instance that hosts the Airflow database for your Cloud Composer environment."],["While direct access to the Airflow database is possible, it's advised to use alternative methods like the Airflow REST API or CLI commands whenever feasible."],["To connect, create a DAG with `PostgresOperator` operators, specifying the SQL query in the `sql` parameter, and uploading/triggering it."],["It is not recommended to add custom tables or change the schema of the airflow database."],["Backing up the environment's data, including the Airflow database, should be done using snapshots instead of the deprecated database dumping method."]]],[]]