We can choose to shutdown PostgreSQL in 3 modes:
- Smart mode
- Fast mode
- Immediate mode
You can use the flag -m to invoke PostgreSQL shutdown using a specific mode. Read More
- Smart mode: This is the default mode; hence just a stop should work. Explicitly invoking shutdown using smart mode is actually not needed.
pg_ctl -D $PGDATA stop pg_ctl -D $PGDATA stop -ms
- Fast mode: To stop PostgreSQL in fast mode, we should use -mf as shown below.
pg_ctl -D $PGDATA stop -mf
- Immediate mode: We must use -mi to stop the PostgreSQL server using immediate mode.
pg_ctl -D $PGDATA stop -mi
Explanation
- Smart mode (-ms): After receiving SIGTERM, the server disallows new connections, but lets existing sessions end their work normally. It shuts down only after all of the sessions terminate. If the server is in recovery when a smart shutdown is requested, recovery and streaming replication will be stopped only after all regular sessions have terminated.
- Fast mode (-mf): 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.
- Immediate mode (-mi): The server will send SIGQUIT to all child processes and wait for them to terminate. If any do not terminate within 5 seconds, they will be sent SIGKILL. The supervisor server process exits as soon as all child processes have exited, without doing normal database shutdown processing. This will lead to recovery (by replaying the WAL log) upon next start-up. This is recommended only in emergencies.
Cheers!
Leave a Reply