Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Esta página descreve como importar para um banco de dados do AlloyDB um arquivo DMP
criado pela ferramenta pg_dump usando o formato custom ou directory.
Para importar um arquivo criado pela ferramenta pg_dump usando o formato plain, consulte
Importar um arquivo SQL.
O procedimento para realizar a importaçã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)
Fazer upload do arquivo DMP
Para enviar o arquivo DMP, crie um bucket do Cloud Storage e faça o upload do arquivo para ele.
Para preparar um host cliente para realizar a operação de importaçã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_restore 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_restore instalada. Ao seguir estas instruções, aloque armazenamento local suficiente para a VM do Compute Engine acomodar o arquivo da DMP que você está importando.
Instale a gcloud CLI para fornecer
acesso de linha de comando ao arquivo DMP no bucket do Cloud Storage.
Importar o arquivo DMP
Para importar o arquivo DMP, receba o endereço IP da instância primária do AlloyDB em que o banco de dados está localizado e use a ferramenta pg_restore para importar o arquivo para o banco de dados.
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.
[[["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-03 UTC."],[[["\u003cp\u003eThis page provides instructions on importing a DMP file, created using the \u003ccode\u003epg_dump\u003c/code\u003e tool in \u003ccode\u003ecustom\u003c/code\u003e or \u003ccode\u003edirectory\u003c/code\u003e format, into an AlloyDB database.\u003c/p\u003e\n"],["\u003cp\u003eThe import process involves uploading the DMP file to a Cloud Storage bucket, preparing a Compute Engine VM client host, and then using the \u003ccode\u003epg_restore\u003c/code\u003e tool to import the file.\u003c/p\u003e\n"],["\u003cp\u003eUsers must have specific IAM roles, such as Owner, Editor, AlloyDB Admin, or others, to perform the import.\u003c/p\u003e\n"],["\u003cp\u003eA TOC file needs to be generated by running the \u003ccode\u003epg_restore\u003c/code\u003e command with \u003ccode\u003e-l\u003c/code\u003e flag, then using the \u003ccode\u003esed\u003c/code\u003e command to comment out all EXTENSION statements before importing.\u003c/p\u003e\n"],["\u003cp\u003eAfter a successful import, resources like the Cloud Storage bucket and the Compute Engine VM used for the import can be deleted.\u003c/p\u003e\n"]]],[],null,["# Import a DMP file\n\nThis page describes how to import into an AlloyDB database a DMP\nfile created by the `pg_dump` tool using the `custom` or `directory` format.\n\nTo import a file created by the `pg_dump` tool using the `plain` format, see\n[Import a SQL file](/alloydb/docs/import-sql-file).\n\nThe procedure to perform the import involves these tasks:\n\n1. [Upload the DMP file](#upload) to a Cloud Storage bucket.\n\n2. [Prepare a client host](#prepare-host) to perform the import operation.\n\n3. [Import the DMP file](#import) into the database.\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\nUpload the DMP file\n-------------------\n\nTo upload the DMP file, you create a Cloud Storage bucket and then\nupload the DMP file to that bucket.\n\n1. [Create a standard storage, regional storage bucket](/storage/docs/creating-buckets)\n in the project and region where your AlloyDB database is\n located.\n\n2. [Upload the DMP file](/storage/docs/uploading-objects) to the storage bucket\n you created.\n\nPrepare a client host\n---------------------\n\nTo prepare a client host to perform the import operation, you create a\nCompute Engine VM that can connect to the AlloyDB primary\ninstance where your database is located, and install the `pg_restore` tool and\nthe Google 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_restore` 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 are importing.\n\n2. [Install the gcloud CLI](/sdk/docs/install) to provide\n command-line access to the DMP file in the Cloud Storage bucket.\n\nImport the DMP file\n-------------------\n\nTo import the DMP file, you get the IP address of the AlloyDB\nprimary instance where your database is located and then use the `pg_restore`\ntool to import the file into the database.\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. Copy the DMP file to the client host's local file system: \n\n ```bash\n gcloud storage cp gs://BUCKET_NAME/DMP_FILE_NAME .\n ```\n4. Run the following command to create a TOC file that comments out all `EXTENSION` statements: \n\n ```bash\n pg_restore \\\n -l DMP_FILE_NAME | sed -E 's/(.* EXTENSION )/; \\1/g' \u003e TOC_FILE_NAME\n ```\n - \u003cvar translate=\"no\"\u003eDMP_FILE_NAME\u003c/var\u003e: The DMP file on the local file system.\n - \u003cvar translate=\"no\"\u003eTOC_FILE_NAME\u003c/var\u003e: Provide a file name for the TOC file to create on the local file system.\n5. Import the DMP file: \n\n ```\n pg_restore -h IP_ADDRESS -U postgres \\\n -d DB_NAME \\\n -L TOC_FILE_NAME \\\n DMP_FILE_NAME\n ```\n - \u003cvar translate=\"no\"\u003eIP_ADDRESS\u003c/var\u003e: The IP address of the primary instance.\n - \u003cvar translate=\"no\"\u003eDB_NAME\u003c/var\u003e: The name of the database to import into.\n - \u003cvar translate=\"no\"\u003eTOC_FILE_NAME\u003c/var\u003e: The TOC file you created in the previous step.\n - \u003cvar translate=\"no\"\u003eDMP_FILE_NAME\u003c/var\u003e: The DMP file.\n\n The [`pg_restore`\n command](https://www.postgresql.org/docs/16/app-pgrestore.html) provides several additional options to control the data import\n operation.\n\nClean up resources\n------------------\n\nAfter successfully importing the DMP file, you can [delete the\nCloud Storage bucket](/storage/docs/deleting-buckets) and delete the\n[Compute Engine VM](/compute/docs/instances/deleting-instance)\nyou used during the import procedure."]]