psql -d appdb -c "SELECT pg_terminate_backend(12345);"

Category: Databases & SQL

psql -d appdb -c "SELECT pg_terminate_backend(12345);"

Kill a backend connection

Forcefully ends the backend with the given pid, rolling back its current transaction and dropping its connection. Take the pid from pg_stat_activity. Prefer pg_cancel_backend when the query might still finish.
Looking for more? Search all 7,657 commands — works offline, in English or Spanish, and fixes typos.