本記事では、ODP上の指定されたClientセッションおよび指定されたClientセッション上のServerセッションをどのように終了するかについて説明します。
操作手順
sysテナントはKILL PROXYSESSIONステートメントを使用して、指定されたセッションを終了できます。
rootユーザーとしてODP経由でクラスタのsysテナントにログインします。接続例:
obclient -h10.xx.xx.xx -uroot@sys#obdemo -P2883 -p****** -c -A oceanbaseODP経由でデータベースに接続する方法の詳細な操作ガイドについては、OBClientを使用してOceanBaseテナントに接続する(MySQLモード)およびOBClientを使用してOceanBaseテナントに接続する(Oracleモード)を参照してください。
指定されたクライアントセッションを終了します。
指定されたクライアントセッションを終了する
KILL PROXYSESSION {cs_id | connection_id};パラメータの説明:
idはcs_idまたはconnection_idのいずれかであり、表示結果は同じです。cs_idはODP内部で各クライアントに割り当てられるid番号であり、connection_idはOceanBaseデータベース全体で各クライアントに割り当てられるid番号です。connection_idはSELECT CONNECTION_ID();ステートメントを使用して取得します。KILL connection_idと同じ機能を持ちます。KILLステートメントの詳細については、KILL(MySQLモード)またはKILL(Oracleモード)を参照してください。
例:
クライアントセッションを確認し、
cs_idまたはconnection_idを取得します。以下のステートメントを実行して
cs_idを取得します。SHOW PROXYSESSION;クエリ結果は次のとおりで、返される結果の
Idがcs_idです。+----------------------+-------+----------+----------+------+----------------------+------+-------------+-------------------+-------------------+-------+-------+-----------+ | proxy_sessid | Id | Cluster | Tenant | User | Host | db | trans_count | svr_session_count | state | tid | pid | using_ssl | +----------------------+-------+----------+----------+------+----------------------+------+-------------+-------------------+-------------------+-------+-------+-----------+ | 12402504630519660553 | 56932 | test420 | sys | root | 100.xx.xx.xx:63882 | NULL | 0 | 1 | MCS_ACTIVE_READER | 76286 | 76286 | 0 | +----------------------+-------+----------+----------+------+----------------------+------+-------------+-------------------+-------------------+-------+-------+-----------+ 1 row in setまたは、以下のステートメントを実行して
connection_idを取得します。SELECT CONNECTION_ID ();次のような結果が返されます。
+------------------+ | CONNECTION_ID () | +------------------+ | 3221562906 | +------------------+ 1 row in setcs_idが56392またはconnection_idが3221562906のクライアントセッションを終了します。KILL PROXYSESSION 56392;または
KILL PROXYSESSION 3221562906;実行が成功すると、次のようなエラーメッセージが表示されます。
ERROR 1317 (70100): Query execution was interruptedクエリが中断された後、クライアントセッションを確認すると、接続が切断されていることがわかります。
SHOW PROXYSESSION;次のメッセージが表示されます:
ERROR 2013 (HY000): Lost connection to MySQL server during queryクライアントセッションを再度確認します。
SHOW PROXYSESSION;次のメッセージが表示されます:
ERROR 2006 (HY000): OceanBase server has gone away No connection. Trying to reconnect... Connection id: 57195 Current database: *** NONE *** +----------------------+-------+----------+--------+------+----------------------+------+-------------+-------------------+-------------------+-------+-------+-----------+ | proxy_sessid | Id | Cluster | Tenant | User | Host | db | trans_count | svr_session_count | state | tid | pid | using_ssl | +----------------------+-------+----------+--------+------+----------------------+------+-------------+-------------------+-------------------+-------+-------+-----------+ | 12402504630519660555 | 57195 | test420 | sys | root | 100.xx.xx.xx:24996 | NULL | 0 | 1 | MCS_ACTIVE_READER | 76286 | 76286 | 0 | +----------------------+-------+----------+--------+------+----------------------+------+-------------+-------------------+-------------------+-------+-------+-----------+ 1 row in set
この例からわかるように、
cs_idまたはconnection_idを指定して現在のセッションをKILLした場合、コマンドの実行が成功すると、現在の接続が切断されます。SHOW PROXYSESSIONで確認すると、OBClientは再びセッション接続を確立し、SQLを実行して結果を表示します。指定されたクライアントセッション上のサーバーセッションを終了する
KILL PROXYSESSION {cs_id | connection_id} ss_idパラメータの説明:
idはcs_idまたはconnection_idのいずれかであり、表示結果は同じです。cs_idはODP内部で各クライアントに割り当てられるid番号であり、connection_idはOceanBaseデータベース全体で各クライアントに割り当てられるid番号です。connection_idはSELECT CONNECTION_ID();ステートメントを使用して取得します。ss_idはODP内部で各サーバー側セッション(Server Session)に割り当てられるid番号を表し、SHOW PROXYSESSION ATTRIBUTE idから取得できます。詳細な取得操作については、Sessionの詳細状態を表示するを参照してください。
例:
クライアントセッションを確認し、
cs_idを取得します。SHOW PROXYSESSION;クエリ結果は次のとおりで、返される結果の
Idがcs_idです。+----------------------+-------+----------+--------+------+----------------------+------+-------------+-------------------+-------------------+-------+-------+-----------+ | 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前のステップで得られた
cs_idに基づいてss_idを取得します。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クライアントセッション上のサーバーセッションを終了します。
KILL PROXYSESSION 64940 16;