PostgreSQL Learning Notes (iii) connection management

Source: Internet
Author: User
Tags postgresql

Use the following three SQL statements to cancel a running query and terminate the connection

(1) Isolate the active connection list and its process ID

SELECT * from Pg_stat_activity;

(2) Cancel the active query on the connection

Select Pg_cancel_backend (PROCID);

The operation does not terminate the connection itself

(3) Terminate the connection

Select Pg_terminate_backend (PROCID);

If you do not stop the executing statement on a connection and terminate the connection directly, these statements will also be stopped at this time. After the execution of step 2 above, the client application's suspend state is dismissed, that is, the client can re-execute the statement, some anxious users will be again at this time to execute the statement just terminated, which will cause the system to fall into the previous state. In order to avoid this situation, it is possible to use direct

The way to terminate the connection.


If you want to terminate all connections for a user at once, you can execute the following statements on versions 9.2 and later:

Select Pg_terminate_backend (PID) from pg_stat_activity where username= ' some_role ';

The following statements can be executed on versions prior to version 9.2:

Select Pg_terminate_backend (procpid) from pg_stat_activity where username= ' some_role ';


This article is from the "Corasql" blog, make sure to keep this source http://corasql.blog.51cto.com/5908329/1911927

PostgreSQL Learning Notes (iii) connection management

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.