This topic describes how to terminate a client session or a server session on OceanBase Database Proxy (ODP).
Terminate a specified client session
You can use the KILL PROXYSESSION (cs_id | connection_id) statement to terminate a client session.
Take note of the following considerations:
In the statement,
idcan be replaced withcs_idorconnection_id. These parameters are equivalent.cs_idindicates the IDof a client session in ODP. `connection_id` indicates the IDof a client session in OceanBase Database.The effect of
KILL PROXYSESSION (cs_id | connection_id)is the same as that ofKILL connection_id. For more information about theKILLstatement, see KILL (MySQL Mode) or KILL (Oracle Mode).
You can use the KILL PROXYSESSION (cs_id | connection_id) ss_id statement to terminate a server session on a client session.
Take note of the following considerations:
In the statement,
idcan be replaced withcs_idorconnection_id. These parameters are equivalent.cs_idindicates the ID of a client session in ODP.connection_idindicates the ID of a client session in OceanBase Database.ss_idindicates theIDof a server session on ODP, and can be obtained by using theSHOW PROXYSESSION ATTRIBUTE idstatement. For more information, see Query the details of a session.
Here are some examples:
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
If you perform a kill session operation by specifying a cs_id or connection_id value and the specified session is terminated, the operation is successful. If you execute the SHOW PROXYSESSION statement, OBClient re-establishes a session connection, starts the statement execution, and then returns the result.