こんにちは、まっさんです
ご覧頂きありがとうございます
お客様のデータベースサーバのメンテナンスで嵌まったというお話です。
結論から言うと、接続するポートで違う古いデータベースに接続しているのに気付かなかったというお話です。
データベースにログインしてテーブルの一覧表示すると途中までしか表示されないので、そんな特殊なことやってるの?
とか思ってましたが、仕様上ありえないと思い
まず、pg_dumpコマンド叩いてフルバックアップして内容チェックしてみようと思い
pg_dump叩くと、
# which pg_dump
/usr/bin/pg_dump
# pg_dump -V
pg_dump (PostgreSQL) 9.2.5
あれ?とここで!?と・・なんか変だなと
pg_dumpこんな古いバージョン使用してたかなと
コマンド検索したら複数現る
$ find / -name pg_dump -print
/usr/local/src/postgresql-9.6.5/src/bin/pg_dump
/usr/pgsql-9.6/bin/pg_dump
/usr/pgsql-9.2/bin/pg_dump
/usr/bin/pg_dump
その後、フルダンプしたテーブルを語句抽出かけたら必要なテーブルにデータが入ってる・・・
ん~・・・・という事は・・・。
バージョンアップをしていたようで、その際違うポートで運用していたのが、思い込みというやつで
見えてなかった模様。
なので、次失敗しないようにメモと備忘録
Linuxで運用しているので原則コマンドラインでの確認。
今までの慣例でポート5432で運用しているものだと思っていたので
-bash-4.1$ psql -d ”データベース名" -U postgres
Password for user postgres:
でパスワード入力でログインしていました。
後で履歴コマンドみてたら、-p 5433の文字がありましたが、疲れて入力ミスしていたかなと思ってたら
疲れているのは自分だったという。
Listenポート確認したらふたつ動いてる
-bash-4.1$ netstat -l -n | grep 5432
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN
tcp 0 0 ::1:5432 :::* LISTEN
unix 2 [ ACC ] STREAM LISTENING 14740 /tmp/.s.PGSQL.5432
-bash-4.1$ netstat -l -n | grep 5433
tcp 0 0 0.0.0.0:5433 0.0.0.0:* LISTEN
tcp 0 0 :::5433 :::* LISTEN
unix 2 [ ACC ] STREAM LISTENING 14738 /tmp/.s.PGSQL.5433
まさかまさかのinit.dを確認したら
# /etc/rc.d/init.d/postgresql-9.タブ補完
postgresql-9.2 postgresql-9.6
ということで、サービス起動の状態確認したら
# /etc/rc.d/init.d/postgresql-9.2 status
(pid 2626) を実行中...
# /etc/rc.d/init.d/postgresql-9.6 status
pg_ctl: server is running (PID: 2574)
/usr/pgsql-9.6/bin/postgres "-D" "/home/pgsql/9.6/data"
自動起動どうなってるのかなと確認したら
自動起動はOFFなはずなんだけど、メンテナンスで起動させてた模様
これはこれで色々怖い。
# chkconfig --list | grep postgres
postgresql-9.2 0:off 1:off 2:off 3:off 4:off 5:off 6:off
postgresql-9.6 0:off 1:off 2:on 3:on 4:on 5:on 6:off
旧データ動かしてた~という具合で、
ログイン開始したときにもバージョン表示されてましたがスルーしてた。
(新)
-bash-4.1$ psql -h localhost -p 5433 -U postgres
Password for user postgres:
psql (9.6.5)
Type "help" for help.
(旧)
-bash-4.1$ psql -h localhost -p 5432 -U postgres
psql (9.6.5, server 9.2.5)
Type "help" for help.
後で気づいたのはpostgresql.confとpg_hba.conf ファイル検索しとけば解決早かったかもというもの
# find /home -name postgresql.conf -print
/home/pgsql/9.6/data/postgresql.conf
/home/pgsql/9.2/data/postgresql.conf
# grep -B1 'port' /home/pgsql/9.6/data/postgresql.conf
以下結果
--------------------------------------------------------------------------------------
# (change requires restart)
port = 5433 # (change requires restart)
--
dynamic_shared_memory_type = posix # the default is the first option
# supported by the operating system:
--
#wal_sync_method = fsync # the default is the first option
# supported by the operating system:
--
# %d = database name
# %r = remote host and port
--------------------------------------------------------------------------------------
# find /home -name pg_hba.conf -print
/home/pgsql/9.6/data/pg_hba.conf
/home/pgsql/9.2/data/pg_hba.conf
# ps -ef | grep postmaster
postgres 2574 1 0 Jun11 ? 00:02:04 /usr/pgsql-9.6/bin/postmaster -D /home/pgsql/9.6/data
postgres 2626 1 0 Jun11 ? 00:00:28 /usr/pgsql-9.2/bin/postmaster -p 5432 -D /home/pgsql/9.2/data
pidを番号見る限り先に9.6の方が若いけど、なんで起動しているのか後で要確認ですね
アップデート後サービス落としていないのが濃厚ではあるとおもいますが。
まとめると
思い込みは怖いので注意し気を付けて
最初のところから見直しましょうというお話でした。
それでは、素敵なインターネットライフをお過ごしください
御覧頂きありがとうございました。
またのお越しをお待ちしております。
さようなら