PostgreSQL lists and stops executing SQL statements

Source: Internet
Author: User

PostgreSQL lists SQL statements in progress

  1. SELECT
  2. Procpid,
  3. Start,
  4. Now ()-start AS lap,
  5. Current_query
  6. FROM
  7. (SELECT
  8. Backendid,
  9. Pg_stat_get_backend_pid (S. backendid) AS procpid,
  10. Pg_stat_get_backend_activity_start (S. backendid) AS start,
  11. Pg_stat_get_backend_activity (S. backendid) AS current_query
  12. FROM
  13. (SELECT pg_stat_get_backend_idset () AS backendid) AS S
  14. ) AS S
  15. WHERE
  16. Current_query <>'<IDLE>'
  17. ORDER
  18. Lap DESC;

Procpid: process id
Start: process start time
Lap: elapsed time
Current_query: SQL statement in execution

How to stop executing SQL statements
SELECT pg_cancel_backend (process id );

Or use system functions.

Kill-9 process id;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.