How to shut down postgres database
-m : This option is used to provide the “shutdown signal” to the database server. We can also give only first letter of the signal to this option.
-D : Cluster data directory location. If we export PGDATA variable , we no need this option. I have already set the variable so I am not using this option.
smart : (SIGTERM for kill command)
[postgres@node1 data]$ pg_ctl -m smart stop
waiting for server to shut down…. done
server stopped
(OR)
[postgres@node1 data]$ kill -s SIGTERM `head -1 /opt/PostgreSQL/9.5/data/postmaster.pid`
[postgres@node1 data]$ echo $?
0
We can observe the below info in the log file of postgres..
2016-02-06 17:57:05 IST LOG: received smart shutdown request
2016-02-06 17:57:05 IST LOG: autovacuum launcher shutting down
2016-02-06 17:57:05 IST LOG: shutting down
2016-02-06 17:57:05 IST LOG: database system is shut down
NOTE : Mode is case sensitive , need give mode only in small letters.
fast : (SIGINT for kill command)
This is the Fast Shutdown mode. The server disallows new connections and sends all existing server processes SIGTERM, which will cause them to abort their current transactions and exit promptly. It then waits for all server processes to exit and finally shuts down. If the server is in online backup mode, backup mode will be terminated, rendering the backup useless.
[postgres@node1 data]$ pg_ctl -m fast stop
waiting for server to shut down…. done
server stopped
(OR)
[postgres@node1 data]$ kill -s SIGINT `head -1 /opt/PostgreSQL/9.5/data/postmaster.pid`
[postgres@node1 data]$ echo $?
0
We can observe the below info in the log file of postgres..
2016-02-06 18:25:11 IST LOG: received fast shutdown request
2016-02-06 18:25:11 IST LOG: aborting any active transactions
2016-02-06 18:25:11 IST LOG: autovacuum launcher shutting down
2016-02-06 18:25:11 IST LOG: shutting down
2016-02-06 18:25:11 IST LOG: database system is shut down
immediate : (SIGQUIT for kill command)
This will terminate the server processes abruptly which causes the recovery from WAL logs at the time of startup.
[postgres@node1 data]$ pg_ctl -m immediate stop
waiting for server to shut down…. done
server stopped
(OR)
[postgres@node1 data]$ kill -s SIGQUIT `head -1 /opt/PostgreSQL/9.5/data/postmaster.pid`
[postgres@node1 data]$ echo $?
0
We can observe the below info in the log file of postgres.
2016-02-06 18:33:02 IST LOG: received immediate shutdown request
2016-02-06 18:33:02 IST WARNING: terminating connection because of crash of another server process
2016-02-06 18:33:02 IST DETAIL: 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.
2016-02-06 18:33:02 IST HINT: In a moment you should be able to reconnect to the database and repeat your command.