简体   繁体   English

pg_restore: [archiver] 文件头中不支持的版本 (1.14)

[英]pg_restore: [archiver] unsupported version (1.14) in file header

I have a live server and development box, call them live and dev respectively both running postgresql.我有一个实时服务器和开发盒,分别称它们为 live 和 dev,它们都运行 postgresql。 I can see both and manage both with pgadmin4 without trouble, and both are fully functional the one behing a live website and the other when I run by website in debug mode on the my dev box.我可以使用 pgadmin4 轻松查看和管理两者,并且当我在开发箱上以调试模式通过网站运行时,两者都功能齐全,一个是实时网站,另一个是。 Pretty ordinary setup.很普通的设定。

For years I have been running the same bash script I wrote that dumps the live database then restores it on the dev box so I have the latest live snapshot to work with.多年来,我一直在运行我编写的相同 bash 脚本,该脚本转储实时数据库,然后在开发箱上恢复它,这样我就有了最新的实时快照可以使用。

Today this fails me with the titled message:今天,这让我失望了标题消息:

pg_restore: [archiver] unsupported version (1.14) in file header

I have tried to diagnose this, and searched extensively on-line but am bedeviled and have failed so here I am cap in hand for expertise.我试图诊断出这个问题,并在网上进行了广泛的搜索,但我很困惑并且失败了,所以在这里我掌握了专业知识。

To help I will share the following:为了帮助我将分享以下内容:

$ pg_dump --version
pg_dump (PostgreSQL) 10.11 (Ubuntu 10.11-1.pgdg18.04+1)
$ pg_restore --version
pg_restore (PostgreSQL) 10.11 (Ubuntu 10.11-1.pgdg18.04+1)
$ pg_dump --host=live.lan --port=5432 --dbname=mydb --username=myuser --format=custom > test.backup
$ ls -l test.backup 
-rw-r--r-- 1 bernd bernd 2398358 Dec 23 23:40 test.backup
$ file test.backup 
test.backup: PostgreSQL custom database dump - v1.14-0
$ pg_restore --dbname=mydb test.backup 
pg_restore: [archiver] unsupported version (1.14) in file header

Given pg_dump and pg_restore are identical versions and:鉴于 pg_dump 和 pg_restore 是相同的版本,并且:

$ which pg_dump
/usr/bin/pg_dump
$ which pg_restore
/usr/bin/pg_restore
$ ls -l /usr/bin/pg_dump /usr/bin/pg_restore
lrwxrwxrwx 1 root root 37 Nov 14 23:23 /usr/bin/pg_dump -> ../share/postgresql-common/pg_wrapper
lrwxrwxrwx 1 root root 37 Nov 14 23:23 /usr/bin/pg_restore -> ../share/postgresql-common/pg_wrapper

I can see they are not just identical versions but are run by the same wrapper script (which happens to be a perl script - now that's a language you don't see much anymore and I used to code in extensively)我可以看到它们不仅仅是相同的版本,而是由相同的包装脚本运行(恰好是一个 perl 脚本 - 现在这是一种你不再看到的语言,我曾经广泛地编码)

So I'm left totally perplexed.所以我完全困惑了。 Thinking there may be a version issue with the live machine:认为直播机可能存在版本问题:

$ ssh live.lan
Welcome to Ubuntu 18.04.3 LTS (GNU/Linux 4.15.0-72-generic x86_64)
$ which pg_dump
/usr/bin/pg_dump
$ which pg_restore
/usr/bin/pg_restore
$ pg_dump --version
pg_dump (PostgreSQL) 10.10 (Ubuntu 10.10-0ubuntu0.18.04.1)
$ pg_restore --version
pg_restore (PostgreSQL) 10.10 (Ubuntu 10.10-0ubuntu0.18.04.1)

I can see the live box does have slightly older version of pg_dump (which would only matter if pg_dump on my dev box somehow used a RPC to the live box to run its pg_dump).我可以看到 live box 确实有稍旧版本的 pg_dump(只有在我的 dev box 上的 pg_dump 以某种方式使用 RPC 到 live box 来运行它的 pg_dump 时才重要)。

Now there is maybe a small clue in the fact that my dev box has seen a few postgresql upgrades come through and so for example:现在可能有一个小线索,我的开发箱已经看到了一些 postgresql 升级,例如:

$ pg_lsclusters
Ver Cluster Port Status Owner    Data directory              Log file
10  main    5432 online postgres /var/lib/postgresql/10/main /var/log/postgresql/postgresql-10-main.log
11  main    5433 online postgres /var/lib/postgresql/11/main /var/log/postgresql/postgresql-11-main.log
12  main    5434 online postgres /var/lib/postgresql/12/main /var/log/postgresql/postgresql-12-main.log

The 11 and 12 clusters remain unused as evidenced by empty log files.空日志文件证明 11 和 12 集群仍未使用。 I'm using 10. But I do notice that:我正在使用 10。但我确实注意到:

$ psql --version
psql (PostgreSQL) 12.1 (Ubuntu 12.1-1.pgdg18.04+1)
$ ssh live.lan
Welcome to Ubuntu 18.04.3 LTS (GNU/Linux 4.15.0-72-generic x86_64)
$ psql --version
psql (PostgreSQL) 10.10 (Ubuntu 10.10-0ubuntu0.18.04.1)

which is mildly fishy but again not obviously a cause or related:这有点可疑,但又不是明显的原因或相关:

  1. I am using pg_dump not psql我使用的是 pg_dump 而不是 psql
  2. I am using only the dev boxes pg tools not the live boxes (they should be irrelevant, the whole data transfer theoretically over port 5432 on the live box which delivers a databse dump to pg_dump on my dev box.我只使用开发盒 pg 工具而不是实时盒(它们应该无关紧要,理论上整个数据传输通过实时盒上的端口 5432 传输数据转储到我的开发盒上的 pg_dump。

Here are the clusters on the love box and it's over port 5432 that on live.lan I'm running pg_dump!这是 love box 上的集群,它位于 live.lan 上的端口 5432 上,我正在运行 pg_dump!

$ pg_lsclusters 
Ver Cluster Port Status Owner    Data directory           Log file
10  main    5432 online postgres /data/postgresql/10/main /var/log/postgresql/postgresql-10-main.log

I am deeply perplexed and hamstrung at present by this.我目前对此深感困惑和束手无策。 Would deeply appreciate forward moving clues.将深深地欣赏向前移动的线索。 If I am compelled to fish around in the dark I will probbaly uninstall postgres 11 and 12 again and see if that helps, else I will end up having to trace /usr/share/postgresql-common/pg_wrapper to see how and where the two paths of pg_dump and pg_restore diverge down incompatible version paths.如果我被迫在黑暗中钓鱼,我可能会再次卸载 postgres 11 和 12,看看是否有帮助,否则我最终将不得不跟踪/usr/share/postgresql-common/pg_wrapper以查看两者的方式和位置pg_dump 和 pg_restore 的路径沿着不兼容的版本路径发散。

Update:更新:

A further clue I have uncovered, that permits me a workaround but simply deepens the mystery is as follows:我发现的另一条线索允许我解决问题,但只是加深了谜团如下:

$ sudo -u postgres pg_dump --host=live.lan --port=5432 --dbname=mydb --username=myuser --format=custom > test.backup
$ sudo -u postgres /usr/lib/postgresql/10/bin/pg_dump --host=live.lan --port=5432 --dbname=mydb --username=myuser --format=custom > test2.backup
$ sudo -u postgres pg_restore -l test.backup
pg_restore: [archiver] unsupported version (1.14) in file header
$ sudo -u postgres pg_restore -l test2.backup
... produces listing of contents ...
$ sudo -u postgres pg_dump --version
pg_dump (PostgreSQL) 10.11 (Ubuntu 10.11-1.pgdg18.04+1)
$ sudo -u postgres /usr/lib/postgresql/10/bin/pg_dump --version
pg_dump (PostgreSQL) 10.11 (Ubuntu 10.11-1.pgdg18.04+1)

That is perplexing beyond belief.这是令人难以置信的令人困惑。 The only possible explanations:唯一可能的解释:

  1. in spite of reporting identical version numbers the two pg_dumps are different.尽管报告的版本号相同,但两个 pg_dump 是不同的。 I would rule this out as beyond belief.我会认为这是难以置信的。
  2. pg_dump runs pg_wrapper which runs /usr/lib/postgresql/10/bin/pg_dump with some mystery argument(s) that break it! pg_dump 运行 pg_wrapper,它运行 /usr/lib/postgresql/10/bin/pg_dump 并带有一些破坏它的神秘参数!

The second is plausible, and will require me to instrument pg_wrapper to diagnose.第二个是合理的,需要我使用 pg_wrapper 进行诊断。

Update 2:更新 2:

And one instrumentation of pg_wrapper later.稍后对 pg_wrapper 进行一种检测。 It eventuates that pg_dump runs pg_wrapper which runs /usr/lib/postgresql/12/bin/pg_dump yet it runs /usr/lib/postgresql/10/bin/pg_restore ... Go figure!它最终导致 pg_dump 运行 pg_wrapper,它运行/usr/lib/postgresql/12/bin/pg_dump但它运行/usr/lib/postgresql/10/bin/pg_restore ......去图! Starting to think this a postgresql version interoperability bug!开始认为这是一个 postgresql 版本的互操作性错误!

Update 3:更新 3:

Looking deeper into pg_wrapper , nailed the cause, and yes I'd argue it's a pg_wrapper bug of a kind though it may be debatable, hardly though IMHO.深入研究pg_wrapperpg_wrapper原因,是的,我认为这是一种 pg_wrapper 错误,尽管它可能有争议,但恕我直言。 Here's what it does:这是它的作用:

If --host is provided then it uses the newest version of postgresql installed (12 in my case and this is for pg_dump, so pg_dump 12 creates the dump)如果提供了--host则它使用最新版本的 postgresql 安装(在我的例子中是 12,这是用于 pg_dump,所以 pg_dump 12 创建转储)

If --host is not provided then it consults the user config (10 in my case, and this is for pg_restore, so pg_restore 10 is run and it can't read a file created by pg_dump 12).如果未提供--host则它会咨询用户配置(在我的情况下为 10,这是用于 pg_restore,因此运行 pg_restore 10 并且它无法读取由 pg_dump 12 创建的文件)。

So why is this a bug?那么为什么这是一个错误呢? Because I have a use config, and I'd like it respected whether or not I'm talking to a remote host.因为我有一个使用配置,而且无论我是否在与远程主机交谈,我都希望它受到尊重。 More to the point if I specify a host I certainly don't expect to use the latest local version ignoring local config.更重要的是,如果我指定一个主机,我当然不希望使用最新的本地版本而忽略本地配置。 I'd expect either to respect local config (as is the case when no remote host is specified) or try to match the rmeote hosts version.我希望要么尊重本地配置(就像没有指定远程主机的情况一样),要么尝试匹配 rmeote 主机版本。 Arbitrarily leaning on the latest installed version is IMHO deeply questionable.任意依赖最新安装的版本恕我直言,深表怀疑。

BUT it turns out there is a workaround that works.但事实证明,有一种可行的解决方法。 Essentially instead of:基本上代替:

sudo -u postgres pg_restore -l test.backup

this works:这有效:

sudo -u postgres pg_restore --host=localhost -l test.backup

By specifying the host ironically we force it to ignore local configs and use the newest version of pg_restore which seems to work fine restoring to a PG 10 cluster.通过讽刺地指定主机,我们强制它忽略本地配置并使用最新版本的 pg_restore,它似乎可以很好地恢复到 PG 10 集群。

ubuntu guys: most likely your pg_restore is outdated. ubuntu 伙计们:很可能你的pg_restore已经过时了。 Just use postgres doc and install newest version of postgres:只需使用 postgres doc并安装最新版本的 postgres:

  1. Create the file /etc/apt/sources.list.d/pgdg.list and add a line for the repository: deb http://apt.postgresql.org/pub/repos/apt/ YOUR_UBUNTU_VERSION_HERE-pgdg main where ubuntu versions are:创建文件/etc/apt/sources.list.d/pgdg.list并为存储库添加一行: deb http://apt.postgresql.org/pub/repos/apt/ YOUR_UBUNTU_VERSION_HERE-pgdg main ubuntu 版本所在的位置:

    • 20.04 - focal 20.04 - 焦点
    • 18.04 - bionic 18.04 - 仿生
    • 16.04 - xenial 16.04 - xenial
  2. Add keys: wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -添加密钥: wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

  3. sudo apt-get update && sudo apt-get upgrade

It worked for me!它对我有用!

Here's another twist, but please note first that this is a windows case.这是另一个转折点,但请首先注意这是一个 windows 案例。 If it's just linux for you, don't read further.如果它只是适合您的 linux,请不要进一步阅读。 All advice given here did not help me, eventually the cause IMC was simpler and had to do with the use of pgAdmin.这里给出的所有建议都没有帮助我,最终导致 IMC 更简单,并且与 pgAdmin 的使用有关。 Because of the repetitive nag for newer versions, my habit is to install pgAdmin separately (not using stackbuilder).由于新版本的重复唠叨,我的习惯是单独安装pgAdmin(不使用stackbuilder)。 (AT LEAST) in that case, pgAdmin has its own cache of utility programs and will use these unless you tell it differently. (至少)在这种情况下,pgAdmin 有自己的实用程序缓存,除非您以不同方式告诉它,否则将使用它们。 My pg instances are still version 11(.6), but the latest pgAdmin will probably have V12 utilities.我的 pg 实例仍然是版本 11(.6),但最新的 pgAdmin 可能会有 V12 实用程序。 Which may quite well cause a version discrepancy.这很可能会导致版本差异。 This crept up on me after doing a number of succesful transfers from my main machine to a laptop.在从我的主机成功转移到笔记本电脑之后,我突然想到了这一点。 So, in pgAdmin do (menu)File->preferences->Paths and set Binary Paths corresponding to your postgres installation, IMC C:\\Program Files\\PostgreSQL\\11\\bin.因此,在 pgAdmin 中执行 (menu)File->preferences->Paths 并设置与您的 postgres 安装对应的二进制路径,IMC C:\\Program Files\\PostgreSQL\\11\\bin。 That did the job.那做的工作。

So my experience here was somewhat similar to OP, but not completely.所以我在这里的经历有点类似于 OP,但并不完全。

I had versions 9.4, 9.5, 11, and 12 installed, and all the pg_* tools pointed to the 9.4 version.我安装了 9.4、9.5、11 和 12 版本,并且所有 pg_* 工具都指向 9.4 版本。 I tried to pg_restore a dump create by version 12 on a different host, which didn't work because this host used the 9.4 tools, which were incompatible (same error as OP posted).我试图在不同的主机上 pg_restore 版本 12 创建的转储,这不起作用,因为该主机使用了不兼容的 9.4 工具(与 OP 发布的错误相同)。

So, here was my debugging flow:所以,这是我的调试流程:

  • which pg_restore
    • /usr/bin/pg_restore /usr/bin/pg_restore
  • ls -l /usr/bin/pg_restore
    • /usr/bin/pg_restore -> ../share/postgresql-common/pg_wrapper /usr/bin/pg_restore -> ../share/postgresql-common/pg_wrapper
  • vim /usr/share/postgresql-common/pg_wrapper
    • Read about how it determines version.阅读有关它如何确定版本的信息。 Just read through the first 20 or so lines只需通读前 20 行左右

Apparantly, there is a --cluster option, which is helpful in resolving the version.显然,有一个--cluster选项,它有助于解决版本问题。 So I simply added --cluster 12/main to my pg_restore call, and everything works as expected again所以我只是将--cluster 12/main添加到我的pg_restore调用中,一切都再次按预期工作

检查并查看您的 pgadmin 是否是最新的,我遇到了这个问题并通过更新解决了它

This error is caused by a version mismatch between the version of pg_dump used to create the backup file and the version of pg_restore used to attempt the restore.此错误是由用于创建备份文件的 pg_dump 版本与用于尝试恢复的 pg_restore 版本之间的版本不匹配引起的。

Updating my PostgreSQL solved the problem更新我的 PostgreSQL 解决了这个问题

On my case (on Mac, Postgres managed by Homebrew) the solution was to check the pg_dump version used to create the dump file and install that version of postgresql .在我的情况下(在 Mac 上,由 Homebrew 管理的 Postgres)解决方案是检查用于创建转储文件的pg_dump版本并安装该版本的postgresql

Apparently with Brew you can't install pg_restore separately from postgresql (not sure, didn't really dig into it), so I needed to install postgresql@12 and link it.显然,使用 Brew,您无法将 pg_restore 与 postgresql 分开安装(不确定,并没有真正深入研究它),所以我需要安装 postgresql@12 并链接它。 That did it.做到了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 pg_restore: [archiver] 文件头中不受支持的版本 (1.13) - pg_restore: [archiver] unsupported version (1.13) in file header 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)” - Getting "[archiver] unsupported version (1.13) in file header" when running pg_restore AWS Elatic Beanstalk和rails:pg_restore:文件头中的[archiver]不支持的版本(1.13) - AWS Elatic Beanstalk and rails: pg_restore: [archiver] unsupported version (1.13) in file header pg_restore: [archiver] postgres 中的输入文件太短错误 - pg_restore: [archiver] input file is too short error in postgres 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: [directory archiver] could not open input file. Error while trying to restore DB Postgres 教程:pg_restore:[archiver] 输入文件似乎不是有效的存档 - Postgres Tutorial: pg_restore: [archiver] input file does not appear to be a valid archive 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
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM