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'

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

4

5 回答 5

6

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

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

于 2011-01-16T19:09:30.420 回答
5
$ 宝石--版本
1.3.7

$红宝石--版本
ruby 1.9.2p180(2011-02-18 修订版 30909)[x86_64-linux]

$ cat /etc/redhat-release
CentOS 5.4 版(最终版)

$ unname -m
x86_64

sudo yum 列表已安装 | grep postgre(查看您安装的内容)
sudo yum 列表可用 | grep postgre(我错过了 postgresql-devel)
sudo yum install postgresql-devel (我安装了它)
sudo gem install pg (这次没有错误!)

$ 宝石列表 --local | grep
pg (0.11.0)
于 2011-06-18T22:59:40.157 回答
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...
于 2012-07-31T16:16:08.200 回答
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
于 2011-10-24T05:35:55.057 回答
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 编译)感到高兴。

于 2011-01-22T15:35:58.527 回答