from Hacker News

How to Find and Stop Running Queries on PostgreSQL

by j4mie on 6/20/22, 12:15 PM with 15 comments

  • by superb-owl on 6/20/22, 8:20 PM

    This process has saved me from an outage more than once.

    I keep a dashboard of running pids, and get alerts when any of them take more than N minutes (excepting autovacuum). Once every few months I have to psql into prod and cancel one.

  • by unnouinceput on 6/21/22, 1:26 AM

    Quote: "Windows does not have a kill command..."

    Yes, she does. It's called "taskkill"

  • by natmaka on 6/23/22, 12:08 PM

    https://github.com/dalibo/pg_activity ('a top-like application for PostgreSQL server activity monitoring') is quite useful.
  • by faizshah on 6/21/22, 1:56 AM

    This is really nice, are there any preventative measures one could take as well? For example setting a max query run time or something like that?
  • by aidos on 6/20/22, 9:26 PM

    Ooohh. That pg_blocking_pids(blockedpid) function is a nice one to add to the arsenal.
  • by SnowHill9902 on 6/20/22, 10:32 PM

    How can you find and stop users which are accessing a certain table?
  • by devoutsalsa on 6/21/22, 1:07 AM

    There’s always “sudo reboot”, too :)