#navi(../)
* PostgreSQLのCentOSインストール&起動メモ [#d448a09b]
CentOS5でpostgresql84-serverをインストールし起動までの備忘録です。~
#contents
#htmlinsertpcsp(db-top.html,db-sp.html)
* 関連資料 [#z7107e07]
-[[PostgreSQLコミュニティーベースのリポジトリを設定し最新を利用する>PostgreSQL/PostgreSQLコミュニティーベースのリポジトリを設定し最新を利用する]]
- [[CentOS/CentOS 5.4 インストール後の初期設定>http://linux.just4fun.biz/CentOS/CentOS%205.4%20%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB%E5%BE%8C%E3%81%AE%E5%88%9D%E6%9C%9F%E8%A8%AD%E5%AE%9A.html]]~
linux.just4fun.bizの記事になります。
* PostgreSQLのインストール [#ebf88953]
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
** 各パッケージの確認 [#ma31b32f]
yum infoコマンドを利用してインストールされたパッケージのサマリーを確認してみます。
- postgresql84-8.4.9 (クライアントプログラム)
# 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>
- postgresql84-libs(PostgreSQL共有ライブラリ)
$ 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>
- postgresql84-server(PostgreSQLサーバ)
$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>
* PostgreSQLの起動 [#c71a4c81]
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起動することができました。
* service postgresql の後にあるオプション [#wed5e01f]
上記では、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の自動起動 [#w726246b]
サーバの再起動時に自動的に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 ]
#htmlinsertpcsp(db-btm.html,db-sp.html)