Skip to content
This repository has been archived by the owner on Oct 20, 2023. It is now read-only.

Latest commit

 

History

History
35 lines (29 loc) · 514 Bytes

managing_queries.md

File metadata and controls

35 lines (29 loc) · 514 Bytes

Managing queries

List longest running queries

SELECT
      DATEDIFF(minutes, starttime, GETDATE()) AS duration_minutes,
      *,
      'SELECT PG_CANCEL_BACKEND(' || pid || ');'
FROM
      STV_RECENTS
WHERE
      status = 'Running'
ORDER BY
      starttime ASC
;

Kill a query by PID

SELECT PG_CANCEL_BACKEND(pid)

Get pids of running queries for a given user

SELECT DISTINCT
      pid
FROM
      STV_RECENTS
WHERE
      status = 'Running'
      AND user_name = 'xxx'
;