Database PostrageSQL-Shut down the server

18.5. Shut down the server

There are several ways to shut down the database server. By sending different signals to the postgres process, you can control the type of shutdown.

SIGTERM
This is the smart shutdown mode. After receiving SIGTERM, the server will not allow new connections, but will allow existing sessions to end their work normally. It closes only when all sessions are terminated. If the server is in online backup mode, it will wait until the online backup mode is no longer activated. When the online backup mode is activated, new connections are still allowed, but only super user connections (this exception allows the super user connection to terminate the online backup mode).

If the server requests an intelligent shutdown during recovery, recovery and streaming replication will only stop after all normal sessions are terminated.

SIGINT
This is the quick shutdown mode. The server no longer allows new connections, and sends SIGTERM to all existing server processes to let them interrupt the current transaction and exit immediately. The server then waits for all server processes to exit and finally shuts down. If the service is in online backup mode, the backup mode will be terminated and render the backup useless.

SIGQUIT
This is the immediate shutdown mode. The server will send SIGQUIT to all child processes and wait for them to terminate. If any processes are not terminated within 5 seconds, they will be sent SIGKILL. The main server process will exit immediately after all child processes exit, without the need for ordinary database shutdown processing. This will result in recovery (by replaying the WAL log) at the next startup. This method is only recommended in an emergency.

The pg_ctl program provides a convenient interface for sending these signals to shut down the server. In addition, you can use kill to send these signals directly on non-Windows systems. You can use the ps program or find the postgres process PID from the postmaster.pid file in the data directory. For example, to do a quick shutdown:

$ kill -INT `head -1 /usr/local/pgsql/data/postmaster.pid`

It is best not to use SIGKILL to shut down the server. Doing so will prevent the server from releasing shared memory and semaphores, so you may need to manually complete these releases before starting a new server. In addition, when using SIGKILL to kill the postgres process, postgres will not have the opportunity to propagate the signal to its child processes, so individual child processes must be killed manually.

To terminate a single session while allowing other sessions to continue, use pg_terminate_backend() (see Table 9.78) or send a SIGTERM signal to the child processes associated with the session.

Guess you like

Origin blog.csdn.net/weixin_42528266/article/details/108593574