本文介绍了如何终止 ODP 上指定 Client Session 和 Server Session。
操作步骤
sys 租户可以通过 KILL PROXYSESSION 语句终止指定的 Session。
通过 ODP 连接的方式登录 OceanBase 集群的
sys租户。obclient -h10.xx.xx.xx -uroot@sys#obdemo -P2883 -p****** -c -A oceanbase有关更加详细的通过 ODP 连接方式连接数据库的操作指引,请参见 通过 OBClient 连接数据库。
终止指定 Client Session。
终止指定的 Client Session
KILL PROXYSESSION {cs_id | connection_id};参数说明:
cs id为 ODP 内部标记的每个 Client 的id号,connection_id为整个 OceanBase 数据库标记的每个 Client 的id号。与
KILL connection_id的作用一致。有关KILL语句的详细介绍,请参见 KILL(MySQL 模式) 或 KILL(Oracle 模式)。
示例如下:
obclient> SHOW PROXYSESSION; +--------------------+------+-----------------+--------+------+-----------------+------+-------------+-------------------+-------------------+---------+---------+ | proxy_sessid | Id | Cluster | Tenant | User | Host | db | trans_count | svr_session_count | state | tid | pid | +--------------------+------+-----------------+--------+------+-----------------+------+-------------+-------------------+-------------------+---------+---------+ | 756006681247547400 | 7 | ob1.jianhua.sjh | sys | root | 127.0.0.1:23706 | NULL | 0 | 1 | MCS_ACTIVE_READER | 2230520 | 2230520 | +--------------------+------+-----------------+--------+------+-----------------+------+-------------+-------------------+-------------------+---------+---------+ 1 row in set obclient> KILL PROXYSESSION 7; ERROR 1317 (70100): Query execution was interrupted obclient> SHOW PROXYSESSION; ERROR 2006 (HY000): MySQL server has gone away No connection. Trying to reconnect... Connection id: 8 Current database: *** NONE *** +--------------------+------+-----------------+--------+------+-----------------+------+-------------+-------------------+-------------------+---------+---------+ | proxy_sessid | Id | Cluster | Tenant | User | Host | db | trans_count | svr_session_count | state | tid | pid | +--------------------+------+-----------------+--------+------+-----------------+------+-------------+-------------------+-------------------+---------+---------+ | 756006681247547401 | 8 | ob1.jianhua.sjh | sys | root | 127.0.0.1:23715 | NULL | 0 | 1 | MCS_ACTIVE_READER | 2230520 | 2230520 | +--------------------+------+-----------------+--------+------+-----------------+------+-------------+-------------------+-------------------+---------+---------+ 1 row in set obclient> SELECT CONNECTION_ID (); +-----------------+ | connection_id() | +-----------------+ | 2147549203 | +-----------------+ 1 row in set obclient> KILL PROXYSESSION 2147549203; ERROR 1317 (70100): Query execution was interrupted obclient> SHOW PROXYSESSION; ERROR 2006 (HY000): MySQL server has gone away No connection. Trying to reconnect... Connection id: 9 Current database: *** NONE *** +--------------------+------+-----------------+--------+------+-----------------+------+-------------+-------------------+-------------------+---------+---------+ | proxy_sessid | Id | Cluster | Tenant | User | Host | db | trans_count | svr_session_count | state | tid | pid | +--------------------+------+-----------------+--------+------+-----------------+------+-------------+-------------------+-------------------+---------+---------+ | 756006681247547402 | 9 | ob1.jianhua.sjh | sys | root | 127.0.0.1:23734 | NULL | 0 | 1 | MCS_ACTIVE_READER | 2230520 | 2230520 | +--------------------+------+-----------------+--------+------+-----------------+------+-------------+-------------------+-------------------+---------+---------+ 1 row in set通过指定
cs_id或CONNECTION_ID来 KILL 当前的 Session 时,当前的连接中断,命令执行成功。使用SHOW PROXYSESSION查看时,OBClient 会重新建立 Session 连接,并执行 SQL 显示结果。您可以通过
KILL PROXYSESSION (cs_id | connection_id) ss_id语句来终止指定 Client Session 上的 Server Session。终止指定 Client Session 上的 Server Session
KILL PROXYSESSION {cs_id | connection_id} ss_id;参数说明:
id既可以是cs_id,也可以是connection_id,显示结果相同。cs_id为 ODP 内部标记的每个 Client 的id号,connection_id为整个 OceanBase 数据库标记的每个 Client 的id号。ss_id表示 ODP 内部标记每个 Server 端会话(Server Session)的id号,可以从SHOW PROXYSESSION ATTRIBUTE id中获取。详细的获取操作请参见 展示 Session 详细状态。
示例如下:
obclient> SHOW PROXYSESSION; +----------------------+-------+----------+--------+------+----------------------+------+-------------+-------------------+-------------------+-------+-------+-----------+ | proxy_sessid | Id | Cluster | Tenant | User | Host | db | trans_count | svr_session_count | state | tid | pid | using_ssl | +----------------------+-------+----------+--------+------+----------------------+------+-------------+-------------------+-------------------+-------+-------+-----------+ | 12402504630519660556 | 64940 | test420 | sys | root | 100.xx.xx.xx:63882 | NULL | 0 | 1 | MCS_ACTIVE_READER | 76286 | 76286 | 0 | +----------------------+-------+----------+--------+------+----------------------+------+------------- +-------------------+-------------------+-------+-------+-----------+ 1 row in set obclient> SHOW PROXYSESSION ATTRIBUTE 64940; +----------------------------------+----------------------+----------------+ | attribute_name | value | info | +----------------------------------+----------------------+----------------+ | proxy_sessid | -6044239443189891060 | cs common | | cs_id | 64940 | cs common | | cluster | test3233 | cs common | | tenant | sys | cs common | | user | root | cs common | | host_ip | 100.xx.xx.xx | cs common | | host_port | 63882 | cs common | | db | NULL | cs common | | total_trans_cnt | 0 | cs common | | svr_session_cnt | 1 | cs common | | active | true | cs common | | read_state | MCS_ACTIVE_READER | cs common | | tid | 76286 | cs common | | pid | 76286 | cs common | | idc_name | | cs common | | modified_time | 0 | cs stat | | reported_time | 0 | cs stat | | hot_sys_var_version | 0 | cs var version | | sys_var_version | 2 | cs var version | | user_var_version | 0 | cs var version | | last_insert_id_version | 0 | cs var version | | db_name_version | 0 | cs var version | | server_ip | xx.xx.xx.xx | last used ss | | server_port | 2881 | last used ss | | server_sessid | 3221579563 | last used ss | | ss_id | 16 | last used ss | | state | MSS_KA_CLIENT_SLAVE | last used ss | | transact_count | 2 | last used ss | | server_trans_stat | 0 | last used ss | | hot_sys_var_version | 0 | last used ss | | sys_var_version | 2 | last used ss | | user_var_version | 0 | last used ss | | last_insert_id_version | 0 | last used ss | | db_name_version | 0 | last used ss | | is_checksum_supported | 1 | last used ss | | is_safe_read_weak_supported | 0 | last used ss | | is_checksum_switch_supported | 1 | last used ss | | checksum_switch | 1 | last used ss | | enable_extra_ok_packet_for_stats | 1 | last used ss | +----------------------------------+----------------------+----------------+ 39 rows in set obclient> KILL PROXYSESSION 64940 16;