Stopping the server in an emergency
If nothing else is working, we may need to stop the server quickly, without caring about disconnecting the clients gently.
Break the glass in case of emergency!
How to do it…
- The basic command to perform an emergency stop on the server is the following:
pg_ctl -D datadir stop -m immediate
- On Debian/Ubuntu, you can also use the following:
pg_ctlcluster 11 main stop -m immediate
As we mentioned in the previous recipe, this is just a wrapper around pg_ctl
. From this example, we can see that it can pass through the -m immediate
option.
Note
In the previous recipe, we have seen examples where the systemctl
command was used to stop a server safely; however, that command cannot be used to perform an emergency stop.
How it works…
When you do an immediate stop, all users have their transactions aborted and all connections are disconnected. There is no clean shutdown, nor is there politeness of any kind.
An immediate mode stop is similar to a database crash. Some cached files...