2010年2月25日木曜日

PostgreSQLをソースからビルド

ubuntu8.04 LTS Serverで、PostgreSQLをソースからビルドする手順です。

コンパイラなどのビルドに必要なパッケージがインストールされていないときは、build-essentialをインストールします。
$ sudo apt-get install build-essential

ビルドに必要なパッケージをインストールします。
sudo apt-get install libreadline5-dev zlib1g-dev

PostgreSQLの管理者のpostgresユーザーを作成します。
$ sudo adduser postgres
Adding user `postgres' ...
Adding new group `postgres' (1001) ...
Adding new user `postgres' (1001) with group `postgres' ...
Creating home directory `/home/postgres' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for postgres
Enter the new value, or press ENTER for the default
        Full Name []:
        Room Number []:
        Work Phone []:
        Home Phone []:
        Other []:
Is the information correct? [y/N] y

PostgreSQLのディレクトリを作成します。
$ sudo mkdir /usr/local/pgsql
sudo chown postgres:postgres /usr/local/pgsql

ソースをダウンロードしてきます。今回は現時点で最新の8.4.2を使います。
$ cd /usr/local/src
sudo wget ftp://ftp2.jp.postgresql.org/pub/postgresql/source/v8.4.2/postgresql-8.4.2.tar.gz
sudo tar zxvf postgresql-8.4.2.tar.gz
sudo chown -R postgres:postgres postgresql-8.4.2

ユーザーをpostgresに切り替えてビルドします。
$ su - postgres
Password:
$ cd /usr/local/src/postgresql-8.4.2/
$ ./configure
$ make
$ make install

postgresユーザーの環境変数の設定を行います。
~/.profileの末尾に
# User specific environment and startup programs
PGHOME=/usr/local/pgsql
PGDATA=$PGHOME/data
PGLIB=$PGHOME/lib
PATH=$PATH:$HOME/bin:$PGHOME/bin
export PGHOME PGDATA PGLIB PATH
を追加して、
$ source ~/.profile
で環境変数の反映します。

PostgreSQLの初期化を行います。
$ initdb --no-locale

postgresユーザーから元のユーザーに戻ります。
$ exit

/etc/ld.so.confにライブラリを追加します。
sudo vi /etc/ld.so.conf
で、/usr/local/pgsql/libを追加して、
sudo ldconfig -v
を実行します。

OS起動時にPostgreSQLが自動起動するように設定します。
$ sudo cp /usr/local/src/postgresql-8.4.2/contrib/start-scripts/linux /etc/init.d/postgresql
$ sudo chmod 755 /etc/init.d/postgresql
$ sudo update-rc.d postgresql start 90 2 3 4 5 . stop 10 0 1 6 .

PostgreSQLを起動します。
$ sudo /etc/init.d/postgresql start

0 コメント :

コメントを投稿