当前位置:网站首页>SQL to check the disk usage of the database / table, kill the process and terminate the connection in tidb

SQL to check the disk usage of the database / table, kill the process and terminate the connection in tidb

2022-06-21 08:24:00 Mr. Chang Ming

1、 view the database / Table disk usage

--  Check the memory usage of the entire library :
select concat(truncate(sum(data_length)/1024/1024,2),'MB') as data_size,
          concat(truncate(sum(index_length)/1024/1024,2),'MB') as index_size
  from information_schema.tables
where TABLE_SCHEMA = 'tablename';
--  The memory occupation of the query table :
select concat(truncate(sum(data_length)/1024/1024,2),'MB') as data_size,
          concat(truncate(sum(index_length)/1024/1024,2),'MB') as index_size
  from information_schema.tables
where TABLE_NAME = 'tablesname';
  • TABLE_SCHEMA: The name of the schema to which the table belongs .
    TABLE_NAME: The name of the table .
    DATA_LENGTH: Data length .DATA_LENGTH= TABLE_ROWS * The sum of the storage lengths of the columns in a tuple . Not thinking about TiKV Copy of .
    INDEX_LENGTH: Index length .INDEX_LENGTH= TABLE_ROWS * The sum of the length of the columns in the index tuple . Not thinking about TiKV Copy of .

Reference resources tidb

2、KILL TIDB Statement is used to terminate TiDB Connection in .

SHOW PROCESSLIST;
+------+------+-----------+------+---------+------+-------+------------------+
| Id   | User | Host      | db   | Command | Time | State | Info             |
+------+------+-----------+------+---------+------+-------+------------------+
|    1 | root | 127.0.0.1 | test | Query   |    0 | 2     | SHOW PROCESSLIST |
|    2 | root | 127.0.0.1 |      | Sleep   |    4 | 2     |                  |
+------+------+-----------+------+---------+------+-------+------------------+
2 rows in set (0.00 sec)
KILL TIDB 2;

according to the design ,KILL TIDB Statement default and MySQL Are not compatible . The load balancer is usually followed by multiple TiDB The server , This default incompatibility helps prevent errors in TiDB Terminate connection on server .

mysql Usage method :

KILL [CONNECTION | QUERY] thread_id

Reference resources tidb Official website

原网站

版权声明
本文为[Mr. Chang Ming]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/172/202206210821267545.html