LoginSignup
39
38

More than 5 years have passed since last update.

Vagrant上のCentOS 6.6にPostgreSQL 9.3をインストールする

Posted at

Vagrant上のCentOS 6.6にPostgreSQL 9.3をインストールする手順のメモ。
CentOS 6.6の標準のPostgreSQLは8.4系だったので、PostgreSQL RPM Building Projectからインストールを行いました。

環境

今回はhttp://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-6.6_chef-provisionerless.boxのboxファイル上に環境の構築を行いました。
具体的には以下の通りです。

vagrant$ uname -a
Linux oberon-vagrant 2.6.32-504.el6.x86_64 #1 SMP Wed Oct 15 04:27:16 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
vagrant$ cat /etc/redhat-release 
CentOS release 6.6 (Final)

標準のPostgreSQLをアンインストールする

PostgreSQLサーバを停止し、パッケージをアンインストールします。

vagrant$ sudo service postgresql stop
vagrant$ sudo yum remove postgresql postgresql-devel postgresql-libs postgresql-server

PostgreSQL 9.3をインストールする

PostgreSQL RPM Building Projectのrpmを使ってインストールを行います。
上記のページからディストリビューションに合ったrpmをインストールすることで、yumリポジトリの設定が行われます。
その後、postgresql93パッケージ群のインストール、初期化、起動、自動起動の設定を行います。

vagrant$ sudo rpm -ivh http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-centos93-9.3-1.noarch.rpm
vagrant$ sudo yum install postgresql93-server postgresql93-devel
vagrant$ sudo service postgresql-9.3 initdb
vagrant$ sudo service postgresql-9.3 start
vagrant$ sudo chkconfig postgresql-9.3 on

vagrantユーザを追加する

PostgreSQL上にvagrantユーザを追加します。

vagrant$ sudo su - postgres
postgres$ createuser --superuser vagrant
postgres$ exit
vagrant$ psql -l
(テーブル一覧が表示される)

おまけ: Ruby用のPostgreSQLバインディング(pg)をビルドする

postgresql93パッケージ群を用いてPostgreSQLをインストールした場合、標準のパスとは異なる場所にインストールするため、pgのビルドに失敗します。
そのため、ビルド時にpg_configコマンドの場所を指定する必要があります。

bundleコマンドを用いる例:

vagrant$ bundle config build.pg --with-pg-config=/usr/pgsql-9.3/bin/pg_config
vagrant$ bundle install
39
38
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
39
38