tidb
tidb copied to clipboard
how to catch the long-running sql statements in TiDB?
Please answer these questions before submitting your issue. Thanks!
- What did you do?
I ran a sql
select sleep(12);, it finished in 12 sec, I've set long_query_time setting to 1 sec, so it's a long-running sql, but the localhost-slow.log file doesn't seem exist. Can you shed some light?
I deployed TiDB by Ansible Deployment(root deployment).
[root@TiDB_PD ~]# cat /usr/local/mysql/data/localhost-slow.log
cat: /usr/local/mysql/data/localhost-slow.log: No such file or directory
MySQL [(none)]> select sleep(12);
+-----------+
| sleep(12) |
+-----------+
| 0 |
+-----------+
1 row in set (12.00 sec)
some settings:
MySQL [(none)]> show variables like 'long_query_time';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| long_query_time | 1 |
+-----------------+-------+
MySQL [(none)]> show variables like '%slow%';
+---------------------------+------------------------------------------+
| Variable_name | Value |
+---------------------------+------------------------------------------+
| log_slow_slave_statements | OFF |
| slow_query_log | ON |
| log_slow_admin_statements | OFF |
| slow_query_log_file | /usr/local/mysql/data/localhost-slow.log |
| slow_launch_time | 2 |
+---------------------------+------------------------------------------+
there's only few items in "show global status;", Slow_queries is not supported.
MySQL [(none)]> show global status like '%slow%';
Empty set (0.01 sec)
MySQL [(none)]> show global status;
+--------------------+--------------------------------------+
| Variable_name | Value |
+--------------------+--------------------------------------+
| server_id | c81fad0e-2ea5-4c23-816a-1f85f7d02f92 |
| ddl_schema_version | 226 |
+--------------------+--------------------------------------+
2 rows in set (0.01 sec)
MySQL:
mysql> show global status like '%slow%';
+---------------------+-------+
| Variable_name | Value |
+---------------------+-------+
| Slow_launch_threads | 0 |
| Slow_queries | 1 |
+---------------------+-------+
2 rows in set (0.01 sec)
mysql> quit
Bye
[root@mysqlprimary ~]# vi /usr/local/mysql/data/mysqlprimary-slow.log
/usr/local/mysql/bin/mysqld, Version: 5.7.16-log (MySQL Community Server (GPL)). started with:
Tcp port: 3306 Unix socket: /tmp/mysql.sock
Time Id Command Argument
# Time: 2017-08-22T15:09:45.462763Z
# User@Host: root[root] @ localhost [] Id: 9
# Query_time: 10.000751 Lock_time: 0.000000 Rows_sent: 1 Rows_examined: 0
use gin;
SET timestamp=1503414585;
SELECT SLEEP(10);
- What version of TiDB are you using (
tidb-server -V)? Git Commit Hash: 365e4ab491b683a69c2004f30b1ae4f86256e2ad Git Commit Branch: master UTC Build Time: 2017-08-16 01:24:27
@tshqin Please use grep TIME_QUERY tidb.log to get the slow queries.
We are developing a tool to collect and show slow log.
cat /home/tidb/deploy/log/tidb.log |grep TIME_QUERY got it, thx!