CentOSにPostgreSQL9.1をソースからインストールする。

まずはコマンド用、データベース用のディレクトリを作成します。

mkdir /usr/local/pgsql9.1
mkdir /var/lib/pgsql9.1
mkdir /var/lib/pgsql9.1/data
chown postgres:postgres /usr/local/pgsql9.1/
chown -Rf postgres:postgres /var/lib/pgsql9.1/


次にソースをダウンロードします。
日本PostgreSQLの会からソースをダウンロードし、解凍します。

cd /usr/local/src/
wget ftp://ftp2.jp.postgresql.org/pub/postgresql/source/v9.1.0/postgresql-9.1.0.tar.gz
tar zxvf postgresql-9.1.0.tar.gz


パスとポート番号を指定してコンパイルを行います。

cd postgresql-9.1.0
./configure --prefix=/usr/local/pgsql9.1/ --with-pgport=5551
make
make install

※複数PostgreSQLをインストールする場合にはポート番号を指定してconfigureします。


もしconfigureで以下のようなエラーが発生した場合readline、zlibのインストールが必要です。

configure: error: readline library not found
If you have readline already installed, see config.log for details on the
failure. It is possible the compiler isn't looking in the proper directory.
Use --without-readline to disable readline support.


readlineはyumでインストールします。

yum install readline readline-devel


zlibは投稿日のバージョン1.2.3ではだめだったため、最新版の1.2.5をソースからインストールします。

cd /usr/local/src/
wget http://zlib.net/zlib-1.2.5.tar.gz
tar zcvf zlib-1.2.5.tar.gz

cd zlib-1.2.5
./conifigure
make
make install


次にデータベースの初期化を行います。

cd /usr/local/pgsql9.1/bin/
./initdb -D /var/lib/pgsql9.1/data --no-locale --encoding=UTF-8


次に設定ファイルの変更を行います。

vi /var/lib/pgsql9.1/data/postgresql.conf


postgresql.confは以下の内容を修正してください。

port=5551


起動スクリプトを作成します。

cp /usr/local/src/postgresql-9.1.0/contrib/start-scripts/linux /etc/rc.d/init.d/postgresql9.1


コピーした起動スクリプトの以下を修正します。

prefix=/usr/local/pgsql9.1

PGDATA=/var/lib/pgsql9.1/data


後は以前の記事の内容に従って設定すれば大丈夫です。