PostgreSQL 9.3.5 をソースコードからコンパイルする ( CentOS 6.2 )

PostgreSQL 9.3.5ソースコードからコンパイルしてみたのでメモを残しておきます。OS は CentOS 6.2 になります。


1.ソースコードのダウンロード


ソースコードは以下にある。wget でダウンロードする。

PostgreSQL: File Browser
http://www.postgresql.org/ftp/source/v9.3.5/

[root@centos62 ~]# mkdir /usr/local/postgres
[root@centos62 ~]# cd /usr/local/postgres/
[root@centos62 postgres]# wget https://ftp.postgresql.org/pub/source/v9.3.5/postgresql-9.3.5.tar.gz


2.コンパイル


以下のドキュメントによると GNU make、C コンパイラ ( 推奨 GCC )、tar、zlib は必須みたいなので無ければ事前にインストールしておく ( 無いわけないのもありそうですが )。

PostgreSQL: Documentation: 9.3: Requirements
http://www.postgresql.org/docs/9.3/static/install-requirements.html

あとオプションですが readline はインストールしておきました。

[root@centos62 postgresql-9.3.5]# yum -y install readline readline-devel

インストールディレクトリは /usr/local/postgres/9.3.5 としてコンパイルする。

[root@centos62 postgres]# tar zxvf postgresql-9.3.5.tar.gz
[root@centos62 postgres]# mkdir /usr/local/postgres/9.3.5
[root@centos62 postgres]# cd postgresql-9.3.5
[root@centos62 postgresql-9.3.5]# ./configure --prefix=/usr/local/postgres/9.3.5/
[root@centos62 postgresql-9.3.5]# make
[root@centos62 postgresql-9.3.5]# make install

PostgreSQL installation complete.」出たら成功ですかね。

[root@centos62 postgresql-9.3.5]# ll /usr/local/postgres/9.3.5/
合計 16
drwxr-xr-x 2 root root 4096  9月  9 23:00 2015 bin
drwxr-xr-x 6 root root 4096  9月  9 23:00 2015 include
drwxr-xr-x 4 root root 4096  9月  9 23:00 2015 lib
drwxr-xr-x 6 root root 4096  9月  9 23:00 2015 share


3.動作確認


せっかくインストールしたのでちょっと動作確認を。環境変数の設定なりいろいろと必要みたいなので、そのあたりと、あとデータベース作成、テーブル作成、データ挿入ぐらいまで順にやってみます。

環境変数の設定 ( /home/postgres/.bashrc あたりに設定しておくと後々らくですね )

export POSTGRES_HOME=/usr/local/postgres/9.3.5
export LD_LIBRARY_PATH=$POSTGRES_HOME/lib
export PGDATA=$POSTGRES_HOME/data
export PATH=$POSTGRES_HOME/bin:$PATH

■ ユーザの作成

[root@centos62 postgresql-9.3.5]# useradd postgres
[root@centos62 postgresql-9.3.5]# passwd postgres

■ データディレクトリの作成

[root@centos62 postgresql-9.3.5]# mkdir /usr/local/postgres/9.3.5/data
[root@centos62 postgresql-9.3.5]# chown postgres:postgres /usr/local/postgres/9.3.5/data/

■ initdb の実行

[root@centos62 postgresql-9.3.5]# su - postgres
[postgres@centos62 ~]$ initdb 

■ データベースの起動

[postgres@centos62 ~]$ pg_ctl -w start

■ 接続、データベース ( testdb ) の作成

[postgres@centos62 ~]$ psql postgres
postgres=# create database testdb;
CREATE DATABASE
postgres=# \l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | postgres | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 | 
 template0 | postgres | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 testdb    | postgres | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 | 
(4 rows)

postgres=# \q

■ テーブル作成、データ挿入

[postgres@centos62 ~]$ psql testdb
psql (9.3.5)
Type "help" for help.

testdb=# create table t1 (n integer);
CREATE TABLE
testdb=# insert into t1 values (1);
INSERT 0 1
testdb=# select * from t1;
 n 
---
 1
(1 row)

■ データベースの停止

[postgres@centos62 ~]$ pg_ctl stop


PostgreSQL: Documentation: 9.3: Post-Installation Setup
http://www.postgresql.org/docs/9.3/static/install-post.html

PostgreSQL: Documentation: 9.3: Creating a Database Cluster
http://www.postgresql.org/docs/9.3/static/creating-cluster.html

PostgreSQL: Documentation: 9.3: Starting the Database Server
http://www.postgresql.org/docs/9.3/static/server-start.html


とりあえず無事動いてそうです。以上です。

[ 環境情報 ]
CentOS 6.2
PostgresSQL 9.3.5