简体   繁体   English

如何使用 pg_restore 在 cloudsql 中导入转储文件?

[英]How to use pg_restore to import dump file in cloudsql?

I want to import the.sql file created with pg_dump into cloudsql.我想将使用 pg_dump 创建的 .sql 文件导入到 cloudsql 中。

The console and gcloud commands are both custom-type dump files, so they are told to use pg_restore. console 和 gcloud 命令都是自定义类型的转储文件,所以它们被告知使用 pg_restore。

On my local machine在我的本地机器上

pg_restore -h cloud_sql_ip -U postgres -d database sqlfile.sql

When I use the command, I get the following error:当我使用该命令时,出现以下错误:

pg_restore: error: connection to database "database" failed: could not connect to server: Operation timed out
        Is the server running on host "cloud_sql_ip" and accepting
        TCP/IP connections on port 5432?

If I use the gcloud sql connect command, it will connect without any problems.如果我使用 gcloud sql 连接命令,它将毫无问题地连接。

I don't know why I am getting the error.我不知道为什么会收到错误消息。

Thank you for your help.谢谢您的帮助。

To use PostgreSQL's pg_restore with -d , it needs to be able to connect to the database, which apparently it can't, probably due to firewall issues.要使用 PostgreSQL 的 pg_restore 和-d ,它需要能够连接到数据库,显然它不能,可能是由于防火墙问题。

Perhaps you can change the config to let you connect from your own computer (I don't know, I'm not a Google Clouse user.)也许您可以更改配置以让您从自己的计算机连接(我不知道,我不是 Google Clouse 用户。)

Another option would be use pg_restore without -d to convert the custom dump file into a real sql file, then load that real sql file using one of the other methods you already tried but which failed because it was the wrong format.另一种选择是使用不带-d的 pg_restore 将自定义转储文件转换为真正的 sql 文件,然后使用您已经尝试过但由于格式错误而失败的其他方法之一加载该真正的 sql 文件。

pg_restore -f real_sql.sql sqlfile.sql

Or you could just re-run pg_dump, choosing the plain format not the custom format this time.或者你可以重新运行 pg_dump,这次选择普通格式而不是自定义格式。

PostgreSQL's pg_restore -d from your local (On my local machine) requires you to first authorize your public IP, there by allowing your machine to connect to your cloudsql instance...来自本地(在我的本地计算机上)的 PostgreSQL 的 pg_restore -d 要求您首先授权您的公共 IP,然后允许您的计算机连接到您的 cloudsql 实例...

Per GCP根据 GCP

You have not authorised any external.networks to connect to your Cloud SQL instance.您尚未授权任何 external.networks 连接到您的 Cloud SQL 实例。

If you click on the Connections link on the left nav, under the Networking tab, you will see the above message...you will need to add your pubic IP (click Add Network)如果您单击左侧导航栏上的“连接”链接,在“网络”选项卡下,您将看到以上消息...您需要添加您的 pubic IP(单击“添加网络”)

在此处输入图像描述

Hopefully this helps希望这有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM