pg_config, ruby pg, postgresql 9.0问题升级后,CentOS 5

8

将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

但是当我尝试为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.

尝试使用另一个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)

并且

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

也导出路径

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

在运行带有“require pg”(在8.1上有效)的Ruby脚本后,我得到了以下结果:
/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'

有什么更多的建议吗?

5个回答

6

1
gem install pg -- --with-pgsql-lib=/usr/pgsql-9.0/lib --with-pg-config=/usr/pgsql-9.0/bin/pg_config,这解决了pg的安装问题,谢谢!但是在运行脚本后,我仍然遇到了缺少libpq.so.4的问题... - objah
有进展了吗?也许你可以更新一下你的问题,这样我们就能更好地帮助你了? - Michael Kohl

5
``` $ 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 (查看已安装的内容) sudo yum list available | grep postgre (我缺少postgresql-devel) sudo yum install postgresql-devel (我安装了它) sudo gem install pg (这次没有错误!) $ gem list --local | grep pg pg (0.11.0) ```

我在尝试在已经安装了postgres的CentOS上安装pg gem时遇到了相同的情况。我怀疑问题出在无法找到pg_config,因为我的系统上根本没有它。安装了postgresql-devel之后,pg_config被添加了进来,pg gem也成功安装了。 - krukid

3

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

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

解决了它!
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...

你可能想让那些pgsql-9.X版本匹配起来。 - Ramfjord

1
在Mac OSX 10.6.8上,使用MacPorts安装的Postgres 9,以下命令适用于我:
gem install pg -- --with-pgsql-lib=/opt/local/lib/postgresql90/lib --with-pg-config=/opt/local/lib/postgresql90/bin/pg_config

0

libpq.so.4 是旧版PostgreSQL的库文件;9.0版本则使用 /usr/pgsql-9.0/lib/libpq.so.5

如果您有一个是基于 libpq.so.4 构建的程序,那么该文件可以通过compat-postgresql-libs软件包提供,但您可能没有安装它。很多人使用“--force”选项删除它,因为否则很难安装新的RPM包;这是个坏主意,但另一种选择就比较复杂。如果您已经安装了该软件包,您应该能够找到一个可用的 /usr/lib/libpq.so.4 文件,使您原本为旧版PostgreSQL编译的现有程序正常运行。


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