简体   繁体   English

Postgres 教程:pg_restore:[archiver] 输入文件似乎不是有效的存档

[英]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:到目前为止,我的流程如下:

  1. Download the dvdrental.zip file下载dvdrental.zip文件
  2. Extract it to a .tar using 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)
  3. Running 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.

相关问题 pg_restore:[存档]输入文件在使用Pgadmin 4的PostgreSQL中似乎不是有效的存档错误 - pg_restore: [archiver] input file does not appear to be a valid archive error in PostgreSQL using Pgadmin 4 pg_restore:[archiver]输入文件在ubuntu 18.04中使用Pgadmin 4的PostgreSQL中似乎不是有效的存档错误 - pg_restore: [archiver] input file does not appear to be a valid archive error in PostgreSQL using Pgadmin 4 in ubuntu 18.04 pg_restore:错误:输入文件似乎不是有效的存档 - pg_restore: error: input file does not appear to be a valid archive pg_restore: [archiver] postgres 中的输入文件太短错误 - pg_restore: [archiver] input file is too short error in postgres pg_restore: [目录归档程序] 无法打开输入文件。 尝试恢复数据库时出错 - pg_restore: [directory archiver] could not open input file. Error while trying to restore DB pg_restore:[tar archiver] 在 tar 存档中找不到文件“toc.dat”的 header:- [PostgreSQL-11] pg admin 4 - pg_restore: [tar archiver] could not find header for file "toc.dat" in tar archive :- [PostgreSQL-11] pg admin 4 pg_restore错误:pg_restore:文件头中的[archiver]不支持的版本(1.13) - pg_restore error: pg_restore: [archiver] unsupported version (1.13) in file header pg_restore: [archiver] 文件头中不受支持的版本 (1.13) - pg_restore: [archiver] unsupported version (1.13) in file header pg_restore: [archiver] 文件头中不支持的版本 (1.14) - pg_restore: [archiver] unsupported version (1.14) in file header 运行 pg_restore 时在文件头中获取“[archiver] 不受支持的版本(1.13)” - Getting "[archiver] unsupported version (1.13) in file header" when running pg_restore
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM