在部署到Heroku时出现错误:您必须安装至少一个postgresql-client-<version>包。

167
sdilshod@sdilshod-Lenovo-B590:~/webapp/saturn$ heroku run rake db:migrate
Running `rake db:migrate` attached to terminal... up, run.6194
DEPRECATION WARNING: You have Rails 2.3-style plugins in    vendor/plugins! Support for these plugins will be removed in Rails 4.0.  Move them out and bundle them in your Gemfile, or fold them in to your app  as lib/myplugin/* and config/initializers/myplugin.rb. See the release  notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2- 0-rc2-has-been-released. (called from <top (required)> at /app/Rakefile:7)
DEPRECATION WARNING: You have Rails 2.3-style plugins in  vendor/plugins! Support for these plugins will be removed in Rails 4.0.   Move them out and bundle them in your Gemfile, or fold them in to your app   as lib/myplugin/* and config/initializers/myplugin.rb. See the release   notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-  0-rc2-has-been-released. (called from <top (required)> at /app/Rakefile:7)
 Error: You must install at least one postgresql-client-<version> package.
 rake aborted!
 Error dumping database
 /app/vendor/bundle/ruby/1.9.1/gems/activerecord-   3.2.12/lib/active_record/railties/databases.rake:415:in `block (3 levels)   in <top (required)>'
 /app/vendor/bundle/ruby/1.9.1/gems/activerecord- 3.2.12/lib/active_record/railties/databases.rake:188:in `block (2 levels) in <top (required)>'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/railties/databases.rake:182:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:structure:dump
(See full trace by running task with --trace)

Heroku pg:psql可以正常工作,但当我执行migrate rake db:migrate时,会出现需要安装pg客户端的错误。我需要在哪里安装pg客户端?有什么帮助吗?


1
我找到了这个解决方案并修复了错误。 - dilshod
4个回答

340

在基于Debian的系统上,PostgreSQL客户端程序由postgresql-client-common提供,作为符号链接到/usr/share/postgresql-common/pg_wrapper

如果你安装了该软件包并尝试使用任何PostgreSQL客户端程序如psqlpg_dumppg_dumpallpg_restore等,没有安装特定版本的二进制包如postgresql-client-9.1,它将会发出以下错误:

You must install at least one postgresql-client-< version > package

最简单的解决方法是安装postgresql-client元包。它始终依赖于基于Debian的系统上当前支持的PostgreSQL数据库客户端软件包,并依赖于postgresql-client-common。

sudo apt-get install postgresql-client

感谢您的回复,jla!看起来是Heroku的一个bug,我找到了https://dev59.com/q2Qm5IYBdhLWcg3w2R1J来解决。 - dilshod
不用谢。我在使用命令行上的psql时搜索“至少一个”错误消息时找到了这个。在找到答案后,我想留下一个Debian特定的修复程序,以提供一个可工作的pg_dump和psql,作为建议的heroku修复程序的替代方案,以解决Debian特定的错误。 - jla
1
通过 heroku run bash 运行 sudo apt-get install postgresql-client 无法正常工作?它返回 bash: sudo: command not found。我在这里缺少什么? - s2t2
运行以下命令 sudo apt install postgresql-client-common - Julfikar Haidar

34

2020年3月30日更新

同意所选答案,但我发现在Ubuntu 18上安装postgresql-client-12稍微有些复杂。

sudo apt update
sudo apt -y install vim bash-completion wget
sudo apt -y upgrade
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list
sudo apt update
sudo apt -y install postgresql-client-12

详见此参考资料


6
在Ubuntu 20.04上,只需按照指示的最后一行即可解决问题。 - Holger Brandl
对于PostgreSQL 13,请参阅他们(几乎相同的)指南:https://computingforgeeks.com/how-to-install-postgresql-13-on-ubuntu/ - Venryx

12

对于Ubuntu 18.04.6 LTS,只需要两个命令就可以实现。

sudo apt-get install postgresql-client-common

并且

sudo apt-get install postgresql-client

0

随着新版本的PostgreSQL 14,我遵循这份文档。

http://apt.postgresql.org/pub/repos/apt/README

$ sudo su - 

$ lsb_release -c

Codename:       focal

$ echo "deb http://apt.postgresql.org/pub/repos/apt/ focal-pgdg main" > /etc/apt/sources.list.d/pgdg.list

$ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
$ sudo apt-get update
$ sudo apt-get install postgresql-client-14

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接