KILL

功能描述

终止指定连接或该连接下执行的SQL语句。

注意事项

  • KILL语法在非线程池模式和线程池模式下均有效。
  • 一般结合SHOW PROCESSSLIST的查询结果Id字段使用。
  • 也可以结合select sessionid from pg_stat_activity where (过滤条件) 使用

语法格式

1. KILL [CONNECTION | QUERY] processlist_id

参数说明

  • CONNECTION

使用CONNECTION关键字修饰KILL语句时,效果等价于KILL processlist_id,终止当前连接。 - QUERY

使用QUERY关键字修饰KILL语句时,终止当前连接执行的SQL语句,连接本身不受影响。 - processlist_id

连接Id。

示例

1. --查看当前连接
2. openGauss=# show processlist;
3. Id        |       Pid       |      QueryId      | UniqueSqlId |   User    | Host |    db    |        Command         |
4. BackendStart          |           XactStart           |  Time  | State  |                  Info
5. -----------------+-----------------+-------------------+-------------+-----------+------+----------+------------------------+---
6. ----------------------------+-------------------------------+--------+--------+----------------------------------------
7. 139653370304256 | 139653370304256 |                 0 |           0 | opengauss |      | postgres | ApplyLauncher          | 20
8. 22-06-21 16:46:19.656076+08 |                               |        |        |
9. 139653319255808 | 139653319255808 |                 0 |           0 | opengauss |      | postgres | Asp                    | 20
10. 22-06-21 16:46:19.728521+08 |                               |      1 | active |
11. 139653336483584 | 139653336483584 |                 0 |           0 | opengauss |      | postgres | PercentileJob          | 20
12. 22-06-21 16:46:19.728527+08 |                               |      8 | active |
13. 139653302175488 | 139653302175488 |                 0 |           0 | opengauss |      | postgres | statement flush thread | 20
14. 22-06-21 16:46:19.728558+08 |                               | 508507 | idle   |
15. 139653198239488 | 139653198239488 |                 0 |           0 | opengauss |      | postgres | WorkloadMonitor        | 20
16. 22-06-21 16:46:19.750133+08 |                               |        |        |
17. 139653181298432 | 139653181298432 |                 0 |           0 | opengauss |      | postgres | WLMArbiter             | 20
18. 22-06-21 16:46:19.750976+08 |                               |        |        |
19. 139653215110912 | 139653215110912 |                 0 |           0 | opengauss |      | postgres | workload               | 20
20. 22-06-21 16:46:19.754504+08 | 2022-06-21 16:46:19.769585+08 | 508507 | active | WLM fetch collect info from data nodes
21. 139653421840128 | 139653421840128 |                 0 |           0 | opengauss |      | postgres | JobScheduler           | 20
22. 22-06-27 10:00:54.754007+08 |                               |      0 | active |
23. 139653044328192 | 139653044328192 | 48976645947655327 |  1772643515 | opengauss | -1   | dolphin  | gsql                   | 20
24. 22-06-27 14:00:53.163338+08 | 2022-06-27 14:01:26.794658+08 |      0 | active | show processlist;
25. 139653027546880 | 139653027546880 | 48976645947655326 |  1775585557 | opengauss | -1   | postgres | gsql                   | 20
26. 22-06-27 14:01:03.969962+08 | 2022-06-27 14:01:19.967521+08 |      7 | active | select pg_sleep(100);
27. (10 rows)

29. --终止139653027546880连接执行的SQL语句
30. openGauss=# kill query 139653027546880;
31. result
32. --------
33. t
34. (1 row)

36. --查看processlist的139653027546880连接状态,已经变为idle
37. openGauss=# show processlist;
38. Id        |       Pid       |      QueryId      | UniqueSqlId |   User    | Host |    db    |        Command         |
39. BackendStart          |           XactStart           |  Time  | State  |                  Info
40. -----------------+-----------------+-------------------+-------------+-----------+------+----------+------------------------+---
41. ----------------------------+-------------------------------+--------+--------+----------------------------------------
42. 139653370304256 | 139653370304256 |                 0 |           0 | opengauss |      | postgres | ApplyLauncher          | 20
43. 22-06-21 16:46:19.656076+08 |                               |        |        |
44. 139653319255808 | 139653319255808 |                 0 |           0 | opengauss |      | postgres | Asp                    | 20
45. 22-06-21 16:46:19.728521+08 |                               |      0 | active |
46. 139653336483584 | 139653336483584 |                 0 |           0 | opengauss |      | postgres | PercentileJob          | 20
47. 22-06-21 16:46:19.728527+08 |                               |      5 | active |
48. 139653302175488 | 139653302175488 |                 0 |           0 | opengauss |      | postgres | statement flush thread | 20
49. 22-06-21 16:46:19.728558+08 |                               | 508573 | idle   |
50. 139653198239488 | 139653198239488 |                 0 |           0 | opengauss |      | postgres | WorkloadMonitor        | 20
51. 22-06-21 16:46:19.750133+08 |                               |        |        |
52. 139653181298432 | 139653181298432 |                 0 |           0 | opengauss |      | postgres | WLMArbiter             | 20
53. 22-06-21 16:46:19.750976+08 |                               |        |        |
54. 139653215110912 | 139653215110912 |                 0 |           0 | opengauss |      | postgres | workload               | 20
55. 22-06-21 16:46:19.754504+08 | 2022-06-21 16:46:19.769585+08 | 508573 | active | WLM fetch collect info from data nodes
56. 139653421840128 | 139653421840128 |                 0 |           0 | opengauss |      | postgres | JobScheduler           | 20
57. 22-06-27 10:00:54.754007+08 |                               |      1 | active |
58. 139653044328192 | 139653044328192 | 48976645947655329 |  1772643515 | opengauss | -1   | dolphin  | gsql                   | 20
59. 22-06-27 14:00:53.163338+08 | 2022-06-27 14:02:33.180256+08 |      0 | active | show processlist;
60. 139653027546880 | 139653027546880 |                 0 |           0 | opengauss | -1   | postgres | gsql                   | 20
61. 22-06-27 14:01:03.969962+08 |                               |     11 | idle   | select pg_sleep(100);
62. (10 rows)

64. --终止139653027546880连接
65. openGauss=# kill 139653027546880;
66. result
67. --------
68. t
69. (1 row)

71. --或

73. openGauss=# kill connection 139653027546880;
74. result
75. --------
76. t
77. (1 row)

79. --查看processlist中已经不存在该连接
80. openGauss=# show processlist;
81. Id        |       Pid       |      QueryId      | UniqueSqlId |   User    | Host |    db    |        Command         |
82. BackendStart          |           XactStart           |  Time  | State  |                  Info
83. -----------------+-----------------+-------------------+-------------+-----------+------+----------+------------------------+---
84. ----------------------------+-------------------------------+--------+--------+----------------------------------------
85. 139653370304256 | 139653370304256 |                 0 |           0 | opengauss |      | postgres | ApplyLauncher          | 20
86. 22-06-21 16:46:19.656076+08 |                               |        |        |
87. 139653319255808 | 139653319255808 |                 0 |           0 | opengauss |      | postgres | Asp                    | 20
88. 22-06-21 16:46:19.728521+08 |                               |      1 | active |
89. 139653336483584 | 139653336483584 |                 0 |           0 | opengauss |      | postgres | PercentileJob          | 20
90. 22-06-21 16:46:19.728527+08 |                               |      7 | active |
91. 139653302175488 | 139653302175488 |                 0 |           0 | opengauss |      | postgres | statement flush thread | 20
92. 22-06-21 16:46:19.728558+08 |                               | 508696 | idle   |
93. 139653198239488 | 139653198239488 |                 0 |           0 | opengauss |      | postgres | WorkloadMonitor        | 20
94. 22-06-21 16:46:19.750133+08 |                               |        |        |
95. 139653181298432 | 139653181298432 |                 0 |           0 | opengauss |      | postgres | WLMArbiter             | 20
96. 22-06-21 16:46:19.750976+08 |                               |        |        |
97. 139653215110912 | 139653215110912 |                 0 |           0 | opengauss |      | postgres | workload               | 20
98. 22-06-21 16:46:19.754504+08 | 2022-06-21 16:46:19.769585+08 | 508696 | active | WLM fetch collect info from data nodes
99. 139653421840128 | 139653421840128 |                 0 |           0 | opengauss |      | postgres | JobScheduler           | 20
100. 22-06-27 10:00:54.754007+08 |                               |      1 | active |
101. 139653044328192 | 139653044328192 | 48976645947655331 |  1772643515 | opengauss | -1   | dolphin  | gsql                   | 20
102. 22-06-27 14:00:53.163338+08 | 2022-06-27 14:04:35.418518+08 |      0 | active | show processlist;
103. (9 rows)