service postgresql restart と reload
CentOS 5.x postgresql-server-8.1
restart
psqlでポスグレのサーバに接続しておく。
$ psql testdb Welcome to psql 8.1.23, the PostgreSQL interactive terminal. Type: \copyright for distribution terms \h for help with SQL commands \? for help with psql commands \g or terminate with semicolon to execute query \q to quit testdb=> \d No relations found. testdb=>
サービスをrestartする。
# service postgresql restart postgresql サービスを停止中: [ OK ] postgresql サービスを開始中: [ OK ]
restart時にはpsql側に何も出ませんが、何か(\d)実行したところで管理者の命令で接続を終了した等言われて、再接続が行われます。
testdb=> \d FATAL: terminating connection due to administrator command server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. The connection to the server was lost. Attempting reset: Succeeded. testdb=>
ポスグレのログを見ると管理者の命令で接続を終了したとの「FATAL: terminating connection due to administrator command」が記録されています。
2015-07-04 23:12:40 JST LOG: received fast shutdown request 2015-07-04 23:12:40 JST LOG: aborting any active transactions 2015-07-04 23:12:40 JST FATAL: terminating connection due to administrator command 2015-07-04 23:12:40 JST FATAL: terminating connection due to administrator command 2015-07-04 23:12:40 JST LOG: shutting down 2015-07-04 23:12:40 JST LOG: database system is shut down 2015-07-04 23:12:40 JST LOG: logger shutting down 2015-07-04 23:12:41 JST LOG: database system was shut down at 2015-07-04 23:12:40 JST 2015-07-04 23:12:41 JST LOG: checkpoint record is at 1E/2F185324 2015-07-04 23:12:41 JST LOG: redo record is at 1E/2F185324; undo record is at 0/0; shutdown TRUE 2015-07-04 23:12:41 JST LOG: next transaction ID: 26492163; next OID: 74066 2015-07-04 23:12:41 JST LOG: next MultiXactId: 1; next MultiXactOffset: 0 2015-07-04 23:12:41 JST LOG: database system is ready 2015-07-04 23:12:41 JST LOG: transaction ID wrap limit is 1073813240, limited by database "postgres"
reload
psqlで接続した状態でサービスをreloadしてみます。
# service postgresql reload #
接続は切れていません。
testdb=> \d No relations found. testdb=>
ポスグレのログを見ると、SIGHUPを受信して、設定ファイルをリロードした旨が記録されています。
2015-07-04 23:26:30 JST LOG: received SIGHUP, reloading configuration files
設定ファイルの変更を反映させるときは reload の方がクライアントに迷惑をかけないと言えそうです。
reload 時に何をやっているか
/etc/rc.d/init.d/postgresql を見ると pg_ctl reload しています。
235 reload(){ 236 $SU -l postgres -c "$PGENGINE/pg_ctl reload -D '$PGDATA' -s" > /dev/null 2>&1 < /dev/null 237 }
日本語ドキュメント(HTML版)によると、
https://www.postgresql.jp/document/8.1/html/app-pg-ctl.html
reloadモードは、単にpostmasterにSIGHUPシグナルを送り、(postgresql.conf、pg_hba.confなどの)設定ファイルを再読み込みを実行させます。 これにより、完全な再起動をすることなく、設定ファイルのオプションの変更を反映させることができます。