postgresql 为什么 pg_restore 成功返回但实际上没有恢复我的数据库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5900888/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why is pg_restore returning successfully but not actually restoring my database?
提问by Mike Deck
I have a Postgres 8.4 database on a linux server that I have dumped using the following command:
我在使用以下命令转储的 Linux 服务器上有一个 Postgres 8.4 数据库:
pg_dump --format=c --exclude-table=log --file=/path/to/output my_db
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:
然后我将创建的文件 ftp 到我的本地 Windows 7 机器,并尝试使用以下命令将文件恢复到我的本地 Postgres 8.4 实例:
pg_restore --create --exit-on-error --verbose c:\path\to\file
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.
restore 命令生成大量输出,声称它创建了我的数据库,连接到它,然后按预期创建了所有其他表。但是,当我通过 pgAdmin 查看本地机器上的数据库时,恢复的数据库根本不存在。
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?
有没有人遇到过这种情况或知道会导致这种情况发生什么?
回答by Matthew Wood
You have to add the name of a valid database to initially connect to or it will just dump the contents to STDOUT:
您必须添加有效数据库的名称以进行初始连接,否则它只会将内容转储到 STDOUT:
pg_restore --create --exit-on-error --verbose --dbname=postgres <backup_file>
回答by tgunr
This is still confusing, I attempted to execute this thing that the --dbname should be the db I want to create.
这仍然令人困惑,我试图执行这个 --dbname 应该是我想要创建的数据库的事情。
pg_restore --create --exit-on-error --verbose --dbname=jiradb jiradb.tar
WRONG!!
错误的!!
It should literally be --dbname postgres, the --create then will create the real db from the name in the file. In my case, I restored from a tar backup with
它应该字面上是--dbname postgres,--create 然后将从文件中的名称创建真正的数据库。就我而言,我从 tar 备份中恢复了
pg_restore --create --exit-on-error --verbose --dbname=postgres jiradb.tar