为什么pg_restore成功返回却没有真正恢复我的数据库? [英] Why is pg_restore returning successfully but not actually restoring my database?

查看:269
本文介绍了为什么pg_restore成功返回却没有真正恢复我的数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用以下命令转储的Linux服务器上有一个Postgres 8.4数据库:

I have a Postgres 8.4 database on a linux server that I have dumped using the following command:

pg_dump --format=c --exclude-table=log --file=/path/to/output my_db

I然后将创建的文件ftp到我的本地Windows 7计算机上,并尝试使用以下命令将文件还原到我的本地Postgres 8.4实例:

I then ftp the created file to my local Windows 7 machine and attempt to restore the file to my local Postgres 8.4 instance using the following command:

pg_restore --create --exit-on-error --verbose c:\path\to\file

restore命令会产生大量输出,声称它创建了我的数据库并连接到该数据库,然后按预期创建了所有其他表。但是,当我通过pgAdmin查看本地计算机上的数据库时,恢复的数据库根本不存在。

The restore command generates plenty of output claiming it created my database, connected to it, and then created all the other tables as expected. However, when I view the databases on my local machine through pgAdmin the restored database doesn't exist at all.

为排除故障,我尝试了以下命令: / p>

In an attempt to troubleshoot I tried the following command:

pg_restore --create --exit-on-error --verbose --host=blahblah --username=no_one c:\path\to\file

即使指定的主机名和用户名是完全是胡说八道,我仍然可以从命令中获得完全相同的输出而没有任何错误。

When I run this command even though the host and username given are complete nonsense I still get the exact same output from the command without any errors.

是否有人之前遇到过这种情况,或者知道是什么原因引起的?

Has anyone run into this before or know what could by causing this?

推荐答案

您必须添加一个有效数据库的名称以进行初始连接,否则它将只是将内容转储到STDOUT:

You have to add the name of a valid database to initially connect to or it will just dump the contents to STDOUT:

pg_restore --create --exit-on-error --verbose --dbname=postgres <backup_file>

这篇关于为什么pg_restore成功返回却没有真正恢复我的数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆