Stay organized with collections Save and categorize content based on your preferences.
MySQL | PostgreSQL | SQL ServerThis page describes exporting and importing files into Cloud SQL instances in parallel.
Note: If you're exporting because you want to create a new instance from the exported file, consider restoring from a backup to a different instance or cloning the instance.
You can verify that the import or export operation for multiple files in parallel completed successfully by checking the operation's status. You can also cancel the import of data into Cloud SQL instances and the export of data from the instances. For more information about cancelling an import or export operation, see Cancel the import and export of data.
Before you beginBefore you begin an export or import operation:
Export and import operations use database resources, but they don't interfere with typical database operations unless the instance is under-provisioned.
Important: Before starting a large operation, ensure that at least 25 percent of the disk is free on the instance. Doing so helps prevent issues with aggressive autogrowth, which can adversely affect the availability of the instance.The following sections contain information about exporting data from Cloud SQL for PostgreSQL to multiple files in parallel.
Required roles and permissions for exporting data from Cloud SQL for PostgreSQL to multiple files in parallelTo export data from Cloud SQL into Cloud Storage, the user initiating the export must have one of the following roles:
cloudsql.instances.get
cloudsql.instances.export
Additionally, the service account for the Cloud SQL instance must have one of the following roles:
storage.objectAdmin
Identity and Access Management (IAM) rolestorage.objects.create
storage.objects.list
(for exporting files in parallel only)storage.objects.delete
(for exporting files in parallel only)For help with IAM roles, see Identity and Access Management.
Note: The changes that you make to the IAM permissions and roles might take a few minutes to take effect. For more information, see Access change propagation. Export data to multiple files in parallelYou can export data in parallel from multiple files that reside in Cloud SQL to Cloud Storage. To do this, use the
pg_dump
utility with the
--jobs
option.
If you plan to import your data into Cloud SQL, then follow the instructions provided in Exporting data from an external database server so that your files are formatted correctly for Cloud SQL.
Note: If your data contains large objects (blobs), then the export might consume a large amount of memory, impacting instance performance. For help, see Issues with importing and exporting data. gcloudTo export data from Cloud SQL to multiple files in parallel, complete the following steps:
Note: You don't have to create a folder in the bucket. If the folder doesn't exist, then Cloud SQL creates it for you as a part of the process of exporting multiple files in parallel. However, if the folder exists, then it must be empty or the export operation fails.
gcloud sql instances describe
command.
gcloud sql instances describe INSTANCE_NAME
Replace INSTANCE_NAME with the name of your Cloud SQL instance.
In the output, look for the value that's associated with the serviceAccountEmailAddress
field.
storage.objectAdmin
IAM role to the service account, use the gcloud storage buckets add-iam-policy-binding
command. For help with setting IAM permissions, see Use IAM permissions.gcloud sql export sql
command:
gcloud sql export sql INSTANCE_NAME gs://BUCKET_NAME/BUCKET_PATH/FOLDER_NAME \ --offload \ --parallel \ --threads=THREAD_NUMBER \ --database=DATABASE_NAME \ --table=TABLE_EXPRESSION
Make the following replacements:
3
as the value for this parameter.offload
parameter. If you want to export multiple files in parallel, then use the parallel
parameter. Otherwise, remove these parameters from the command.
The export sql
command doesn't contain triggers or stored procedures, but does contain views. To export triggers or stored procedures, use a single thread for the export. This thread uses the pg_dump
tool.
After the export completes, you should have files in a folder in the Cloud Storage bucket in the pg_dump
directory format.
To export data from Cloud SQL to multiple files in parallel, complete the following steps:
gcloud storage buckets create gs://BUCKET_NAME --project=PROJECT_NAME --location=LOCATION_NAMEMake the following replacements:
my-bucket
.us-east1
.Note: You don't have to create a folder in the bucket. If the folder doesn't exist, then Cloud SQL creates it for you as a part of the process of exporting multiple files in parallel. However, if the folder exists, then it must be empty or the export operation fails.
legacyBucketWriter
IAM role for your bucket. For help with setting IAM permissions, see Use IAM permissions.Export data from Cloud SQL to multiple files in parallel:
Before using any of the request data, make the following replacements:
3
as the value for this parameter.offload
parameter enables you to use serverless exports for up to 2 threads. The parallel
parameter enables you to export multiple files in parallel. To use these features, set the values of these parameters to TRUE. Otherwise, set their values to FALSE.
HTTP method and URL:
POST https://sqladmin.googleapis.com/v1/projects/PROJECT_NAME/instances/INSTANCE_NAME/export
Request JSON body:
{ "exportContext": { "fileType": "SQL", "uri": "gs://BUCKET_NAME/BUCKET_PATH/FOLDER_NAME", "databases": ["DATABASE_NAME"], "offload": [TRUE|FALSE], "sqlExportOptions": { "parallel": [TRUE|FALSE], "threads": [THREAD_NUMBER] } } }
To send your request, expand one of these options:
curl (Linux, macOS, or Cloud Shell) Note: The following command assumes that you have logged in to thegcloud
CLI with your user account by running gcloud init
or gcloud auth login
, or by using Cloud Shell, which automatically logs you into the gcloud
CLI . You can check the currently active account by running gcloud auth list
.
Save the request body in a file named request.json
, and execute the following command:
curl -X POST \PowerShell (Windows) Note: The following command assumes that you have logged in to the
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://sqladmin.googleapis.com/v1/projects/PROJECT_NAME/instances/INSTANCE_NAME/export"
gcloud
CLI with your user account by running gcloud init
or gcloud auth login
. You can check the currently active account by running gcloud auth list
.
Save the request body in a file named request.json
, and execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_NAME/instances/INSTANCE_NAME/export" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
Response{ "kind": "sql#operation", "targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_NAME/instances/DESTINATION_INSTANCE_NAME", "status": "PENDING", "user": "user@example.com", "insertTime": "2020-01-21T22:43:37.981Z", "operationType": "UPDATE", "name": "OPERATION_ID", "targetId": "INSTANCE_NAME", "selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_NAME/operations/OPERATION_ID", "targetProject": "PROJECT_NAME" }
After the export completes, you should have files in a folder in the Cloud Storage bucket in the pg_dump
directory format.
To export data from Cloud SQL to multiple files in parallel, complete the following steps:
gcloud storage buckets create gs://BUCKET_NAME --project=PROJECT_NAME --location=LOCATION_NAMEMake the following replacements:
my-bucket
.us-east1
.Note: You don't have to create a folder in the bucket. If the folder doesn't exist, then Cloud SQL creates it for you as a part of the process of exporting multiple files in parallel. However, if the folder exists, then it must be empty or the export operation fails.
storage.objectAdmin
IAM role for your bucket. For help with setting IAM permissions, see Use IAM permissions.Export data from Cloud SQL to multiple files in parallel:
Before using any of the request data, make the following replacements:
3
as the value for this parameter.offload
parameter enables you to use serverless exports for up to 2 threads. The parallel
parameter enables you to export multiple files in parallel. To use these features, set the values of these parameters to TRUE. Otherwise, set their values to FALSE.
HTTP method and URL:
POST https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_NAME/instances/INSTANCE_NAME/export
Request JSON body:
{ "exportContext": { "fileType": "SQL", "uri": "gs://BUCKET_NAME/BUCKET_PATH/FOLDER_NAME", "databases": ["DATABASE_NAME"], "offload": [TRUE|FALSE], "sqlExportOptions": { "parallel": [TRUE|FALSE], "threads": [THREAD_NUMBER] } } }
To send your request, expand one of these options:
curl (Linux, macOS, or Cloud Shell) Note: The following command assumes that you have logged in to thegcloud
CLI with your user account by running gcloud init
or gcloud auth login
, or by using Cloud Shell, which automatically logs you into the gcloud
CLI . You can check the currently active account by running gcloud auth list
.
Save the request body in a file named request.json
, and execute the following command:
curl -X POST \PowerShell (Windows) Note: The following command assumes that you have logged in to the
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_NAME/instances/INSTANCE_NAME/export"
gcloud
CLI with your user account by running gcloud init
or gcloud auth login
. You can check the currently active account by running gcloud auth list
.
Save the request body in a file named request.json
, and execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_NAME/instances/INSTANCE_NAME/export" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
Response{ "kind": "sql#operation", "targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_NAME/instances/DESTINATION_INSTANCE_NAME", "status": "PENDING", "user": "user@example.com", "insertTime": "2020-01-21T22:43:37.981Z", "operationType": "UPDATE", "name": "OPERATION_ID", "targetId": "INSTANCE_NAME", "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_NAME/operations/OPERATION_ID", "targetProject": "PROJECT_NAME" }
After the export completes, you should have files in a folder in the Cloud Storage bucket in the pg_dump
directory format.
You can export or import all user databases in an entire instance using a directory-formatted, parallel export.
To export or import an entire instance, use the same commands as shown in the parallel export and parallel import sections, removing the databases
or database
field, respectively. If you don't specify a database, Cloud SQL runs a parallel export or import for all user databases in the instance. This excludes system databases and Cloud SQL databases used to manage internal operations.
In a directory-formatted parallel export to Cloud Storage, after the export successfully completes, the data associated with each database is stored in a subdirectory named for each database, similar to the following:
gs://example-bucket/test-folder/ |---- postgres/ | |---- 3929.dat.gz (table data file) | |---- toc.dat (metadata file) | |---- second_database/ | |---- 3930.dat.gz | |---- 3931.dat.gz | |---- toc.dat
If you want to run a parallel import for an entire instance, and the instance's files were created outside of Cloud SQL, this subdirectory structure is required in order for the operation to successfully complete.
When the entire instance dump structure is detected, the import database specified in the API is ignored. The operation detects the entire instance's structure from the directory name.
You can't run an entire instance export or import for other file formats.
You can't export or import an entire instance as a single SQL file or CSV file.
Import data from multiple files in parallel to Cloud SQL for PostgreSQLThe following sections contain information about importing data from multiple files in parallel to Cloud SQL for PostgreSQL.
Required roles and permissions for importing data from multiple files in parallel to Cloud SQL for PostgreSQLTo import data from Cloud Storage into Cloud SQL, the user initiating the import must have one of the following roles:
cloudsql.instances.get
cloudsql.instances.import
Additionally, the service account for the Cloud SQL instance must have one of the following roles:
storage.objectAdmin
IAM rolestorage.objects.get
storage.objects.list
(for importing files in parallel only)For help with IAM roles, see Identity and Access Management.
Note: The changes that you make to the IAM permissions and roles might take a few minutes to take effect. For more information, see Access change propagation. Import data to Cloud SQL for PostgreSQLYou can import data in parallel from multiple files that reside in Cloud Storage to your database. To do this, use the pg_restore
utility with the --jobs
option.
To import data from multiple files in parallel into Cloud SQL, complete the following steps:
Upload the files to your bucket.
Note: Make sure that the files that you're uploading are in the pg_dump
directory format. For more information, see Export data from multiple files in parallel.
For help with uploading files to buckets, see Upload objects from files.
gcloud sql instances describe
command.
gcloud sql instances describe INSTANCE_NAME
Replace INSTANCE_NAME with the name of your Cloud SQL instance.
In the output, look for the value that's associated with the serviceAccountEmailAddress
field.
storage.objectAdmin
IAM role to the service account, use the gcloud storage buckets add-iam-policy-binding
utility. For help with setting IAM permissions, see Use IAM permissions.gcloud sql import sql
command:
gcloud sql import sql INSTANCE_NAME gs://BUCKET_NAME/BUCKET_PATH/FOLDER_NAME \ --parallel \ --threads=THREAD_NUMBER \ --database=DATABASE_NAME
Make the following replacements:
3
as the value for this parameter.Note: If you want to import multiple files in parallel, then use the parallel
parameter.
If you use the parallel
parameter, and you want to drop (clean) database objects before you recreate them, then use the clean
parameter. If you use the parallel
parameter, and you want to include the IF EXISTS
SQL statement with each DROP
statement that's produced by the clean
parameter, then use the if-exists
parameter.
Otherwise, remove these parameters from the command.
If the command returns an error like ERROR_RDBMS
, then review the permissions; this error is often due to permissions issues.
gcloud storage buckets remove-iam-policy-binding
to remove them.To import data from multiple files in parallel into Cloud SQL, complete the following steps:
gcloud storage buckets create gs://BUCKET_NAME --project=PROJECT_NAME --location=LOCATION_NAMEMake the following replacements:
my-bucket
.us-east1
.Upload the files to your bucket.
Note: Make sure that the files that you're uploading are in the pg_dump
directory format. For more information, see Export data from multiple files in parallel.
For help with uploading files to buckets, see Upload objects from files.
storage.objectAdmin
IAM role for your bucket. For help with setting IAM permissions, see Use IAM permissions.Import data from multiple files in parallel into Cloud SQL:
Before using any of the request data, make the following replacements:
3
as the value for this parameter.Note: The offload
parameter enables you to use serverless imports for up to 2 threads. The parallel
parameter enables you to import multiple files in parallel.
If you use the parallel
parameter, then the clean
parameter enables you to drop (clean) database objects before you recreate them. If you use the parallel
parameter, then the ifExists
parameter enables you to include the IF EXISTS
SQL statement with each DROP
statement that's produced by the clean
parameter.
To use these features, set the values of these parameters to TRUE. Otherwise, set their values to FALSE.
HTTP method and URL:
POST https://sqladmin.googleapis.com/v1/projects/PROJECT_NAME/instances/INSTANCE_NAME/import
Request JSON body:
{ "importContext": { "fileType": "SQL", "uri": "gs://BUCKET_NAME/BUCKET_PATH/FOLDER_NAME", "databases": ["DATABASE_NAME"], "offload": [TRUE|FALSE], "sqlImportOptions": { "parallel": [TRUE|FALSE], "clean": [TRUE|FALSE], "ifExists": [TRUE|FALSE], "threads": [THREAD_NUMBER] } } }
To send your request, expand one of these options:
curl (Linux, macOS, or Cloud Shell) Note: The following command assumes that you have logged in to thegcloud
CLI with your user account by running gcloud init
or gcloud auth login
, or by using Cloud Shell, which automatically logs you into the gcloud
CLI . You can check the currently active account by running gcloud auth list
.
Save the request body in a file named request.json
, and execute the following command:
curl -X POST \PowerShell (Windows) Note: The following command assumes that you have logged in to the
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://sqladmin.googleapis.com/v1/projects/PROJECT_NAME/instances/INSTANCE_NAME/import"
gcloud
CLI with your user account by running gcloud init
or gcloud auth login
. You can check the currently active account by running gcloud auth list
.
Save the request body in a file named request.json
, and execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_NAME/instances/INSTANCE_NAME/import" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
Response{ "kind": "sql#operation", "targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_NAME/instances/DESTINATION_INSTANCE_NAME", "status": "PENDING", "user": "user@example.com", "insertTime": "2020-01-21T22:43:37.981Z", "operationType": "UPDATE", "name": "OPERATION_ID", "targetId": "INSTANCE_NAME", "selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_NAME/operations/OPERATION_ID", "targetProject": "PROJECT_NAME" }
To use a different user for the import, specify the importContext.importUser
property.
gcloud storage buckets remove-iam-policy-binding
to remove them.To import data from multiple files in parallel into Cloud SQL, complete the following steps:
gcloud storage buckets create gs://BUCKET_NAME --project=PROJECT_NAME --location=LOCATION_NAMEMake the following replacements:
my-bucket
.us-east1
.Upload the files to your bucket.
Note: Make sure that the files that you're uploading are in the pg_dump
directory format. For more information, see Export data from multiple files in parallel.
For help with uploading files to buckets, see Upload objects from files.
storage.objectAdmin
IAM role for your bucket. For help with setting IAM permissions, see Use IAM permissions.Import data from multiple files in parallel into Cloud SQL:
Before using any of the request data, make the following replacements:
3
as the value for this parameter.Note: The offload
parameter enables you to use serverless imports for up to 2 threads. The parallel
parameter enables you to import multiple files in parallel.
If you use the parallel
parameter, then the clean
parameter enables you to drop (clean) database objects before you recreate them. If you use the parallel
parameter, then the ifExists
parameter enables you to include the IF EXISTS
SQL statement with each DROP
statement that's produced by the clean
parameter.
To use these features, set the values of these parameters to TRUE. Otherwise, set their values to FALSE.
HTTP method and URL:
POST https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_NAME/instances/INSTANCE_NAME/import
Request JSON body:
{ "importContext": { "fileType": "SQL", "uri": "gs://BUCKET_NAME/BUCKET_PATH/FOLDER_NAME", "databases": ["DATABASE_NAME"], "offload": [TRUE|FALSE], "sqlImportOptions": { "parallel": [TRUE|FALSE], "clean": [TRUE|FALSE], "ifExists": [TRUE|FALSE], "threads": [THREAD_NUMBER] } } }
To send your request, expand one of these options:
curl (Linux, macOS, or Cloud Shell) Note: The following command assumes that you have logged in to thegcloud
CLI with your user account by running gcloud init
or gcloud auth login
, or by using Cloud Shell, which automatically logs you into the gcloud
CLI . You can check the currently active account by running gcloud auth list
.
Save the request body in a file named request.json
, and execute the following command:
curl -X POST \PowerShell (Windows) Note: The following command assumes that you have logged in to the
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_NAME/instances/INSTANCE_NAME/import"
gcloud
CLI with your user account by running gcloud init
or gcloud auth login
. You can check the currently active account by running gcloud auth list
.
Save the request body in a file named request.json
, and execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_NAME/instances/INSTANCE_NAME/import" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
Response{ "kind": "sql#operation", "targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_NAME/instances/DESTINATION_INSTANCE_NAME", "status": "PENDING", "user": "user@example.com", "insertTime": "2020-01-21T22:43:37.981Z", "operationType": "UPDATE", "name": "OPERATION_ID", "targetId": "INSTANCE_NAME", "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_NAME/operations/OPERATION_ID", "targetProject": "PROJECT_NAME" }
To use a different user for the import, specify the importContext.importUser
property.
gcloud storage buckets remove-iam-policy-binding
to remove them.If you specify too many threads when you import or export data from multiple files in parallel, then you might use more memory than your Cloud SQL instance has. If this occurs, then an internal error message appears. Check the memory usage of your instance and increase the instance's size, as needed. For more information, see About instance settings.
When performing an export, commas in database names or table names in the databases
or tables
fields aren't supported.
Make sure that you have enough disk space for the initial dump file download. Otherwise, a no space left on disk
error appears.
If your instance has only one virtual CPU (vCPU), then you can't import or export multiple files in parallel. The number of vCPUs for your instance can't be smaller than the number of threads that you're using for the import or export operation, and the number of threads must be at least two.
Multi-threaded (parallel) imports and exports aren't compatible with single-threaded imports and exports. For example, dump files generated by a single-threaded export can only be imported by single-threaded imports. Similarly, dump files generated by parallel exports can only be imported by parallel imports.
pg_dump
utility can't chunk any tables that you export. Therefore, if you have one very large table, then it can become a bottleneck for the speed of the export operation.Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-07-02 UTC.
[[["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-07-02 UTC."],[],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4