pg_config、ruby pg、postgresql 9.0 升级后问题、centos 5

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4707401/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-20 00:29:47  来源:igfitidea点击:

pg_config, ruby pg, postgresql 9.0 problem after upgrade, centos 5

rubypostgresqlgemcentos5pg

提问by objah

After upgrade postgresql 8.1 to 9.0 ive noticed issues with libraries dependency. Postgresql works fine (connection, queries).

将 postgresql 8.1 升级到 9.0 后,我注意到库依赖问题。Postgresql 工作正常(连接、查询)。

yum list postgresql*
Installed Packages
postgresql.i386 9.0.0-1PGDG.el5 installed
postgresql-debuginfo.i386 9.0.0-1PGDG.el5 installed
postgresql-devel.i386 9.0.0-1PGDG.el5 installed
postgresql-libs.i386 9.0.0-1PGDG.el5 installed
postgresql-odbcng.i386 0.90.101-2.el5 installed
postgresql-plruby.i386 0.5.1-5.el5 installed
postgresql-server.i386 9.0.0-1PGDG.el5 install

but when im trying to install 'pg' for ruby, ive received

但是当我尝试为 ruby​​ 安装“pg”时,我收到了

gem install pg
Building native extensions.  This could take a while...
ERROR:  Error installing pg:
        ERROR: Failed to build gem native extension.

/usr/local/bin/ruby extconf.rb
checking for pg_config... no
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

When trying with another ruby-postgres driver, ive got

尝试使用另一个 ruby​​-postgres 驱动程序时,我得到了

yum install ruby-postgres
ruby-postgres-0.7.1-5.el5.i386 from epel has depsolving problems
  --> Missing Dependency: libpq.so.4 is needed by package ruby-postgres-0.7.1-5.el5.i386 (epel)

and

locate libpq.so.4
/usr/lib/libpq.so.4
/usr/lib/libpq.so.4.1

also exported path

也导出路径

LD_LIBRARY_PATH=/usr/pgsql-9.0/lib
export LD_LIBRARY_PATH

after running ruby script with "require pg" (works on 8.1), ive got:

使用“require pg”运行 ruby​​ 脚本后(适用于 8.1),我得到:

/usr/local/lib/ruby/site_ruby/1.8/i686-linux/pg_ext.so: libpq.so.4: cannot open shared object file: No such file or directory - /usr/local/lib/ruby/site_ruby/1.8/i686-linux/pg_ext.so (LoadError)
        from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:29:in `require'
        from /usr/local/lib/ruby/site_ruby/1.8/pg.rb:12
        from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:29:in `gem_original_require'
        from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:29:in `require'

Any suggestions what to do more?

有什么建议可以做更多吗?

回答by Michael Kohl

There are various config options you can add to the gem install, like -with-opt-dir, --with-pg-dirand --with-pg-config. Look at this mailing list thread:

您可以将各种配置选项添加到 gem 安装中,例如-with-opt-dir,--with-pg-dir--with-pg-config. 看看这个邮件列表线程:

http://www.ruby-forum.com/topic/409608

http://www.ruby-forum.com/topic/409608

回答by Francis Trujillo Jr

$ gem --version
1.3.7

$ ruby --version
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]

$ cat /etc/redhat-release 
CentOS release 5.4 (Final)

$ uname -m
x86_64

sudo yum list installed | grep postgre    (see what you have installed)
sudo yum list available | grep postgre    (I was missing postgresql-devel)
sudo yum install postgresql-devel         (I installed it)
sudo gem install pg                       (no error this time!)

$ gem list --local | grep pg
pg (0.11.0)

回答by user1566323

This seems like a pg config file location error,

这似乎是一个 pg 配置文件位置错误,

gem install pg -- --with-pgsql-lib=/usr/pgsql-9.0/lib --with-pg-config=/usr/pgsql-9.1/bin/pg_config

solves it!!

解决了!!

gem install pg -- --with-pgsql-lib=/usr/pgsql-9.0/lib --with-pg-config=/usr/pgsql-9.1/bin/pg_config

/usr/local/lib/ruby/1.9.1/yaml.rb:56:in `<top (required)>':
It seems your ruby installation is missing psych (for YAML output).
To eliminate this warning, please install libyaml and reinstall your ruby.
Building native extensions.  This could take a while...
Successfully installed pg-0.14.0
1 gem installed
Installing ri documentation for pg-0.14.0...
Installing RDoc documentation for pg-0.14.0...

回答by Anonymous

On Mac OSX 10.6.8, using the MacPorts install of Postgres 9, the following command worked for me:

在 Mac OSX 10.6.8 上,使用 Postgres 9 的 MacPorts 安装,以下命令对我有用:

gem install pg -- --with-pgsql-lib=/opt/local/lib/postgresql90/lib --with-pg-config=/opt/local/lib/postgresql90/bin/pg_config

回答by Greg Smith

libpq.so.4is from an older version of PostgreSQL; 9.0 ships with /usr/pgsql-9.0/lib/libpq.so.5

libpq.so.4来自较旧版本的 PostgreSQL;9.0 附带/usr/pgsql-9.0/lib/libpq.so.5

If you have a program that was built against libpq.so.4, that file is provided by the compat-postgresql-libspackages, which you may not have installed. A lot of people remove it using "--force" because it can be hard to get the newer RPMs installed otherwise; that's a bad idea, but the alternative is complicated. If you've installed that package, you should find a /usr/lib/libpq.so.4available that makes your existing program, compiled originally for the older PostgreSQL, happy.

如果您有一个针对 libpq.so.4 构建的程序,则该文件由compat-postgresql-libs软件包提供,您可能尚未安装该软件包。许多人使用“--force”删除它,因为否则很难安装较新的 RPM;这是一个坏主意,但替代方案很复杂。如果你已经安装了那个包,你应该找到一个/usr/lib/libpq.so.4可用,它使你现有的程序,最初为旧的 PostgreSQL 编译,很高兴。