1.查询数据库中的锁信息

SELECT * FROM pg_locks;

2.查询等待锁的线程状态信息

SELECT * FROM pg_thread_wait_status WHERE wait_status = 'acquire lock';

3.结束系统进程

ps ux

kill -9 pid

4.查询事件的线程启动时间、事务启动时间、SQL启动时间以及状态变更时间。

SELECT backend_start,xact_start,query_start,state_change FROM pg_stat_activity;

5.查询当前服务器的会话计数信息

SELECT count(*) FROM pg_stat_activity;

6.查询当前使用内存最多的会话信息

SELECT * FROM pv_session_memory_detail() ORDER BY usedsize desc limit 10;

7.查询表统计信息

SELECT * FROM pg_statistic;

8.查询分区表信息

SELECT * FROM pg_partition;

9.终止进程

9.1查找数据库进程

openGauss=# select pid,sessionid,query,state from pg_stat_activity;

      pid       |    sessionid    |                          query                          |        state        

-----------------+-----------------+---------------------------------------------------------+---------------------

140015279462144 | 140015279462144 | create table t2(id int);                                | idle in transaction

140015296243456 | 140015296243456 | select pid,sessionid,query,state from pg_stat_activity; | active

140015497623296 | 140015497623296 |                                                         |  

140015480841984 | 140015480841984 |                                                         |  

140015514404608 | 140015514404608 | WLM fetch collect info from data nodes                  | active

140015730394880 | 140015730394880 |                                                         | active

140015713613568 | 140015713613568 |                                                         | active

140015763957504 | 140015763957504 |                                                         |  

140015814301440 | 140015814301440 |                                                         | active

140015696832256 | 140015696832256 |                                                         | idle

(10 rows)

9.2 终止进程

openGauss=# SELECT pg_terminate_backend(140015279462144);

pg_terminate_backend  

----------------------

t

(1 row)

openGauss=#  

9.3 killed进程客户端,执行后续命令end,自动连接数据库

openGauss=# begin;    

BEGIN

openGauss=# create table t2(id int);

CREATE TABLE

openGauss=# end;

FATAL:  terminating connection due to administrator command

could not send data to server: Broken pipe

The connection to the server was lost. Attempting reset: Succeeded.

openGauss=#