# gem install dbi Fetching: deprecated-2.0.1.gem (100%) Fetching: dbi-0.4.5.gem (100%) Successfully installed deprecated-2.0.1 Successfully installed dbi-0.4.5 2 gems installed Installing ri documentation for deprecated-2.0.1... Installing ri documentation for dbi-0.4.5... Installing RDoc documentation for deprecated-2.0.1... Installing RDoc documentation for dbi-0.4.5...楽勝。次、dbd-pgだ。
# gem install dbd-pg
Fetching: pg-0.12.2.gem (100%)
Building native extensions. This could take a while...
ERROR: Error installing dbd-pg:
ERROR: Failed to build gem native extension.
/usr/bin/ruby extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
--with-pg-config=/path/to/pg_config
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.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/bin/ruby
--with-pg
--without-pg
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/lib
--with-pg-config
--without-pg-config
--with-pg_config
--without-pg_config
Gem files will remain installed in /usr/lib/ruby/gems/1.9.1/gems/pg-0.12.2 for inspection.
Results logged to /usr/lib/ruby/gems/1.9.1/gems/pg-0.12.2/ext/gem_make.out
ぐぬぬ。libpq-fe.hがないって?あーん?develいれてなかったから入れてみる。#yum install postgresql91-devel.x86_64 Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: ftp.nara.wide.ad.jp * epel: ftp.kddilabs.jp * extras: ftp.nara.wide.ad.jp * updates: ftp.nara.wide.ad.jp Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package postgresql91-devel.x86_64 0:9.1.2-1PGDG.rhel5 set to be updated --> Finished Dependency Resolution Dependencies Resolved ========================================================================================== Package Arch Version Repository Size ========================================================================================== Installing: postgresql91-devel x86_64 9.1.2-1PGDG.rhel5 pgdg91 1.6 M Transaction Summary ========================================================================================== Install 1 Package(s) Upgrade 0 Package(s) Total download size: 1.6 M Is this ok [y/N]: y Downloading Packages: postgresql91-devel-9.1.2-1PGDG.rhel5.x86_64.rpm | 1.6 MB 00:01 Running rpm_check_debug Running Transaction Test Finished Transaction Test Transaction Test Succeeded Running Transaction Installing : postgresql91-devel 1/1 Installed: postgresql91-devel.x86_64 0:9.1.2-1PGDG.rhel5 Complete!うっし、もう一回!
# gem install dbd-pg
Building native extensions. This could take a while...
ERROR: Error installing dbd-pg:
ERROR: Failed to build gem native extension.
/usr/bin/ruby extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
--with-pg-config=/path/to/pg_config
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.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/bin/ruby
--with-pg
--without-pg
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/lib
--with-pg-config
--without-pg-config
--with-pg_config
--without-pg_config
Gem files will remain installed in /usr/lib/ruby/gems/1.9.1/gems/pg-0.12.2 for inspection.
Results logged to /usr/lib/ruby/gems/1.9.1/gems/pg-0.12.2/ext/gem_make.out
ぐぎぎぎぎ。pg_configがないって?見落としてた。言われるままに再チャレンジ!#gem install dbd-pg -- --with-pg_config=/usr/pgsql-9.1/bin/pg_config Building native extensions. This could take a while... Fetching: dbd-pg-0.3.9.gem (100%) Successfully installed pg-0.12.2 Successfully installed dbd-pg-0.3.9 2 gems installed Installing ri documentation for pg-0.12.2... Installing ri documentation for dbd-pg-0.3.9... Installing RDoc documentation for pg-0.12.2... Installing RDoc documentation for dbd-pg-0.3.9...お、うまくいったっぽい?
試してみる。
# irb
irb(main):001:0> require 'dbi'
=> true
irb(main):002:0> dbh = DBI.connect('dbi:Pg:dozaemon:localhost','dozaemon','')
=> #<DBI::DatabaseHandle:0x00・・・以下略>
irb(main):003:0> dbh.select_one('select version()')
=> ["PostgreSQL 9.1.2 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-51), 64-bit"]
irb(main):004:0> exit
でけた!#昨日のセットアップのままだとパスワードはいらないっす。