markdown Postgresql杀挂查询

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown Postgresql杀挂查询相关的知识,希望对你有一定的参考价值。

# PostgreSQL 

How to find and kill a hanging query

First, check all the processes that are running:
```
SELECT * FROM pg_stat_activity WHERE state = 'active';
```
Find processes which are running longer than 5 min:
```
SELECT
  pid,
  now() - pg_stat_activity.query_start AS duration,
  query,
  state
FROM pg_stat_activity
WHERE (now() - pg_stat_activity.query_start) > interval '5 minutes';
```
So you can identify the PID of the hanging query you want to terminate, run this:
```
SELECT pg_cancel_backend(PID);
```
This query might take a while to kill the query, so if you want to kill it the hard way, run this instead:
```
SELECT pg_terminate_backend(PID);
```

以上是关于markdown Postgresql杀挂查询的主要内容,如果未能解决你的问题,请参考以下文章

markdown PostgreSQL的

markdown 更改postgreSQL用户密码

markdown 更改postgreSQL用户密码

markdown PostgreSQL索引提示

markdown Metasploit连接Postgresql

markdown PostgreSQL设计规则