简体   繁体   English

在 Heroku 上运行 pg:pull 时出现 pg_restore 错误 1

[英]Getting pg_restore error 1 when running pg:pull on Heroku

I am trying to copy the database from our staging server onto my local machine and I'm having some issues.我正在尝试将数据库从我们的登台服务器复制到我的本地计算机上,但遇到了一些问题。 This was working 2 months ago flawlessly and when I tried to use it again today I'm getting an issue.这在 2 个月前完美运行,当我今天再次尝试使用它时,我遇到了问题。

I am using this command:我正在使用这个命令:

heroku pg:pull DATABASE_URL my_app_db -a myApp

And at the end of the logs I get this:在日志的末尾,我得到了这个:

pg_dump: reading subscriptions
pg_dump: reading large objects
pg_dump: reading dependency data
pg_dump: saving encoding = UTF8
pg_dump: saving standard_conforming_strings = on
pg_dump: saving search_path = 
pg_dump: saving database definition
pg_restore: [archiver] unsupported version (1.14) in file header
pg_dump: dumping contents of table "public.addresses"
 ▸    pg_restore errored with 1

I've tried updating my postgresql package but they're the same on Heroku and my local machine:我试过更新我的 postgresql package 但它们在 Heroku 和我的本地机器上是一样的:

$ psql --version
psql (PostgreSQL) 12.3 (Ubuntu 12.3-1.pgdg18.04+1)
$ heroku run psql --version -a myApp
Running psql --version on ⬢ myApp... up, run.5796 (Hobby)
psql (PostgreSQL) 12.3 (Ubuntu 12.3-1.pgdg18.04+1)

I've always dropped the database locally before doing the pull:在进行拉取之前,我总是在本地删除数据库:

$ psql postgres
postgres=# DROP DATABASE my_app_db;
postgres=# \q

Update 1:更新 1:

Looks like I have a pg_dump and pg_pull version mismatch:看起来我的pg_dumppg_pull版本不匹配:

$ pg_dump --version
pg_dump (PostgreSQL) 10.13 (Ubuntu 10.13-1.pgdg18.04+1)
$ heroku run pg_dump --version -a myApp
pg_dump (PostgreSQL) 12.3 (Ubuntu 12.3-1.pgdg18.04+1)
$ pg_restore --version
pg_restore (PostgreSQL) 10.13 (Ubuntu 10.13-1.pgdg18.04+1)
$ heroku run pg_restore --version -a myApp
pg_restore (PostgreSQL) 12.3 (Ubuntu 12.3-1.pgdg18.04+1)

What I saw on the internet is that it should be updated by installing the latest postgresql.我在网上看到的是应该通过安装最新的postgresql来更新。 For some reason two of them aren't updated even with the latest PostgreSQL version.由于某种原因,即使使用最新的 PostgreSQL 版本,其中两个也没有更新。

Solution to resolve the issue:解决问题的解决方案:

As clemoun pointed out, I must've had multiple psql versions running.正如clemoun指出的那样,我必须运行多个 psql 版本。 I saw what I have with:我看到了我所拥有的:

$ pg_lsclusters

Then uninstalled version 10 and 11 with:然后卸载版本1011

$ sudo apt-get remove postgresql-10 postgresql-11

After that dropped the clusters:之后删除集群:

$ sudo pg_dropcluster 10 main
$ sudo pg_dropcluster 11 main

And logged out and in.并注销并登录。

The fact that you have at the same time:您同时拥有的事实:

$ psql --version
psql (PostgreSQL) 12.3 (Ubuntu 12.3-1.pgdg18.04+1)

and

$ pg_restore --version
pg_restore (PostgreSQL) 10.13 (Ubuntu 10.13-1.pgdg18.04+1)

makes me think you have several versions of PostgreSQL installed on your computer.让我觉得您的计算机上安装了多个版本的 PostgreSQL。

Try typing:尝试输入:

sudo find /usr -wholename '*/bin/postgres'

and you might find out you have both PostgreSQL versions 10.13 and 12.3 installed.您可能会发现您同时安装了 PostgreSQL 版本 10.13 和 12.3。 For some reason it's the 10.13 version of pg_restore that runs and Heroku requires that you use a version above 10.3 => Your 12.3 version should do the trick出于某种原因,运行的是 pg_restore 的 10.13 版本,并且 Heroku 要求您使用 10.3 以上的版本 => 您的 12.3 版本应该可以解决问题

Try uninstalling version 10.13 of Postgresql, leaving you computer with version 12.3 only.尝试卸载 Postgresql 的 10.13 版本,只留下 12.3 版本的计算机。 Thus pg_restore will run on version 12.3因此 pg_restore 将在版本 12.3 上运行

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM