Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Postgresql Learning Notes (3) connection Management

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

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

(1) find out the list of active connections and their process ID

Select * from pg_stat_activity

(2) cancel the active query on the connection

Select pg_cancel_backend (procid)

This action does not terminate the connection itself

(3) terminate the connection

Select pg_terminate_backend (procid)

If you terminate a connection without stopping the statements that are being executed on the connection, those statements will be stopped at this time. After the execution of step 2 above, the suspended state of the client application is released, that is, the client can re-execute the statement, and some anxious users will execute the statement that has just been terminated again at this time, which will cause the system to fall into the previous state. To avoid this situation, you can use the direct

The way to terminate the connection.

If you want to terminate all connections to a user at once, you can execute the following statement on version 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'

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report