なぜかPostgreSQLサーバが落ちてた。

ちょいとテンプレをいじろうと思って編集画面を開こうとしたら、

Got an error: データベース接続の設定に誤りがあります: エラーが発生しました: could not connect to server: Connection refused   Is the server running on host "localhost" and accepting   TCP/IP connections on port 5432?
って怒られた。

ん?と思って稼働状況を確認すると、PostgreSQLがStoppedになってた。
更に、よく見たらUptimeが減ってたので、おそらく何かの原因で勝手に落ちて再起動した模様。
そこは原因不明。

で、帰宅してからPostgresqlの起動を試みるも、

# /etc/rc.d/init.d/postgresql start
Starting postgresql service:[ FAILED ]

とか残念な感じになる。

何で起動しないかも全く不明で、ログを見ようと思ったらpotgresqlのログファイルらしきものが無い。
/var/log/messagesの中にもらしきものは見あたらない。

じゃぁinit.dの中のじゃなくて直で起動してやればエラーメッセージとかコンソールに出るかなと思ったら今度は、

# postmaster
"root" execution of the PostgreSQL server is not permitted.
The server must be started under an unprivileged user ID to prevent
possible system security compromise. See the documentation for
more information on how to properly start the server.

rootで起動すんな。と。
よく怒られる。

# su - postgresql
してやると、
$ postmaster FATAL: pre-existing shared memory block (key 5432001, ID 98307) is still in use HINT: If you're sure there are no old server processes still running, remove the shared memory block with the command "ipcrm", or just delete the file "/var/lib/pgsql/data/postmaster.pid".

やっとそれらしきものにたどり着いた。
死んでるはずのプロセスがメモリを使ってるみたいな感じ。
急に落ちたからpidファイルが残ってて、サーバも起動してないのにメモリ使ってるみたいに書いてるから起動できなかったみたいな感じだろーか?

ipcrmコマンドってのはよく分からないので、or以後の操作をしてやると、無事PostgreSQLを起動出来た。

$ exit
# rm -f /var/lib/pgsql/data/postmaster.pid
# /etc/rc.d/init.d/postgresql start
Starting postgresql service: [ OK ]

ログが無いのはイマイチなので、設定ファイルを編集。

# vi /var/lib/pgsql/data/postgresql.conf

#syslog = 0 # range 0-2; 0=stdout; 1=both; 2=syslog
#syslog_facility = 'LOCAL0'
#syslog_ident = 'postgres'

こんなそれっぽい3行があったので、

syslog = 2 # range 0-2; 0=stdout; 1=both; 2=syslog
syslog_facility = 'LOCAL0'
syslog_ident = 'postgres'
コメントはずして、syslogにログ吐くように"syslog = 2"としてやって、
# /etc/rc.d/init.d/postgresql restart Starting postgresql service:[ OK ]

postgresqlを再起動してやって、"/var/log/messages"を確認する。

# tail /var/log/messages
Jun 17 14:24:16 vine nmbd[992]: *****
Jun 17 14:24:45 vine pop3d: drac_update() called: DRACHOST=localhost user=::ffff:127.0.0.1
Jun 17 14:25:00 vine su(pam_unix)[32395]: session opened for user postgres by (uid=0)
Jun 17 14:25:01 vine su(pam_unix)[32395]: session closed for user postgres
Jun 17 14:25:01 vine postgres[32424]: [1-1] LOG: could not create IPv6 socket: Address family not supported by protocol
Jun 17 14:25:01 vine postgres[32431]: [2-1] LOG: database system was shut down at 2007-06-17 14:23:24 JST
Jun 17 14:25:01 vine postgres[32431]: [3-1] LOG: checkpoint record is at 0/2FD0224
Jun 17 14:25:01 vine postgres[32431]: [4-1] LOG: redo record is at 0/2FD0224; undo record is at 0/0; shutdown TRUE
Jun 17 14:25:01 vine postgres[32431]: [5-1] LOG: next transaction ID: 101879; next OID: 49939
Jun 17 14:25:01 vine postgres[32431]: [6-1] LOG: database system is ready

よしよし。これでいいでしょう。


問題が起こると設定をいじってちょっと良い感じになるのはいいけど、
結局のところ今回の根本的な問題点は、
なんでサーバマシンがOSごと落ちたのか。
なはずなんだけど、そこは「分からん」の一言で解決しようともしてないのは我ながらどーなのかと。

そして「われながら」を変換すると「wareながら」と出たATOKもどーなのかと。
懐かしすぎるから。「ware」を「割れ」って読むなんて・・・