How to stop PostgreSQL in an emergency?
Sometimes DBAs need to stop PostgreSQL Server on an emergency notice. In such situations, DBAs cannot even wait for client connections to close gracefully, This post is for such scenarios:
Step 1: The basic command to stop the PostgreSQL server is as follows:
1 |
pg_ctl -D datadir stop -m immediate |
Step 2: On Debian/Ubuntu, you can also use the following command:
1 |
pg_ctlcluster 14 main stop -m immediate |
pg_ctlcluster -m (immediate option) will immediately terminate/abort all the transactions and connections. This method is so similar to a PostgreSQL Server crash and the system will undergo crash recovery with a few cached files will be rebuilt.