---
title: 终止 Server Session-V3.2.4-OceanBase 数据库文档-分布式数据库使用文档
description: 分布式数据库OceanBase 企业版文档中心，提供关于终止 Server Session的相关内容，方便用户更好的应用分布式数据库OceanBaseOceanBase 数据库
image: https://mdn.alipayobjects.com/huamei_22khvb/afts/img/A*OSPzQ6GUQF4AAAAAQHAAAAgAeiGDAQ/original
---
[OceanBase AI 数据大会](https://www.oceanbase.com/conference2026 "OceanBase AI 数据大会")文档反馈![](https://mdn.alipayobjects.com/huamei_22khvb/afts/img/A*P8CuR4UJ_FkAAAAAAAAAAAAADiGDAQ/original) OceanBase 数据库分布式版 - V 3.2.4 企业版 LTS

# 终止 Server Session

更新时间：2026-06-08 15:46:36

本文介绍了如何终止 ODP 上指定 Client Session 和 Server Session。

## 操作步骤

`sys` 租户可以通过 `KILL PROXYSESSION` 语句终止指定的 Session。

1. 通过 ODP 连接的方式登录 OceanBase 集群的 `sys` 租户。

   ```shell
   obclient -h10.xx.xx.xx -uroot@sys#obdemo -P2883 -p****** -c -A oceanbase

   ```

   有关更加详细的通过 ODP 连接方式连接数据库的操作指引，请参见 [通过 OBClient 连接数据库](https://www.oceanbase.com/docs/enterprise-oceanbase-database-cn-10000000000944890)。
 2. 终止指定 Client Session。

      - 终止指定的 Client Session

       ```sql
       KILL PROXYSESSION {cs_id | connection_id};

       ```

       参数说明：

            - `cs id` 为 ODP 内部标记的每个 Client 的 `id` 号，`connection_id` 为整个 OceanBase 数据库标记的每个 Client 的 `id` 号。
            - 与 `KILL connection_id` 的作用一致。有关 `KILL` 语句的详细介绍，请参见 [KILL（MySQL 模式）](https://www.oceanbase.com/docs/enterprise-oceanbase-database-cn-10000000000945551) 或 [KILL（Oracle 模式）](https://www.oceanbase.com/docs/enterprise-oceanbase-database-cn-10000000000947109)。

       示例如下：

       ```sql
       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

       ```sql
       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 详细状态](https://www.oceanbase.com/docs/enterprise-oceanbase-database-cn-10000000000944882)。

       示例如下：

       ```sql
       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;

       ```

 上一篇 下一篇 ![有帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*y6ocSqN8cqsAAAAAAAAAAAAAARQnAQ)![无帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*BG9IQJyLHF8AAAAAAAAAAAAAARQnAQ)![反馈](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*eTWdQKCRKHwAAAAAAAAAAAAAARQnAQ) 咨询
