CentOS5でpostgresql84-serverをインストールし起動までの備忘録です。
CentOSなので、yumコマンドを利用してPostgreSQLをインストールしました。
rootユーザで以下のコマンドを実行するとPostgreSQL8.4がインストールされます。
yum install postgresql84-server
依存パッケージとしてpostgresql84-server以外に2つのファイルも同時にインストールされました。
$ rpm -qa | grep postgresql84 postgresql84-libs-8.4.9-1.el5_7.1 postgresql84-8.4.9-1.el5_7.1 postgresql84-server-8.4.9-1.el5_7.1
yum infoコマンドを利用してインストールされたパッケージのサマリーを確認してみます。
# yum info postgresql84 <snip> Installed Packages Name : postgresql84 Arch : x86_64 Version : 8.4.9 Release : 1.el5_7.1 Size : 14 M Repo : installed Summary : PostgreSQL client programs URL : http://www.postgresql.org/ License : PostgreSQL <snip>
$ yum info postgresql84-libs <snip> Installed Packages Name : postgresql84-libs Arch : x86_64 Version : 8.4.9 Release : 1.el5_7.1 Size : 590 k Repo : installed Summary : The shared libraries required for any PostgreSQL clients URL : http://www.postgresql.org/ License : PostgreSQL <snip>
$yum info postgresql84-server <snip> Installed Packages Name : postgresql84-server Arch : x86_64 Version : 8.4.9 Release : 1.el5_7.1 Size : 14 M Repo : installed Summary : The programs needed to create and run a PostgreSQL server <snip>
yum install コマンドによりCentOSにPostgreSQLのインストールが完了したのでrootユーザで以下のコマンドで起動してみます。
service postgresql start
# service postgresql start /var/lib/pgsql/data is missing. Use "service postgresql initdb" to
initialize the cluster first.
[失敗]
起動に失敗してしまいました。
原因はinitdbをしていないためなので、以下のコマンドでinitdbをします。
service postgresql initdb
# service postgresql initdb データベースを初期化中: [ OK ]
データベースの初期化が完了しました。
再度、PostgreSQLサーバの起動を試みます。
# service postgresql start postgresql サービスを開始中: [ OK ]
無事PostgreSQL起動することができました。
上記では、start, initdbのオプションを渡しています。
このオプションは/etc/init.d/postgresqlに渡される引数になります。
各種オプションがあるので、/etc/init.d/postgresqlスクリプトを確認すると良いかもしれません。
initdbの付近を抜粋すると以下のようになっています。
<snip>
restart(){
stop
start
}
condrestart(){
[ -e /var/lock/subsys/${NAME} ] && restart
}
condstop(){
[ -e /var/lock/subsys/${NAME} ] && stop
}
reload(){
$SU -l postgres -c "$PGENGINE/pg_ctl reload -D '$PGDATA' -s" > /dev/null 2>&1 < /dev/null
}
initdb(){
if [ -f "$PGDATA/PG_VERSION" ]
then
echo -n "Data directory is not empty!"
echo_failure
echo
script_result=1
else
echo -n $"Initializing database: "
if [ ! -e "$PGDATA" -a ! -h "$PGDATA" ]
then
<snip>
サーバの再起動時に自動的にPostgreSQLが起動するようにするには、以下のコマンドを利用します。
checkconfig postgresql on
これでサーバ立ち上げ時にPostgreSQLが起動するようになります。
この意味を簡単に説明します。
chkconfig --listコマンドでpostgresqlの状態がどのようになっているかを確認します。
# chkconfig --list | grep postgresql postgresql 0:off 1:off 2:off 3:off 4:off 5:off 6:off
0〜6まではランレベルを示しており、全てがoffなので起動しません。
以下、chkconfig postgresql onを実行後、再度chkconfig --listで確認した結果です。
ランレベルが2〜5がonになっています。
これで、サーバ立ち上げ時にPostgreSQLが起動するようになります。
# chkconfig postgresql on # chkconfig --list | grep postgresql postgresql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
また、PostgreSQLの自動起動を無効にしたい場合は、rootユーザで以下のコマンドによりoffになります。
chkconfig postgresql off
ただし、PostgreSQLは停止しません。(次回サーバー起動時に自動起動しなくなるだけです。)
停止したい場合は、rootユーザで以下のコマンドにより停止します。
service postgresql stop
# service postgresql stop postgresql サービスを停止中: [ OK ]