Stay organized with collections
Save and categorize content based on your preferences.
This page describes how to use the pg_dump tool to export
an AlloyDB database to a custom-format, archive DMP file that you
can later import using the pg_restore tool.
The procedure to perform the export involves these tasks:
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:
AlloyDB Admin (roles/alloydb.admin) or AlloyDB Viewer
(roles/alloydb.viewer)
To prepare a client host to perform the export operation, you create a
Compute Engine VM that can connect to the AlloyDB primary
instance where your database is located, and install the pg_dump tool and the
Google Cloud CLI on that VM.
Follow the instructions
Connect a psql client to an instance
to create a Compute Engine VM with the proper connectivity and the
pg_dump tool installed. When following these instructions, make sure to
allocate enough local storage to the Compute Engine VM to
accommodate the DMP file you will create.
Install the gcloud CLI to provide
command-line access to create the DMP file in the Cloud Storage
bucket.
Export the database
To export the database to a DMP file, you get the IP address of the
AlloyDB primary instance where your database is located and then
use the pg_dump tool.
Get the IP address of the AlloyDB primary instance where your
database is located by viewing its
details.
SSH into the Compute Engine VM.
Console
In the Google Cloud console, go to the VM instances
page.
You will be prompted to enter the password of the postgres user.
IP_ADDRESS: The IP address of the primary instance.
-F custom: Sets the format of the DMP file to a custom-format
archive that you can later import using the pg_restore tool.
DB_NAME: The name of the database you want to
export.
DMP_FILE_NAME: Provide a file name for the DMP file
to create on the client host's local file system.
The above shows a simple pg_dump command. For information about
the wide range of options the command supports, see the
PostgreSQL documentation
provides.
Copy the DMP file to the Cloud Storage bucket you created earlier:
gcloudstoragecpDMP_FILE_NAMEgs://BUCKET_NAME
Clean up resources
After successfully exporting the DMP file, you can delete the
Compute Engine VM
you used during the export procedure.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-26 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)."]]