This topic describes several general operations performed on a client session, which is established between a client and OceanBase Database Proxy (ODP).
Prerequisites
You have connected to OceanBase Database by using ODP. For more information, see Connect to an OceanBase tenant by using OBClient (MySQL mode) and Connect to an OceanBase tenant by using OBClient (Oracle mode).
View client sessions
In the sys tenant, you can use the SHOW PROXYSESSION statement to view all client sessions of all tenants in ODP. In a user tenant, you can use the SHOW PROXYSESSION statement to view all client sessions of the current tenant in ODP. Here is an example in the sys tenant:
obclient> show proxysession;
+---------------------+------+---------+--------+------+-----------------+------+-------------+-------------------+-------------------+--------+--------+-----------+
| proxy_sessid | Id | Cluster | Tenant | User | Host | db | trans_count | svr_session_count | state | tid | pid | using_ssl |
+---------------------+------+---------+--------+------+-----------------+------+-------------+-------------------+-------------------+--------+--------+-----------+
| 7230691421644980673 | 88 | ob1.cc | sys | root | 127.0.0.1:49999 | NULL | 0 | 1 | MCS_ACTIVE_READER | 120685 | 120685 | 0 |
+---------------------+------+---------+--------+------+-----------------+------+-------------+-------------------+-------------------+--------+--------+-----------+
1 row in set
The following table describes the fields in the returned result.
| Field | Description |
|---|---|
| proxy_sessid | The ID of the client session with ODP in OceanBase Database. |
| Id | The ID of the client session in ODP. It is equivalent to cs_id mentioned later. |
| Cluster | The name of the OceanBase cluster to which the client session belongs. |
| Tenant | The tenant name for connecting to the OceanBase cluster. |
| User | The username for connecting to the OceanBase cluster. |
| Host | The IP address and port number of the client. |
| db | The database in which the statement is executed. |
| trans_count | The number of transactions completed in the client session. |
| svr_session_count | The total number of sessions held between ODP and OceanBase Database. |
| state | The status of the client session. Valid values:
|
| tid | The thread ID. |
| pid | The process ID. |
| using_ssl | Indicates whether the client session uses the Secure Sockets Layer (SSL) protocol for transmission. |
View the details of a client session
You can use the SHOW PROXYSESSION ATTRIBUTE statement in the sys tenant or a user tenant to query the details of a client session, including related server sessions of this client session. The SQL syntax is as follows:
SHOW PROXYSESSION ATTRIBUTE [id [like 'xxx']]
The parameters are described as follows:
If
idis not specified, the details of the current session are returned (supported since ODP V1.1.0). Fuzzy search is supported for retrieving the value of a specified attribute in the current session (supported since ODP V1.1.2).If
idis specified, fuzzy search is supported for retrieving the value of a specified attribute (supported since ODP V1.1.0).Here, you can set
idto the value ofcs_idorconnection_id, and the same results are returned.cs_idindicates the ID of a client session in ODP.connection_idindicates the ID of a client session in OceanBase Database. In MySQL mode, you can useSELECT CONNECTION_ID();to obtain the value ofconnection_id. In Oracle mode, you can useSHOW FULL PROCESSLIST;to obtain the value ofconnection_id.Percent signs (
%) and underscores (_) are supported after thelikeoperator for fuzzy search.
Here is an example:
obclient> SHOW PROXYSESSION;
+--------------------+------+---------+--------+------+-----------------+------+-------------+-------------------+-------------------+---------+---------+
| proxy_sessid | Id | Cluster | Tenant | User | Host | db | trans_count | svr_session_count | state | tid | pid |
+--------------------+------+---------+--------+------+-----------------+------+-------------+-------------------+-------------------+---------+---------+
| 756006681247547396 | 2 | ob1.cc | sys | root | 127.0.0.1:22540 | NULL | 0 | 1 | MCS_ACTIVE_READER | 2230520 | 2230520 |
+--------------------+------+---------+--------+------+-----------------+------+-------------+-------------------+-------------------+---------+---------+
1 row in set
obclient> SHOW PROXYSESSION ATTRIBUTE;
+----------------------------------+----------------------+----------------+
| attribute_name | value | info |
+----------------------------------+----------------------+----------------+
| proxy_sessid | 756006681247547396 | cs common |
| cs_id | 2 | cs common |
| cluster | ob1.cc | cs common |
| tenant | sys | cs common |
| user | root | cs common |
| host_ip | 127.0.0.1 | cs common |
| host_port | 22540 | 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 | 2230520 | cs common |
| pid | 2230520 | cs common |
| idc_name | | cs common |
| modified_time | 1469435190244371115 | cs stat |
| reported_time | 1469435190244371115 | cs stat |
| hot_sys_var_version | 0 | cs var version |
| sys_var_version | 0 | 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 | 13203 | last used ss |
| server_sessid | 2147549201 | last used ss |
| ss_id | 4 | 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 | 0 | 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> SHOW PROXYSESSION ATTRIBUTE 2 like '%id%';
+------------------------+--------------------+----------------+
| attribute_name | value | info |
+------------------------+--------------------+----------------+
| proxy_sessid | 756006681247547396 | cs common |
| cs_id | 2 | cs common |
| tid | 2230520 | cs common |
| pid | 2230520 | cs common |
| last_insert_id_version | 0 | cs var version |
| server_sessid | 2147549201 | last used ss |
| ss_id | 4 | last used ss |
| last_insert_id_version | 0 | last used ss |
+------------------------+--------------------+----------------+
8 rows in set
obclient> SHOW PROXYSESSION ATTRIBUTE 2147549201 like '%id%';
+------------------------+--------------------+----------------+
| attribute_name | value | info |
+------------------------+--------------------+----------------+
| proxy_sessid | 756006681247547396 | cs common |
| cs_id | 2 | cs common |
| tid | 2230520 | cs common |
| pid | 2230520 | cs common |
| last_insert_id_version | 0 | cs var version |
| server_sessid | 2147549201 | last used ss |
| ss_id | 4 | last used ss |
| last_insert_id_version | 0 | last used ss |
+------------------------+--------------------+----------------+
8 rows in set
The following table describes the fields in the returned result.
| Field | Description |
|---|---|
| attribute_name | The attribute name. |
| value | The attribute value. |
| info | The basic information. |
The following table describes the general attributes.
| Attribute | Description |
|---|---|
| proxy_sessid | The ID of the client session with ODP in OceanBase Database. |
| cs_id | The ID of the client session in ODP. It is equivalent to Id mentioned earlier. |
| cluster | The name of the OceanBase cluster to which the client session belongs. |
| tenant | The tenant name for connecting to the OceanBase cluster. |
| user | The username for connecting to the OceanBase cluster. |
| host_ip | The IP address of the client. |
| host_port | The port number of the client. |
| db | The database in which the statement is executed. |
| total_trans_cnt | The total number of transactions transmitted by ODP. |
| svr_session_cnt | The total number of sessions held between ODP and OceanBase Database. |
| active | Indicates whether the session is active. |
| read_state | The status of the client session. Valid values:
|
| tid | The thread ID. |
| pid | The process ID. |
| modified_time | The time when the session was modified. |
| reported_time | The time when the session was reported. |
| hot_sys_var_version | The version of the system variable that is updated in real time. |
| sys_var_version | The system variable version. |
| user_var_version | The user variable version. |
| last_insert_id_version | The last inserted ID version. |
| db_name_version | The database name version. |
| server_ip | The IP address of the OBServer node. |
| server_port | The port number of the OBServer node. |
| server_sessid | The session ID of the OBServer node. |
| ss_id | The ID of the server session in ODP. |
View the variables of a client session
Session variables are classified into system variables and user variables. You can use the SHOW PROXYSESSION VARIABLES [all] id [like 'xx'] statement to query the variables of a client session.
If
allis not specified, the local session variables of the specified client session, including modified system and user variables, are returned.If
allis specified, all session variables of the specified client session, including all system and user variables, are returned.
The parameters are described as follows:
Here, you can set
idto the value ofcs_idorconnection_id, and the same results are returned.cs_idindicates the ID of a client session in ODP.connection_idindicates the ID of a client session in OceanBase Database. In MySQL mode, you can useSELECT CONNECTION_ID();to obtain the value ofconnection_id. In Oracle mode, you can useSHOW FULL PROCESSLIST;to obtain the value ofconnection_id.Percent signs (
%) and underscores (_) are supported after thelikeoperator for fuzzy search.
Here are some examples:
Query session variables by
cs_id.obclient> SHOW PROXYSESSION VARIABLES 3; +-----------------------------------+------------------+-----------------+--------------------+--------------------------------------------+ | variable_name | value | info | modified_type | sys_variable_flag | +-----------------------------------+------------------+-----------------+--------------------+--------------------------------------------+ | ob_proxy_global_variables_version | 1461742173142100 | changed sys var | cold modified vars | && invisible && session_scope && readonly | | ob_proxy_user_privilege | 65534 | changed sys var | cold modified vars | && invisible && session_scope && readonly | | ob_capability_flag | 654159 | changed sys var | cold modified vars | && invisible && session_scope && readonly | | ob_enable_transmission_checksum | 1 | changed sys var | cold modified vars | && global_scope && session_scope | | _min_cluster_version | '4.1.0.1' | user var | cold modified vars | | +-----------------------------------+------------------+-----------------+--------------------+--------------------------------------------+ 5 rows in setQuery session variables by
connection_id.obclient> SHOW PROXYSESSION VARIABLES 2147549231; +-----------------------------------+------------------+-----------------+--------------------+--------------------------------------------+ | variable_name | value | info | modified_type | sys_variable_flag | +-----------------------------------+------------------+-----------------+--------------------+--------------------------------------------+ | ob_proxy_global_variables_version | 1461742173142100 | changed sys var | cold modified vars | && invisible && session_scope && readonly | | ob_proxy_user_privilege | 65534 | changed sys var | cold modified vars | && invisible && session_scope && readonly | | ob_capability_flag | 654159 | changed sys var | cold modified vars | && invisible && session_scope && readonly | | ob_enable_transmission_checksum | 1 | changed sys var | cold modified vars | && global_scope && session_scope | | _min_cluster_version | '4.1.0.1' | user var | cold modified vars | | +-----------------------------------+------------------+-----------------+--------------------+--------------------------------------------+ 5 rows in setQuery session variables with
allspecified.obclient> SHOW PROXYSESSION VARIABLES all 3; +-----------------------------------+-----------------------+---------+------------------------------+-----------------------------------------------+ | variable_name | value | info | modified_type | sys_variable_flag | +-----------------------------------+-----------------------+---------+------------------------------+-----------------------------------------------+ | ob_proxy_global_variables_version | 1461742173142100 | sys var | cold modified vars | && invisible && session_scope && readonly | | ob_proxy_user_privilege | 65534 | sys var | cold modified vars | && invisible && session_scope && readonly | | ob_capability_flag | 654159 | sys var | cold modified vars | && invisible && session_scope && readonly | | ob_enable_transmission_checksum | 1 | sys var | cold modified vars | && global_scope && session_scope | | auto_increment_increment | 1 | sys var | cold modified vars | && global_scope && session_scope | | auto_increment_offset | 1 | sys var | cold modified vars | && global_scope && session_scope | ······ # Subsequent outputs omitted
The following table describes the fields in the returned result.
| Field | Description |
|---|---|
| variable_name | The name of the variable. |
| value | The value of the variable. |
| info | The type of the variable. A variable can be a system variable or a user variable. |
| modified_type | The modification type of the variable identified based on the modification frequency. |
| sys_variable_flag | The scope of the system variable. |
For more information about system variables, see System variables. For more information about how to set the user variables, see SET.
View internal statistical items of a client session
You can use the SHOW PROXYSESSION STAT statement in the sys tenant or a user tenant to view internal statistical items of a specified client session, such as the SQL response count and SQL response size. The SQL syntax is as follows:
SHOW PROXYSESSION STAT id LIKE 'xx';
The parameters are described as follows:
Here, you can set
idto the value ofcs_idorconnection_id, and the same results are returned.cs_idindicates the ID of a client session in ODP.connection_idindicates the ID of a client session in OceanBase Database. In MySQL mode, you can useSELECT CONNECTION_ID();to obtain the value ofconnection_id. In Oracle mode, you can useSHOW FULL PROCESSLIST;to obtain the value ofconnection_id.Percent signs (
%) and underscores (_) are supported after thelikeoperator for fuzzy search.
The following example queries internal statistical items by cs_id:
Obtain the
cs_idvalue.obclient> SHOW PROXYSESSION;The output is as follows, where the value of
Idis the value ofcs_id.+----------------------+-------+----------+----------+------+----------------------+------+-------------+-------------------+-------------------+-------+-------+-----------+ | proxy_sessid | Id | Cluster | Tenant | User | Host | db | trans_count | svr_session_count | state | tid | pid | using_ssl | +----------------------+-------+----------+----------+------+----------------------+------+-------------+-------------------+-------------------+-------+-------+-----------+ | 12402504630519660562 | 11 | test420 | mysql001 | root | 100.xx.xx.xx:48056 | NULL | 0 | 1 | MCS_ACTIVE_READER | 76286 | 76286 | 0 | +----------------------+-------+----------+----------+------+----------------------+------+-------------+-------------------+-------------------+-------+-------+-----------+ 1 row in setView internal statistical items.
obclient> SHOW PROXYSESSION STAT 11 LIKE '%time%';The output is as follows:
+-------------------------------------------+-------+ | stat_name | value | +-------------------------------------------+-------+ | total_transactions_time | 0 | | total_user_transactions_time | 0 | | total_client_request_read_time | 0 | | total_client_response_write_time | 0 | | total_client_request_analyze_time | 0 | | total_client_transaction_idle_time | 0 | | total_ok_packet_trim_time | 0 | | total_server_process_request_time | 0 | | total_server_response_read_time | 0 | | total_server_response_analyze_time | 0 | | total_send_saved_login_time | 0 | | total_send_all_session_vars_time | 0 | | total_send_use_database_time | 0 | | total_send_changed_session_vars_time | 0 | | total_send_changed_session_user_vars_time | 0 | | total_send_last_insert_id_time | 0 | | total_send_start_trans_time | 0 | | total_pl_lookup_time | 0 | | total_congestion_control_time | 0 | | total_server_connect_time | 0 | +-------------------------------------------+-------+ 20 rows in set
The following table describes the fields in the returned result.
| Field | Description |
|---|---|
| stat_name | The name of the internal statistical item. |
| value | The value of the internal statistical item. |
The following table describes the internal statistical items.
| Internal statistical item | Description |
|---|---|
| total_transaction_count | The total number of transactions. |
| total_user_transaction_count | The number of transactions executed in ODP. |
| total_query_count | The number of user requests executed. |
| total_client_request_reread_count | The number of user requests read by ODP. |
| total_server_response_reread_count | The number of times that ODP reads data from OBServer nodes. |
| client_request_total_size | The total size of data requested by the client. |
| client_response_total_size | The total size of data returned by the client. |
| server_request_total_size | The total size of the request data sent to OBServer nodes. |
| server_response_total_size | The total size of the response data returned by OBServer nodes. |
| total_transactions_time | The total amount of time consumed to execute transactions. |
| total_user_transactions_time | The total amount of time consumed to execute transactions. |
| total_client_request_read_time | The total amount of time consumed to read client requests. |
| total_client_response_write_time | The total amount of time consumed to return data to the client. |
| total_client_request_analyze_time | The total amount of time consumed to parse client packets. |
| total_client_transaction_idle_time | The total amount of idle time in executing transactions. |
| total_server_process_request_time | The total amount of time consumed by the database to process requests. |
| total_server_response_read_time | The total amount of time consumed to read data from OBServer nodes. |
| total_server_response_analyze_time | The total amount of time consumed by ODP to parse data returned from the server. |
| total_send_saved_login_time | The total amount of time consumed to send LOGIN packets to OBServer nodes. |
| total_send_all_session_vars_time | The total amount of time consumed to synchronize session variables to OBServer nodes. |
| total_send_use_database_time | The total amount of time consumed to send the use database command to OBServer nodes. |
| total_send_changed_session_vars_time | The total amount of time consumed to send session variable modifications to OBServer nodes. |
| total_send_last_insert_id_time | The total amount of time consumed to synchronize values of last_insert_id to OBServer nodes. |
| total_send_start_trans_time | The total amount of time consumed for sending the request that starts transactions to OBServer nodes. |
| total_pl_lookup_time | The total amount of routing time. |
| total_server_connect_time | The total amount of time consumed for creating connections between the ODP and OBServer nodes. |
| client_requests | The total number of requests. |
| client_large_requests | The number of large requests. |
| client_internal_requests | The number of internal requests. |
| local_session_state_requests | The number of internal requests of ODP. |
| client_missing_pk_requests | The number of requests that do not need to be routed but need to use the connection of the last request. |
| client_completed_requests | The number of completed requests. |
| client_connection_abort_count | The number of aborted connections. |
| client_select_requests | The total number of SELECT requests. |
| client_insert_requests | The total number of INSERT requests. |
| client_update_requests | The total number of UPDATE requests. |
| client_delete_requests | The total number of DELETE requests. |
| client_other_requests | The total number of other requests. |
| request_size_100_count | The number of requests within the size range of [0 byte,100 byte). |
| request_size_1K_count | The number of requests within the size range of [100 byte,1 KB). |
| request_size_3K_count | The number of requests within the size range of [1 KB,3 KB). |
| request_size_5K_count | The number of requests within the size range of [3 KB,5 KB). |
| request_size_10K_count | The number of requests within the size range of [5 KB,10 KB). |
| request_size_1M_count | The number of requests within the size range of [10 KB,1 MB). |
| request_size_inf_count | The number of requests within the size range of [1 MB,+∞). |
| response_size_100_count | The number of responses within the size range of [0 byte,100 byte) |
| response_size_1K_count | The number of responses within the size range of [100 byte,1 KB). |
| response_size_3K_count | The number of responses within the size range of [1 KB,3 KB). |
| response_size_5K_count | The number of responses within the size range of [3 KB,5 KB). |
| response_size_10K_count | The number of responses within the size range of [5 KB,10 KB). |
| response_size_1M_count | The number of responses within the size range of [10 KB,1 MB). |
| response_size_inf_count | The number of responses within the size range of [1 MB,+∞). |
| client_speed_bytes_per_sec_100 | The number of clients whose size of request data sent per second is within the range of [0 byte,100 byte). |
| client_speed_bytes_per_sec_1K | The number of clients whose size of request data sent per second is within the range of [100 byte,1 KB). |
| client_speed_bytes_per_sec_10K | The number of clients whose size of request data sent per second is within the range of [1 KB,10 KB). |
| client_speed_bytes_per_sec_100K | The number of clients whose size of request data sent per second is within the range of [10 KB,100 KB). |
| client_speed_bytes_per_sec_1M | The number of clients whose size of request data sent per second is within the range of [100 KB,1 MB). |
| client_speed_bytes_per_sec_10M | The number of clients whose size of request data sent per second is within the range of [1 MB,10 MB). |
| client_speed_bytes_per_sec_100M | The number of clients whose size of request data sent per second is within the range of [10 MB,+∞). |
| server_speed_bytes_per_sec_100 | The number of OBServer nodes whose size of response data sent per second is within the range of [0 byte,100 byte). |
| server_speed_bytes_per_sec_1K | The number of OBServer nodes whose size of response data sent per second is within the range of [100 byte,1 KB). |
| server_speed_bytes_per_sec_10K | The number of OBServer nodes whose size of response data sent per second is within the range of [1 KB,10 KB). |
| server_speed_bytes_per_sec_100K | The number of OBServer nodes whose size of response data sent per second is within the range of [10 KB,100 KB). |
| server_speed_bytes_per_sec_1M | The number of OBServer nodes whose size of response data sent per second is within the range of [100 KB,1 MB). |
| server_speed_bytes_per_sec_10M | The number of OBServer nodes whose size of response data sent per second is within the range of [1 MB,10 MB). |
| server_speed_bytes_per_sec_100M | The number of OBServer nodes whose size of response data sent per second is within the range of [10 MB,+∞). |
| server_connect_count | The total number of connections to OBServer nodes. |
| server_connect_retries | The total number of reconnections to OBServer nodes. |
| server_pl_lookup_count | The total number of times routing is performed. |
| server_pl_lookup_retries | The total number of routing retries. |
| broken_server_connections | The total number of disconnections from OBServer nodes. |
| server_requests | The total number of requests sent to OBServer nodes. |
| server_responses | The total number of responses received from OBServer nodes. |
| server_error_responses | The total number of ERROR responses received from OBServer nodes. |
| server_resultset_responses | The total number of resultset responses received from OBServer nodes. |
| server_ok_responses | The total number of OK responses received from OBServer nodes. |
| server_other_responses | The total number of other responses received from OBServer nodes. |
| send_saved_login_requests | The total number of LOGIN packets sent to OBServer nodes. |
| send_all_session_vars_requests | The total number of times that all session variables are sent to OBServer nodes. |
| send_use_database_requests | The total number of times that the use database command is sent to OBServer nodes. |
| send_changed_session_vars_requests | The total number of times that part of session variables are sent to OBServer nodes. |
| send_last_insert_id_requests | The total number of times that the values of last insert id are sent to OBServer nodes. |
| send_start_trans_requests | The total number of times that the request for starting transactions is sent to OBServer nodes. |
| vip_to_tenant_cache_hit | The number of hits in queries of VIP information in the public cloud. |
| vip_to_tenant_cache_miss | The number of cache misses for VIP information queries in the public cloud. |
Terminate a client session
You can use the KILL PROXYSESSION (cs_id | connection_id) statement to terminate a client session. The following sections describe how to terminate a client session through the client session ID or connection ID.
Note
If you perform a KILL operation on a session by specifying its cs_id or connection_id and the session is terminated, the operation is successful. When you use the SHOW PROXYSESSION statement, the client will reestablish a session, send the SQL statement to ODP for execution, and display the execution result.
Terminate a session by specifying the client session ID
Execute the
SHOW PROXYSESSIONstatement to query the ID of the client session (cs_id) to be terminated.obclient> show proxysession;The output is as follows, where the value in the second column (
Id) indicates the client session ID.+---------------------+--------+---------+--------+------+-----------------+------+-------------+-------------------+-------------------+------+------+-----------+ | proxy_sessid | Id | Cluster | Tenant | User | Host | db | trans_count | svr_session_count | state | tid | pid | using_ssl | +---------------------+--------+---------+--------+------+-----------------+------+-------------+-------------------+-------------------+------+------+-----------+ | 7230691418559283266 | 68 | ob1.cc | sys | root | 127.0.0.1:50260 | NULL | 0 | 1 | MCS_ACTIVE_READER | 8728 | 8728 | 0 | +---------------------+--------+---------+--------+------+-----------------+------+-------------+-------------------+-------------------+------+------+-----------+ 1 rows in setExecute the following statement to terminate the session:
obclient> KILL PROXYSESSION 68; ERROR 1317 (70100): Query execution was interruptedExecute the following statement to verify whether the session is terminated:
obclient> select 88;The output shows that the connection is lost.
ERROR 2013 (HY000): Lost connection to MySQL server during query
Terminate a session by specifying the connection ID
Execute the following statement to query the connection ID of the current session:
obclient> select CONNECTION_ID();The output is as follows:
+-----------------+ | CONNECTION_ID() | +-----------------+ | 3221766868 | +-----------------+ 1 row in setExecute the following statement to terminate the session:
obclient> KILL PROXYSESSION 3221766868; ERROR 1317 (70100): Query execution was interruptedExecute the following statement to verify whether the session is terminated:
obclient> select 88;The output shows that the connection is lost.
ERROR 2013 (HY000): Lost connection to MySQL server during query