首页 > 解决方案 > 是否可以在不使用 pg_restore 的情况下在云 sql 中导入 postgresql 自定义格式转储文件?

问题描述

我从 chembl 数据库下载了 postgresql .dmp 文件。

我想将其导入 gcp cloudsql。

当我使用控制台和 gcloud 命令运行它时,我收到以下错误:

Importing data into Cloud SQL instance...failed.
ERROR: (gcloud.sql.import.sql) [ERROR_RDBMS] exit status 1
The input is a PostgreSQL custom-format dump.
Use the pg_restore command-line client to restore this dump to a database.

我可以在不使用 pg_restore 命令的情况下导入自定义格式的 dmp 文件吗?

https://cloud.google.com/sql/docs/postgres/import-export/importing

该站点上的文档中有对 pg_restore 的描述,但我没有正确理解。

如果是自定义格式的文件,上传到云shell后是否需要pg_restore?

标签: postgresqlgoogle-cloud-platformgoogle-cloud-sqlpg-restore

解决方案


根据CloudSQL 文档

Only plain SQL format is supported by the Cloud SQL Admin API.

The custom format is allowed if the dump file is intended for use with pg_restore.

如果由于某种原因您不能使用pg_restore,我会启动一个本地 Postgres 实例(即在您的笔记本电脑上)并使用它pg_restore来恢复数据库。

加载到本地数据库后,您可以使用pg_dump以明文格式转储到文件,然后使用控制台或gcloud命令加载到 CloudSQL。


推荐阅读