Postgresql – What do I do when pg_cancel_backend doesn’t work

databasepostgresqlsql

If I have a long-running Postgres query, and regular "kill [pid]" doesn't work, and pg_cancel_backend doesn't work, what should I do?

Best Answer

http://www.postgresql.org/docs/current/static/server-shutdown.html

pg_cancel_backend is equivalent to sending SIGINT to the process.
pg_terminate_backend likewise for SIGTERM, but if pg_cancel_backend isn't working I don't see why pg_terminate_backend would.

If you've tried those options, you could try SIGQUIT. The docs say, "This is recommended only in emergencies."

(If you hate your data and hope it dies, you could use SIGKILL. But I wouldn't.)

You can use either kill directly or pg_ctl kill.