PostgreSQLのソースを入手しソースからコンパイルしインストールする手順を記します。
最新のPostgreSQLを試してみたり、プライベートな環境を構築することができます。
使用したOSはCentOS5, CentOS6の2つです。
CentOS5, CentOS6で操作に差異がある場合は、別途記述します。
NPO法人 日本PostgreSQLユーザ会からPostgreSQLのソースコードをダウンロードすることができます。
ブラウザを利用してダウンロードしてもよいですし、wgetやcurlコマンドを利用してダウンロードしてもよいでしょう。
本資料では、ブラウザを利用してダウンロードします。
本資料作成時の最新バージョンである、9.1.4のソースコードを利用します。
CentOSで開発環境をインストールしていない場合は、以下の資料を参考に開発環境(ツール)をインストールしてください。
以下、CentOS上での作業です。
ユーザアカウントはsakuraで行います。
以下の通り、ダウンロードしたPostgreSQLのソースコードはアカウントsakuraのホームディレクトリに保存しました。
[sakura@centos ~]$ pwd /home/sakura [sakura@centos ~]$ ls -l 合計 19984 -rw-r--r-- 1 sakura sakura 20437875 8月 8 22:56 postgresql-9.1.4.tar.gz
CentOS5, CentOS6でPostgreSQLをソースコードからコンパイルするために必要なパッケージなどを以下に記します。
以下にパッケージがインストールされていない場合にconfigureコマンドを利用すると出力される警告やエラーについて記します。
コンパイルとインストールに進む方は「コンパイル&インストール」に進んでください。
configureで以下のWARNINGが出力される原因はflexのバージョンが古いためです。
以下リンクはflexをソースコードからインストールする記事です。
記事を参考にflexをインストールしてください。
checking for flex... configure: WARNING: *** The installed version of Flex, /usr/bin/flex, is too old to use with PostgreSQL. *** Flex version 2.5.31 or later is required, but this is /usr/bin/flex version 2.5.4. configure: WARNING: *** The installed version of Flex, /usr/bin/lex, is too old to use with PostgreSQL. *** Flex version 2.5.31 or later is required, but this is /usr/bin/lex version 2.5.4. no configure: WARNING: *** Without Flex you will not be able to build PostgreSQL from Git nor *** change any of the scanner definition files. You can obtain Flex from *** a GNU mirror site. (If you are using the official distribution of *** PostgreSQL then you do not need to worry about this because the Flex *** output is pre-generated.)
configure時に以下のメッセージが表示された場合は、readline-develがインストールされていないためです。
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.
rootになり、以下のコマンドでreadline-develをインストールしてください。
yum -y install readline-devel
configure時に以下のメッセージが表示された場合は、zlib-develがインストールされていないためです。
configure: error: zlib library not found If you have zlib already installed, see config.log for details on the failure. It is possible the compiler isn't looking in the proper directory. Use --without-zlib to disable zlib support.
rootになり、以下のコマンドでzlib-develをインストールしてください。
yum -y install zlib-devel
以下の手順でPostgreSQLのソースコードのコンパイルとインストールを行います。
tar zxvf postgresql-9.1.4.tar.gz展開が完了するとホームディレクトリは以下のようになります。
[sakura@centos ~]$ ls -ltr 合計 19988 drwxrwxr-x 6 sakura sakura 4096 6月 1 08:25 postgresql-9.1.4 -rw-r--r-- 1 sakura sakura 20437875 8月 8 22:56 postgresql-9.1.4.tar.gzpostgresql-9.1.4ディレクトリが作成されPostgreSQLのソースなど一式が格納されています。
cd postgresql-9.1.4
./configure --prefix=$HOME/pgsql上記の--prefixはインストールするディレクトリになります。
make
All of PostgreSQL successfully made. Ready to install.
[sakura@centos postgresql-9.1.4]$ make install <snip> PostgreSQL installation complete.
[sakura@centos postgresql-9.1.4]$ ls -l $HOME/pgsql 合計 16 drwxrwxr-x 2 sakura sakura 4096 8月 9 00:00 bin drwxrwxr-x 6 sakura sakura 4096 8月 9 00:00 include drwxrwxr-x 3 sakura sakura 4096 8月 9 00:00 lib drwxrwxr-x 6 sakura sakura 4096 8月 9 00:00 share
ホームディレクトリ内にインストールしたPostgreSQLを起動するために以下のようにPATHを設定します。
.bashrcなどに追記すれば以後、有効になります。
export PATH=$HOME/pgsql/bin:$PATH
[sakura@centos postgresql-9.1.4]$ which initdb ~/pgsql/bin/initdb
[sakura@centos postgresql-9.1.4]$ cd [sakura@centos ~]$ initdb -D $HOME/sakura The files belonging to this database system will be owned by user "sakura". This user must also own the server process. <snip> creating directory /home/sakura/sakura ... ok creating subdirectories ... ok selecting default max_connections ... 100 selecting default shared_buffers ... 32MB creating configuration files ... ok creating template1 database in /home/sakura/sakura/base/1 ... ok <snip> Success. You can now start the database server using: postgres -D /home/sakura/sakura or pg_ctl -D /home/sakura/sakura -l logfile start
[sakura@centos ~]$ ls -l sakura/ 合計 80 -rw------- 1 sakura sakura 4 8月 9 00:07 PG_VERSION drwx------ 5 sakura sakura 4096 8月 9 00:07 base drwx------ 2 sakura sakura 4096 8月 9 00:07 global drwx------ 2 sakura sakura 4096 8月 9 00:07 pg_clog -rw------- 1 sakura sakura 4470 8月 9 00:07 pg_hba.conf -rw------- 1 sakura sakura 1636 8月 9 00:07 pg_ident.conf drwx------ 4 sakura sakura 4096 8月 9 00:07 pg_multixact drwx------ 2 sakura sakura 4096 8月 9 00:07 pg_notify drwx------ 2 sakura sakura 4096 8月 9 00:07 pg_serial drwx------ 2 sakura sakura 4096 8月 9 00:07 pg_stat_tmp drwx------ 2 sakura sakura 4096 8月 9 00:07 pg_subtrans drwx------ 2 sakura sakura 4096 8月 9 00:07 pg_tblspc drwx------ 2 sakura sakura 4096 8月 9 00:07 pg_twophase drwx------ 3 sakura sakura 4096 8月 9 00:07 pg_xlog -rw------- 1 sakura sakura 19168 8月 9 00:07 postgresql.conf
[sakura@centos ~]$ pg_ctl -D $HOME/sakura start server starting [sakura@centos ~]$ LOG: database system was shut down at 2012-08-09 00:07:32 JST LOG: autovacuum launcher started LOG: database system is ready to accept connectionsEnterキーを押せばプロンプトが戻ってきます。
[sakura@centos ~]$ psql postgres psql (9.1.4) Type "help" for help. postgres=# select now(); now ------------------------------- 2012-08-09 00:13:27.710802+09 (1 row) postgres-# \q
[sakura@centos ~]$ pg_ctl stop -D $HOME/sakura LOG: received smart shutdown request LOG: autovacuum launcher shutting down LOG: shutting down waiting for server to shut down....LOG: database system is shut down done server stopped