Postgresql 为什么pg_restore成功返回,但没有实际还原我的数据库?

Postgresql 为什么pg_restore成功返回,但没有实际还原我的数据库?,postgresql,pg-dump,pg-restore,Postgresql,Pg Dump,Pg Restore,我在linux服务器上有一个Postgres 8.4数据库,我使用以下命令转储了该数据库: pg_dump --format=c --exclude-table=log --file=/path/to/output my_db pg_restore --create --exit-on-error --verbose c:\path\to\file pg_restore --create --exit-on-error --verbose --host=blahblah --username

我在linux服务器上有一个Postgres 8.4数据库,我使用以下命令转储了该数据库:

pg_dump --format=c --exclude-table=log --file=/path/to/output my_db
pg_restore --create --exit-on-error --verbose c:\path\to\file
pg_restore --create --exit-on-error --verbose --host=blahblah --username=no_one c:\path\to\file
然后,我将创建的文件ftp到本地Windows 7计算机,并尝试使用以下命令将该文件还原到本地Postgres 8.4实例:

pg_dump --format=c --exclude-table=log --file=/path/to/output my_db
pg_restore --create --exit-on-error --verbose c:\path\to\file
pg_restore --create --exit-on-error --verbose --host=blahblah --username=no_one c:\path\to\file
restore命令生成大量输出,声称它创建了我的数据库,连接到数据库,然后按预期创建了所有其他表。但是,当我通过pgAdmin查看本地计算机上的数据库时,还原的数据库根本不存在

为了进行故障排除,我尝试了以下命令:

pg_dump --format=c --exclude-table=log --file=/path/to/output my_db
pg_restore --create --exit-on-error --verbose c:\path\to\file
pg_restore --create --exit-on-error --verbose --host=blahblah --username=no_one c:\path\to\file
当我运行这个命令时,即使给出的主机和用户名完全是胡说八道,我仍然从命令中获得完全相同的输出,没有任何错误


以前是否有人遇到过这种情况,或者知道是什么原因导致了这种情况?

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

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

这仍然让人困惑,我试图执行--dbname应该是我想要创建的数据库

pg_restore --create --exit-on-error --verbose --dbname=jiradb jiradb.tar

它应该是--dbname=postgres,然后--create将根据文件中的名称创建真正的db。在我的例子中,我使用

pg_restore --create --exit-on-error --verbose --dbname=postgres jiradb.tar

为什么在pg_还原文档中没有提到大红色?!6年后,我遇到了同样的问题,最后我偶然发现了这个答案,它解决了这个问题。我无法相信文档仍然没有被修复,或者命令输出中没有任何东西可以让用户知道它实际上没有做任何事情。对于尝试PostgreSQL的新手来说,存在严重的可用性问题。请告诉我。至少两个小时。平心而论:手册的第二段是这样写的。@YoLudke因为posgres文档是世界上最糟糕的文档OK我以为只有我觉得文档不可理解我只是用
--dbname=my_specific_db
,而不是
=postgres
,运行了这篇文章,它起到了作用。。。我想知道自从你的回答后是否有什么变化?