Postgres 到 Google Cloud Storage Operator¶
Google Cloud Storage (GCS) 服務用於儲存來自各種應用程式的大量資料。本頁展示瞭如何將資料從 Postgres 複製到 GCS。
先決條件任務¶
要使用這些 operators,您必須執行以下幾項操作:
使用 Cloud Console 選擇或建立一個 Cloud Platform 專案。
為您的專案啟用賬單功能,如 Google Cloud 文件中所述。
啟用 API,如 Cloud Console 文件中所述。
透過 pip 安裝 API 庫。
pip install 'apache-airflow[google]'詳細資訊請參閱 安裝。
PostgresToGCSOperator¶
PostgresToGCSOperator 允許您將資料從 Postgres 資料庫上傳到 GCS。
使用此 operator 時,您可以選擇將要上傳的資料壓縮為 gzip 格式。
以下是使用此 operator 將資料上傳到 GCS 的示例。
tests/system/google/cloud/transfers/example_postgres_to_gcs.py
postgres_to_gcs = PostgresToGCSOperator(
task_id="postgres_to_gcs",
postgres_conn_id=CONNECTION_ID,
sql=SQL_SELECT,
bucket=BUCKET_NAME,
filename=FILE_NAME,
export_format="csv",
)
參考¶
更多資訊,請參閱: * Google Cloud Storage 文件