There is a way to do this with the shell utilities
pg_ctlcluster in Debian and derivates). But @filiprem's method is more accurate for several reasons:
- It only disconnects users from the database in question.
- It does not to restart the whole cluster.
- It prevents immediate reconnects, possibly spoiling the
With the --force option the "fast" mode is used which rolls back all active transactions, disconnects clients immediately and thus shuts down cleanly. If that does not work, shutdown is attempted again in "immediate" mode, which can leave the cluster in an inconsistent state and thus will lead to a recovery run at the next start. If this still does not help, the postmaster process is killed. Exits with 0 on success, with 2 if the server is not running, and with 1 on other failure conditions. This mode should only be used when the machine is about to be shut down.
pg_ctlcluster 9.1 main restart --force
pg_ctl restart -D datadir -m fast
pg_ctl restart -D datadir -m immediate
immediately followed by:
Possibly in a script for immediate succession.