Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Halaman ini menjelaskan cara menggunakan alat pg_dump untuk mengekspor database AlloyDB ke file DMP arsip berformat kustom yang dapat Anda impor nanti menggunakan alat pg_restore.
Prosedur untuk melakukan ekspor melibatkan tugas-tugas berikut:
Anda harus memiliki peran IAM dasar Pemilik (roles/owner) atau Editor
(roles/editor) di Google Cloud project
yang Anda gunakan, atau Anda harus memiliki peran IAM bawaan berikut:
Admin AlloyDB (roles/alloydb.admin) atau Pelihat AlloyDB
(roles/alloydb.viewer)
Untuk menyiapkan host klien guna melakukan operasi ekspor, Anda membuat VM Compute Engine yang dapat terhubung ke instance utama AlloyDB tempat database Anda berada, dan menginstal alat pg_dump serta Google Cloud CLI di VM tersebut.
Ikuti petunjuk di
Menghubungkan klien psql ke instance
untuk membuat VM Compute Engine dengan konektivitas yang tepat dan alat
pg_dump yang diinstal. Saat mengikuti petunjuk ini, pastikan untuk mengalokasikan penyimpanan lokal yang cukup ke VM Compute Engine untuk mengakomodasi file DMP yang akan Anda buat.
Instal gcloud CLI untuk menyediakan
akses command line guna membuat file DMP di bucket Cloud Storage.
Mengekspor database
Untuk mengekspor database ke file DMP, Anda akan mendapatkan alamat IP instance utama AlloyDB tempat database Anda berada, lalu menggunakan alat pg_dump.
Dapatkan alamat IP instance utama AlloyDB tempat database Anda berada dengan melihat detailnya.
Gunakan SSH untuk terhubung ke VM Compute Engine.
Konsol
Di konsol Google Cloud , buka halaman VM instances.
Anda akan diminta untuk memasukkan sandi pengguna postgres.
IP_ADDRESS: Alamat IP instance utama.
-F custom: Menetapkan format file DMP ke arsip format kustom
yang dapat Anda impor nanti menggunakan alat pg_restore.
DB_NAME: Nama database yang ingin Anda
ekspor.
DMP_FILE_NAME: Berikan nama file untuk file DMP
yang akan dibuat di sistem file lokal host klien.
Di atas menunjukkan perintah pg_dump sederhana. Untuk mengetahui informasi tentang
berbagai opsi yang didukung perintah, lihat
dokumentasi PostgreSQL
yang tersedia.
Salin file DMP ke bucket Cloud Storage yang telah Anda buat sebelumnya:
gcloudstoragecpDMP_FILE_NAMEgs://BUCKET_NAME
Membersihkan resource
Setelah berhasil mengekspor file DMP, Anda dapat menghapus VM Compute Engine yang Anda gunakan selama prosedur ekspor.
[[["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-09-03 UTC."],[[["\u003cp\u003eThis page provides instructions on using the \u003ccode\u003epg_dump\u003c/code\u003e tool to export an AlloyDB database into a custom-format DMP file for later import with \u003ccode\u003epg_restore\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe process requires creating a Cloud Storage bucket, preparing a Compute Engine VM client host with the necessary tools, and then running the \u003ccode\u003epg_dump\u003c/code\u003e command.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003epg_dump\u003c/code\u003e command requires the IP address of the AlloyDB primary instance and database name to perform the database export to the local file system of the client host.\u003c/p\u003e\n"],["\u003cp\u003eAfter exporting, the resulting DMP file must be copied to the previously created Cloud Storage bucket, and then the Compute Engine VM can be deleted.\u003c/p\u003e\n"],["\u003cp\u003eYou must have specific IAM roles, such as AlloyDB Admin or Storage Admin, in your Google Cloud project to perform the database export.\u003c/p\u003e\n"]]],[],null,["# Export a DMP file\n\nThis page describes how to use the `pg_dump` tool to export\nan AlloyDB database to a custom-format, archive DMP file that you\ncan later import using the `pg_restore` tool.\n\nThe procedure to perform the export involves these tasks:\n\n1. [Create a Cloud Storage bucket](#bucket) to store the DMP file in.\n\n2. [Prepare a client host](#prepare-host) to perform the export operation.\n\n3. [Export the database](#export) to the DMP file.\n\n4. [Clean up the resources](#clean-up) created to perform the procedure.\n\n\nBefore you begin\n----------------\n\n- You must have the Owner (`roles/owner`) or Editor (`roles/editor`) basic IAM role in the Google Cloud project you are using, or you must have these predefined IAM roles:\n - AlloyDB Admin (`roles/alloydb.admin`) or AlloyDB Viewer (`roles/alloydb.viewer`)\n - Storage Admin (`roles/storage.admin`)\n - Compute Instance Admin (v1) (`roles/compute.instanceAdmin.v1`)\n\n\u003cbr /\u003e\n\nCreate a Cloud Storage bucket\n-----------------------------\n\n[Create a standard storage, regional storage bucket](/storage/docs/creating-buckets)\nin the project and region where your AlloyDB database is located.\n\nPrepare a client host\n---------------------\n\nTo prepare a client host to perform the export operation, you create a\nCompute Engine VM that can connect to the AlloyDB primary\ninstance where your database is located, and install the `pg_dump` tool and the\nGoogle Cloud CLI on that VM.\n\n1. Follow the instructions\n [Connect a psql client to an instance](/alloydb/docs/connect-psql)\n to create a Compute Engine VM with the proper connectivity and the\n `pg_dump` tool installed. When following these instructions, make sure to\n allocate enough local storage to the Compute Engine VM to\n accommodate the DMP file you will create.\n\n2. [Install the gcloud CLI](/sdk/docs/install) to provide\n command-line access to create the DMP file in the Cloud Storage\n bucket.\n\nExport the database\n-------------------\n\nTo export the database to a DMP file, you get the IP address of the\nAlloyDB primary instance where your database is located and then\nuse the `pg_dump` tool.\n\n1. Get the IP address of the AlloyDB primary instance where your database is located by [viewing its\n details](/alloydb/docs/instance-view).\n2. SSH into the Compute Engine VM. \n\n ### Console\n\n 1. In the Google Cloud console, go to the **VM instances** page.\n\n [Go to VM instances](https://console.cloud.google.com/compute/instances)\n 2. In the list of virtual machine instances, click **SSH** in the row of the instance you created.\n\n ### gcloud\n\n Use the [`gcloud compute\n ssh` command](/sdk/gcloud/reference/compute/ssh) to connect to the instance you created. \n\n ```\n gcloud compute ssh --project=PROJECT_ID --zone=ZONE VM_NAME\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: The ID of the project that contains the instance.\n - \u003cvar translate=\"no\"\u003eZONE\u003c/var\u003e: The name of the zone in which the instance is located.\n - \u003cvar translate=\"no\"\u003eVM_NAME\u003c/var\u003e: The name of the instance.\n3. Export the database to a DMP file: \n\n ```\n pg_dump -h IP_ADDRESS -U postgres -F custom \\\n DB_NAME \u003e DMP_FILE_NAME\n ```\n\n You will be prompted to enter the password of the `postgres` user.\n - \u003cvar translate=\"no\"\u003eIP_ADDRESS\u003c/var\u003e: The IP address of the primary instance.\n - `-F custom`: Sets the format of the DMP file to a custom-format archive that you can later import using the `pg_restore` tool.\n - \u003cvar translate=\"no\"\u003eDB_NAME\u003c/var\u003e: The name of the database you want to export.\n - \u003cvar translate=\"no\"\u003eDMP_FILE_NAME\u003c/var\u003e: Provide a file name for the DMP file to create on the client host's local file system.\n\n The above shows a simple `pg_dump` command. For information about\n the wide range of options the command supports, see the\n [PostgreSQL documentation](https://www.postgresql.org/docs/16/app-pgdump.html)\n provides.\n4. Copy the DMP file to the Cloud Storage bucket you created earlier: \n\n ```bash\n gcloud storage cp DMP_FILE_NAME gs://BUCKET_NAME\n ```\n\nClean up resources\n------------------\n\nAfter successfully exporting the DMP file, you can [delete the\nCompute Engine VM](/compute/docs/instances/deleting-instance)\nyou used during the export procedure.\n\nWhat's next\n-----------\n\n- Learn how to [export a CSV file](/alloydb/docs/export-csv-file).\n- Learn how to [export a SQL dump file](/alloydb/docs/export-sql-file)."]]