Home GaussDB查进程锁和杀进程
Post
Cancel

GaussDB查进程锁和杀进程

通过以下SQL就能确认当前的连接用户、连接地址、连接应用、状态、是否等待锁、排队状态以及线程id

1
2
3
4
5
6
7
8
9
10
SELECT
  usename,
  client_addr,
  application_name,
  state,
  waiting,
  enqueue,
  pid
FROM
  PG_STAT_ACTIVITY;

中止某个会话连接

1
SELECT PG_TERMINATE_BACKEND(pid);

查看当前处于阻塞状态的查询语句

1
2
3
4
5
6
7
8
9
10
11
SELECT
  pid,
  datname,
  usename,
  state,
  query
FROM
  PG_STAT_ACTIVITY
WHERE
  state <> 'idle'
  and waiting = true;

查看事务有没有持有锁

1
2
3
4
5
6
7
8
9
10
11
12
select
  datname,
  usename,
  application_name,
  now() - xact_start elp,
  waiting,
  state,
  query
from
  pg_stat_activity
where
  state <> 'idle';

参考:GaussDB帮助文档

This post is licensed under CC BY 4.0 by the author.