POSTGRESQL View user usage and kill the corresponding process

Source: Internet
Author: User
Tags postgres database

One, to see which users are linked to the database

Select  from Pg_stat_activity;

The pg_stat_activity here is actually a view, and its definition can be found in the View section of the Postgres database.

Second, kill the process now we find all the processes connected to the database, then how to kill those Idel process to release the connection? If the PG version is 8.4 and above, it is easy to kill all Idel processes with the following statement:
SELECT  from WHERE current_query='<IDLE>'
Pg_terminate_backend is the internal method of PG, and there is another called Pg_cancel_backend, which has existed in the previous version of 8.4. The difference between the two methods is:
    • Pg_cancel_backend just cancels the query operation of one of the current processes, but cannot release the database connection
    • Pg_terminate_backend can kill this process in the background of PG, thus freeing up valuable connection resources

POSTGRESQL View user usage and kill the corresponding process

Related Article

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.