pg_ctl kill
$ pg_ctl --help
Usage:
pg_ctl kill SIGNALNAME PID
Allowed signal names for kill:
ABRT HUP INT QUIT TERM USR1 USR2
pg_ctl kill TERM
# /etc/init.d/postgresql restart
# ps -ef|grep -i post|grep -v grep
postgres 8454 1 0 14:13 ? 00:00:00 /usr/lib/postgresql/9.6/bin/postgres -D /data/pg9.6/main -c config_file=/etc/postgresql/9.6/main/postgresql.conf
postgres 8455 8454 0 14:13 ? 00:00:00 postgres: 9.6/main: logger process
postgres 8457 8454 0 14:13 ? 00:00:00 postgres: 9.6/main: checkpointer process
postgres 8458 8454 0 14:13 ? 00:00:00 postgres: 9.6/main: writer process
postgres 8459 8454 0 14:13 ? 00:00:00 postgres: 9.6/main: wal writer process
postgres 8460 8454 0 14:13 ? 00:00:00 postgres: 9.6/main: autovacuum launcher process
postgres 8461 8454 0 14:13 ? 00:00:00 postgres: 9.6/main: archiver process
postgres 8462 8454 0 14:13 ? 00:00:00 postgres: 9.6/main: stats collector process
postgres 8490 8454 0 14:13 ? 00:00:00 postgres: 9.6/main: wal sender process repl 192.168.56.92(34380) streaming 0/1E0000D0
postgres 8502 7488 0 14:15 pts/0 00:00:00 /usr/lib/postgresql/9.6/bin/psql
postgres 8510 8454 0 14:15 ? 00:00:00 postgres: 9.6/main: postgres postgres [local] idle
$ pg_ctl kill TERM 8454
2018-11-30 14:16:03.798 CST,,,8454,,5c00d516.2106,3,,2018-11-30 14:13:42 CST,,0,LOG,00000,"received smart shutdown request",,,,,,,,,""
2018-11-30 14:16:03.798 CST,,,8460,,5c00d516.210c,2,,2018-11-30 14:13:42 CST,1/0,0,LOG,00000,"autovacuum launcher shutting down",,,,,,,,,""
pg_ctl kill INT
# /etc/init.d/postgresql restart
# ps -ef|grep -i post|grep -v grep
postgres 8568 1 0 14:25 ? 00:00:00 /usr/lib/postgresql/9.6/bin/postgres -D /data/pg9.6/main -c config_file=/etc/postgresql/9.6/main/postgresql.conf
postgres 8569 8568 0 14:25 ? 00:00:00 postgres: 9.6/main: logger process
postgres 8571 8568 0 14:25 ? 00:00:00 postgres: 9.6/main: checkpointer process
postgres 8572 8568 0 14:25 ? 00:00:00 postgres: 9.6/main: writer process
postgres 8573 8568 0 14:25 ? 00:00:00 postgres: 9.6/main: wal writer process
postgres 8574 8568 0 14:25 ? 00:00:00 postgres: 9.6/main: autovacuum launcher process
postgres 8575 8568 0 14:25 ? 00:00:00 postgres: 9.6/main: archiver process
postgres 8576 8568 0 14:25 ? 00:00:00 postgres: 9.6/main: stats collector process
postgres 8605 8568 0 14:25 ? 00:00:00 postgres: 9.6/main: wal sender process repl 192.168.56.92(34392) streaming 0/1F0000D0
postgres 8609 7488 0 14:26 pts/0 00:00:00 /usr/lib/postgresql/9.6/bin/psql
postgres 8617 8568 0 14:26 ? 00:00:00 postgres: 9.6/main: postgres postgres [local] idle
$ pg_ctl kill INT 8568
2018-11-30 14:27:20.260 CST,,,8568,,5c00d7e5.2178,3,,2018-11-30 14:25:41 CST,,0,LOG,00000,"received fast shutdown request",,,,,,,,,""
2018-11-30 14:27:20.260 CST,,,8568,,5c00d7e5.2178,4,,2018-11-30 14:25:41 CST,,0,LOG,00000,"aborting any active transactions",,,,,,,,,""
2018-11-30 14:27:20.260 CST,"postgres","postgres",8617,"[local]",5c00d80b.21a9,3,"idle",2018-11-30 14:26:19 CST,3/0,0,FATAL,57P01,"terminating connection due to administrator command",,,,,,,,,"psql"
2018-11-30 14:27:20.260 CST,"postgres","postgres",8617,"[local]",5c00d80b.21a9,4,"idle",2018-11-30 14:26:19 CST,,0,LOG,00000,"disconnection: session time: 0:01:00.280 user=postgres database=postgres host=[local]",,,,,,,,,"psql"
2018-11-30 14:27:20.262 CST,,,8574,,5c00d7e5.217e,2,,2018-11-30 14:25:41 CST,1/0,0,LOG,00000,"autovacuum launcher shutting down",,,,,,,,,""
2018-11-30 14:27:20.269 CST,,,8571,,5c00d7e5.217b,1,,2018-11-30 14:25:41 CST,,0,LOG,00000,"shutting down",,,,,,,,,""
2018-11-30 14:27:20.678 CST,,,8571,,5c00d7e5.217b,2,,2018-11-30 14:25:41 CST,,0,LOG,00000,"checkpoint starting: shutdown immediate",,,,,,,,,""
2018-11-30 14:27:20.823 CST,,,8571,,5c00d7e5.217b,3,,2018-11-30 14:25:41 CST,,0,LOG,00000,"checkpoint complete: wrote 0 buffers (0.0%); 0 transaction log file(s) added, 0 removed, 0 recycled; write=0.000 s, sync=0.000 s, total=0.150 s; sync files=0, longest=0.000 s, average=0.000 s; distance=16384 kB, estimate=16384 kB",,,,,,,,,""
2018-11-30 14:27:21.092 CST,"repl","",8605,"192.168.56.92:34392",5c00d7e9.219d,3,"streaming 0/20000098",2018-11-30 14:25:45 CST,,0,LOG,00000,"disconnection: session time: 0:01:35.875 user=repl database= host=192.168.56.92 port=34392",,,,,,,,,"walreceiver"
2018-11-30 14:27:21.104 CST,,,8568,,5c00d7e5.2178,5,,2018-11-30 14:25:41 CST,,0,LOG,00000,"database system is shut down",,,,,,,,,""
pg_ctl kill QUIT
# /etc/init.d/postgresql restart
# ps -ef|grep -i post|grep -v grep
postgres 8652 1 0 14:31 ? 00:00:00 /usr/lib/postgresql/9.6/bin/postgres -D /data/pg9.6/main -c config_file=/etc/postgresql/9.6/main/postgresql.conf
postgres 8653 8652 0 14:31 ? 00:00:00 postgres: 9.6/main: logger process
postgres 8655 8652 0 14:31 ? 00:00:00 postgres: 9.6/main: checkpointer process
postgres 8656 8652 0 14:31 ? 00:00:00 postgres: 9.6/main: writer process
postgres 8657 8652 0 14:31 ? 00:00:00 postgres: 9.6/main: wal writer process
postgres 8658 8652 0 14:31 ? 00:00:00 postgres: 9.6/main: autovacuum launcher process
postgres 8659 8652 0 14:31 ? 00:00:00 postgres: 9.6/main: archiver process
postgres 8660 8652 0 14:31 ? 00:00:00 postgres: 9.6/main: stats collector process
postgres 8668 8652 0 14:31 ? 00:00:00 postgres: 9.6/main: wal sender process repl 192.168.56.92(34504) streaming 0/200000D0
postgres 8693 7488 1 14:32 pts/0 00:00:00 /usr/lib/postgresql/9.6/bin/psql
postgres 8701 8652 0 14:32 ? 00:00:00 postgres: 9.6/main: postgres postgres [local] idle
$ pg_ctl kill QUIT 8652
2018-11-30 14:33:24.257 CST,,,8652,,5c00d95a.21cc,3,,2018-11-30 14:31:54 CST,,0,LOG,00000,"received immediate shutdown request",,,,,,,,,""
2018-11-30 14:33:24.257 CST,"postgres","postgres",8701,"[local]",5c00d99a.21fd,3,"idle",2018-11-30 14:32:58 CST,3/0,0,WARNING,57P02,"terminating connection because of crash of another server process","The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.","In a moment you should be able to reconnect to the database and repeat your command.",,,,,,,"psql"
2018-11-30 14:33:24.258 CST,"repl","",8668,"192.168.56.92:34504",5c00d95c.21dc,3,"streaming 0/200000D0",2018-11-30 14:31:56 CST,2/0,0,WARNING,57P02,"terminating connection because of crash of another server process","The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.","In a moment you should be able to reconnect to the database and repeat your command.",,,,,,,"walreceiver"
2018-11-30 14:33:24.264 CST,,,8658,,5c00d95a.21d2,2,,2018-11-30 14:31:54 CST,1/0,0,WARNING,57P02,"terminating connection because of crash of another server process","The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.","In a moment you should be able to reconnect to the database and repeat your command.",,,,,,,""
2018-11-30 14:33:24.272 CST,,,8652,,5c00d95a.21cc,4,,2018-11-30 14:31:54 CST,,0,LOG,00000,"archiver process (PID 8659) exited with exit code 1",,,,,,,,,""
2018-11-30 14:33:24.274 CST,,,8706,"192.168.56.92:34506",5c00d9b4.2202,1,"",2018-11-30 14:33:24 CST,,0,LOG,00000,"connection received: host=192.168.56.92 port=34506",,,,,,,,,""
2018-11-30 14:33:24.279 CST,"repl","",8706,"192.168.56.92:34506",5c00d9b4.2202,2,"",2018-11-30 14:33:24 CST,,0,FATAL,57P03,"the database system is shutting down",,,,,,,,,""
2018-11-30 14:33:24.292 CST,,,8652,,5c00d95a.21cc,5,,2018-11-30 14:31:54 CST,,0,LOG,00000,"database system is shut down",,,,,,,,,""
pg_ctl kill HUP
# /etc/init.d/postgresql restart
# ps -ef|grep -i post|grep -v grep
postgres 8746 1 0 14:37 ? 00:00:00 /usr/lib/postgresql/9.6/bin/postgres -D /data/pg9.6/main -c config_file=/etc/postgresql/9.6/main/postgresql.conf
postgres 8747 8746 0 14:37 ? 00:00:00 postgres: 9.6/main: logger process
postgres 8752 8746 0 14:37 ? 00:00:00 postgres: 9.6/main: checkpointer process
postgres 8753 8746 0 14:37 ? 00:00:00 postgres: 9.6/main: writer process
postgres 8754 8746 0 14:37 ? 00:00:00 postgres: 9.6/main: wal writer process
postgres 8755 8746 0 14:37 ? 00:00:00 postgres: 9.6/main: autovacuum launcher process
postgres 8756 8746 0 14:37 ? 00:00:00 postgres: 9.6/main: archiver process
postgres 8757 8746 0 14:37 ? 00:00:00 postgres: 9.6/main: stats collector process
postgres 8803 8746 0 14:37 ? 00:00:00 postgres: 9.6/main: wal sender process repl 192.168.56.92(34610) streaming 0/20000178
postgres 8804 7488 0 14:37 pts/0 00:00:00 /usr/lib/postgresql/9.6/bin/psql
postgres 8812 8746 0 14:37 ? 00:00:00 postgres: 9.6/main: postgres postgres [local] idle
$ pg_ctl kill HUP 8746
2018-11-30 14:38:59.359 CST,,,8746,,5c00daa9.222a,3,,2018-11-30 14:37:29 CST,,0,LOG,00000,"received SIGHUP, reloading configuration files",,,,,,,,,"
pg_ctl kill ABRT
# /etc/init.d/postgresql restart
# ps -ef|grep -i post|grep -v grep
postgres 8848 1 0 14:41 ? 00:00:00 /usr/lib/postgresql/9.6/bin/postgres -D /data/pg9.6/main -c config_file=/etc/postgresql/9.6/main/postgresql.conf
postgres 8849 8848 0 14:41 ? 00:00:00 postgres: 9.6/main: logger process
postgres 8851 8848 0 14:41 ? 00:00:00 postgres: 9.6/main: checkpointer process
postgres 8852 8848 0 14:41 ? 00:00:00 postgres: 9.6/main: writer process
postgres 8853 8848 0 14:41 ? 00:00:00 postgres: 9.6/main: wal writer process
postgres 8854 8848 0 14:41 ? 00:00:00 postgres: 9.6/main: autovacuum launcher process
postgres 8855 8848 0 14:41 ? 00:00:00 postgres: 9.6/main: archiver process
postgres 8856 8848 0 14:41 ? 00:00:00 postgres: 9.6/main: stats collector process
postgres 8895 8848 0 14:41 ? 00:00:00 postgres: 9.6/main: wal sender process repl 192.168.56.92(34614) streaming 0/21000098
postgres 8896 7488 0 14:41 pts/0 00:00:00 /usr/lib/postgresql/9.6/bin/psql
postgres 8904 8848 0 14:41 ? 00:00:00 postgres: 9.6/main: postgres postgres [local] idle
$ pg_ctl kill ABRT 8848
2018-11-30 14:42:32.934 CST,"repl","",8895,"192.168.56.92:34614",5c00dba8.22bf,3,"streaming 0/210000D0",2018-11-30 14:41:44 CST,,0,LOG,00000,"disconnection: session time: 0:00:48.066 user=repl database= host=192.168.56.92 port=34614",,,,,,,,,"walreceiver"
2018-11-30 14:42:32.943 CST,"postgres","postgres",8904,"[local]",5c00dbab.22c8,3,"idle",2018-11-30 14:41:47 CST,3/0,0,FATAL,57P01,"terminating connection due to unexpected postmaster exit",,,,,,,,,"psql"
2018-11-30 14:42:32.943 CST,"postgres","postgres",8904,"[local]",5c00dbab.22c8,4,"idle",2018-11-30 14:41:47 CST,,0,LOG,00000,"disconnection: session time: 0:00:45.196 user=postgres database=postgres host=[local]",,,,,,,,,"psql"
pg_ctl kill USR1
pg_ctl kill USR2
试了没啥日志输出,今天先这样,后面再补充。
总结:
pg_ctl kill TERM pid = pg_ctl stop -m smart
pg_ctl kill INT pid = pg_ctl stop -m fast
pg_ctl kill QUIT pid = pg_ctl stop -m immediate
pg_ctl kill HUP pid = pg_ctl reload
pg_ctl kill ABRT pid = 类似于关闭电源
pg_ctl kill USR1 pid =
pg_ctl kill USR2 pid =