是否可以在不使用 pg_restore 的情况下在 cloud 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?

解决方法

根据CloudSQL docs

          Name     Age
0     Age=John  Age=25
1     Name=Roy  Age=36
2   Name=Smith  Age=19
3  Name=Donald  Age=12
4   Name=jason  Age=57
5     Name=joe   Age=1

如果您由于某种原因无法使用 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. ,我会启动一个本地 Postgres 实例(即在您的笔记本电脑上)并使用 pg_restore 来恢复数据库。

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