Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Nesta página, descrevemos como usar a ferramenta pg_dump para exportar
um banco de dados do AlloyDB para um arquivo DMP de formato personalizado e arquivado que você
pode importar mais tarde usando a ferramenta pg_restore.
O procedimento para realizar a exportação envolve estas tarefas:
Você precisa ter o papel básico de proprietário (roles/owner) ou editor (roles/editor) do IAM no projeto Google Cloud que está usando ou ter estes papéis predefinidos do IAM:
Administrador do AlloyDB (roles/alloydb.admin) ou leitor do AlloyDB
(roles/alloydb.viewer)
Administrador do Storage (roles/storage.admin)
Administrador da instância do Compute (v1) (roles/compute.instanceAdmin.v1)
Para preparar um host cliente para realizar a operação de exportação, crie uma VM do Compute Engine que possa se conectar à instância principal do AlloyDB em que o banco de dados está localizado e instale a ferramenta pg_dump e a Google Cloud CLI nessa VM.
Siga as instruções em
Conectar um cliente psql a uma instância
para criar uma VM do Compute Engine com a conectividade adequada e a
ferramenta pg_dump instalada. Ao seguir estas instruções, aloque armazenamento local suficiente para a VM do Compute Engine acomodar o arquivo DMP que você vai criar.
Instale a gcloud CLI para fornecer
acesso de linha de comando e criar o arquivo DMP no bucket do Cloud Storage.
Exportar o banco de dados
Para exportar o banco de dados para um arquivo DMP, extraia o endereço IP da instância primária do AlloyDB em que o banco de dados está localizado e use a ferramenta pg_dump.
Para conferir o endereço IP da instância primária do AlloyDB em que seu banco de dados está localizado, consulte os detalhes dela.
Conecte-se por SSH à VM do Compute Engine.
Console
No console Google Cloud , acesse a página Instâncias de VM.
Será necessário inserir a senha do usuário postgres.
IP_ADDRESS: o endereço IP da instância principal.
-F custom: define o formato do arquivo DMP como um arquivo
de formato personalizado que pode ser importado mais tarde usando a ferramenta pg_restore.
DB_NAME: o nome do banco de dados que você quer
exportar.
DMP_FILE_NAME: forneça um nome para o arquivo DMP
a ser criado no sistema de arquivos local do host do cliente.
O exemplo acima mostra um comando pg_dump simples. Para informações sobre a ampla variedade de opções compatíveis com o comando, consulte a documentação do PostgreSQL.
Copie o arquivo DMP para o bucket do Cloud Storage criado anteriormente:
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-09-04 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)."]]