Terminating A Connection
Consider the scenario where you are trying to drop a database, but there are existing connections.
If you don't know where these connections are, you can terminate them within a psql
session. You just have to figure out the pid
of those connections. In List Connections To A Database, I explained how to get at the pid
values of connections. Using the pid
value and pg_terminate_backend()
, you can terminate a connection.
To terminate all connections to a particular database, use a query like the following:
This excludes the current session, so you'll need to exit psql
as well before dropping the database.
Last updated