隨著時間推移,環境中的 Airflow 資料庫會儲存越來越多資料。這類資料包括與過去 DAG 執行作業、工作和其他 Airflow 作業相關的資訊和記錄。
如果 Airflow 資料庫大小超過 20 GB,您就無法將環境升級至較新版本。
如果 Airflow 資料庫大小超過 20 GB,就無法建立快照。
維持資料庫效能
Airflow 資料庫效能問題可能會導致整體 DAG 執行問題。觀察資料庫 CPU 和記憶體用量統計資料。如果 CPU 和記憶體使用率接近上限,就表示資料庫超載,需要進行調整。Airflow 資料庫可用的資源量,由環境的環境大小屬性控管。如要擴充資料庫,請變更環境大小,改為較大的等級。增加環境大小會提高環境費用。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-29 (世界標準時間)。"],[[["\u003cp\u003eThis page outlines how to manually clean up the Airflow database in Cloud Composer 3 environments, as well as automatic alternatives.\u003c/p\u003e\n"],["\u003cp\u003eCloud Composer offers a database retention policy that automatically removes records older than a specified period, and it is preferred over the older database cleanup DAG.\u003c/p\u003e\n"],["\u003cp\u003eExceeding a 20 GB database size in Airflow prevents environment upgrades and snapshot creation, making regular cleanup essential.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003egcloud composer environments run\u003c/code\u003e command can be used to manually trim the database, removing entries older than the specified retention period.\u003c/p\u003e\n"],["\u003cp\u003eDatabase performance issues can cause DAG execution problems, and scaling up the environment size can address these issues, while also using proper Xcom practices to avoid issues with the database.\u003c/p\u003e\n"]]],[],null,["# Clean up the Airflow database\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\n**Cloud Composer 3** \\| [Cloud Composer 2](/composer/docs/composer-2/cleanup-airflow-database \"View this page for Cloud Composer 2\") \\| [Cloud Composer 1](/composer/docs/composer-1/cleanup-airflow-database \"View this page for Cloud Composer 1\")\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nThis page explains how to maintain the Airflow database in your environment.\n\nAutomatic database cleanup with a database retention policy\n-----------------------------------------------------------\n\nYou can configure automatic database cleanup for your Cloud Composer 3\nenvironment by setting a database retention policy. After you set up this\npolicy, records older than a certain period are automatically removed from the\nAirflow database daily. For more information, see\n[Configure database retention policy](/composer/docs/composer-3/configure-db-retention).\n\nDeprecated cleanup procedures\n-----------------------------\n\n| **Deprecated:** The **maintenance DAG approach is obsolete** in Cloud Composer 3. If you still use the database maintenance DAG, we recommend to remove or pause it and configure a [database retention policy](/composer/docs/composer-3/configure-db-retention) instead.\n\nBefore the database retention policy became available in\nCloud Composer, we recommended a different approach for automating\nthe database cleanup, through a [database cleanup DAG](/composer/docs/composer-2/cleanup-airflow-database). This\napproach is obsolete in Cloud Composer 3. This DAG does redundant work and you\ncan reduce the resource consumption by removing it and replacing it with a\n[database retention policy](/composer/docs/composer-3/configure-db-retention).\n\nLimits for database size\n------------------------\n\nAs the time goes, the Airflow database of your environment stores more and\nmore data. This data includes information and logs related to past DAG runs,\ntasks, and other Airflow operations.\n\n- If the Airflow database size is more than\n 20 GB,\n then you can't upgrade your environment to a later version.\n\n- If the Airflow database size is more than 20 GB,\n it is not possible to create snapshots.\n\nMaintain database performance\n-----------------------------\n\n- Airflow database performance issues can lead to overall DAG execution\n issues.\n [Observe Database CPU and memory usage](/composer/docs/composer-3/use-monitoring-dashboard#db-statistics)\n statistics. If CPU and memory utilization approaches the limits, then the\n database is overloaded and requires scaling.\n\n The amount of resources available to the Airflow database is controlled by\n the environment size property of your environment. To scale the database up\n [change the environment size](/composer/docs/composer-3/scale-environments) to a larger tier. Increasing the\n environment size increases the costs of your environment.\n\n- If you use the XCom mechanism to transfer files, make sure that you\n [use it according to Airflow's guidelines](https://airflow.apache.org/docs/apache-airflow/stable/core-concepts/xcoms.html#object-storage-xcom-backend).\n Transferring big files or a large number of files using XCom impacts\n Airflow database's performance and can lead to failures when loading\n snapshots or upgrading your environment. Consider using alternatives such\n as Cloud Storage to transfer large volumes of data.\n\nRemove entries for unused DAGs\n------------------------------\n\nYou can remove database entries for unused DAGs by\n[removing DAGs from the Airflow UI](/composer/docs/composer-3/manage-dags#delete-md).\n\nWhat's next\n-----------\n\n- [Configure database retention policy](/composer/docs/composer-3/configure-db-retention)\n- [Access Airflow command-line interface](/composer/docs/composer-3/access-airflow-cli)"]]