[英]Postgres Tutorial: pg_restore: [archiver] input file does not appear to be a valid archive
I'm working through the Postgres DVD tutorial and am running into issues importing their sample database.我正在学习Postgres DVD 教程,并且在导入他们的示例数据库时遇到了问题。
Running pg_restore -U postgres -d dvdrental ~[filepath]/dvd-database.tar.gz
gives me pg_restore: [archiver] input file does not appear to be a valid archive
.运行
pg_restore -U postgres -d dvdrental ~[filepath]/dvd-database.tar.gz
给了我pg_restore: [archiver] input file does not appear to be a valid archive
。
My process so far has been the following:到目前为止,我的流程如下:
tar czf dvd-database.tar.gz dvdrental.zip
(I've also tried extracting the zip to a folder first with the same result, as well as dropping the .gz)tar czf dvd-database.tar.gz dvdrental.zip
将其解压缩到 .tar (我也尝试先将 zip 解压缩到文件夹中,结果相同,并删除 .gz)pg_restore -U postgres -d dvdrental ~[filepath]/dvd-database.tar
as stated above.pg_restore -U postgres -d dvdrental ~[filepath]/dvd-database.tar
。 I'm currently using Postgres 9.5, which may be causing the issue.我目前正在使用 Postgres 9.5,这可能会导致问题。 Looking for an answer that points out where I'm going wrong in this process or how to update an archive of a Postgres database to 9.5.
寻找一个答案,指出我在这个过程中哪里出错了,或者如何将 Postgres 数据库的存档更新到 9.5。
Per comments above, the solution was simple.根据上面的评论,解决方案很简单。
Extracting the dvdrental.zip file to an uncompressed .tar is not necessary as suggested in the tutorial instructions.无需按照教程说明中的建议将 dvdrental.zip 文件解压缩为未压缩的 .tar。
pg_restore
will work if pointed to the directory where the database dump was extracted:如果指向提取数据库转储的目录,
pg_restore
将起作用:
pg_restore -U <username> -d dvdrental <your/path/to/extracted/dir>/dvdrental
My problem was that when installing postgresql, I chose a different name for the superuser ( root
for example, not postgres
).我的问题是,在安装 postgresql 时,我为超级用户选择了不同的名称(例如
root
,而不是postgres
)。 And the dvdrental/restore.sql
file uses the postgres
role.并且
dvdrental/restore.sql
文件使用postgres
角色。 So to solve this problem you need to create another superuser named postgres
.因此,要解决此问题,您需要创建另一个名为
postgres
超级用户。
createuser --superuser postgres
Then create server (PosgreSQL) with role postgres
and db dvdrental
with role postgres
.然后创建角色服务器(PosgreSQL)
postgres
和DB dvdrental
与角色postgres
。 After u can succesfuly restore db from extracted folder在你可以成功地从提取的文件夹中恢复数据库之后
After trying for hours which worked for me is the below command.经过几个小时对我有用的是以下命令。 Since PgAdmin 4 it's very hard to work with.
由于 PgAdmin 4 很难使用。
/Library/PostgreSQL/10/bin/pg_restore -U postgres -p 5433 -d dvdrental /pg-db/dvdrental/
Just extract the zip into a folder and execute the pg_restore
command with these options in my case Mac os where /pg-db/dvdrental/
is the zip extracted directory.只需将 zip 解压缩到一个文件夹中,然后在我的 Mac 操作系统中使用这些选项执行
pg_restore
命令,其中/pg-db/dvdrental/
是 zip 解压缩的目录。
It will be easier to use pgAdmin 4.使用 pgAdmin 4 会更容易。
While restoring the tar file onto the database through pgAdmin you will get this error thrown at you.通过 pgAdmin 将 tar 文件恢复到数据库时,您将收到此错误。 We usually get stuck at this point and forget to check the schema.
我们通常会卡在这一点上而忘记检查架构。
Ignore the error.忽略错误。 The data has already been loaded and restored.
数据已经加载并恢复。
If you are running your postgres on Docker
then make sure to pass hostname and port,如果您在
Docker
上运行 postgres,请确保传递主机名和端口,
pg_restore -U postgres -h localhost -p 5432 -d dvdrental ./Downloads/dvdrental
Here, ./Downloads/dvdrental
is extracted folder from dvdrental.zip在这里,./
./Downloads/dvdrental
dvdrental 是从 dvdrental.zip 中提取的文件夹
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.