0

我收集了来自 RDS 的慢查询日志,并将它们放在一个文件中。尝试按照此处的说明pt-query-digest运行它,但它将整个文件作为单个查询读取。

命令:

pt-query-digest --group-by fingerprint --order-by Query_time:sum collider-slow-query.log > slow-query-analyze.txt

输出,表明它只分析了一个查询:

# Overall: 1 total, 1 unique, 0 QPS, 0x concurrency ______________________

这只是一个简短的片段,其中包含正在分析的文件中的 2 个查询,以演示有许多查询:

2019-05-03T20:44:21.828Z # Time: 2019-05-03T20:44:21.828954Z
# User@Host: username[username] @  [ipaddress]  Id:    19
# Query_time: 17.443164  Lock_time: 0.000145 Rows_sent: 5  Rows_examined: 121380
SET timestamp=1556916261;
SELECT   wp_posts.ID FROM wp_posts  LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1  AND wp_posts.ID NOT IN (752921) AND ( 
  wp_term_relationships.term_taxonomy_id IN (40)
) AND wp_posts.post_type = 'post' AND ((wp_posts.post_status = 'publish')) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 5;
2019-05-03T20:44:53.597Z # Time: 2019-05-03T20:44:53.597137Z
# User@Host: username[username] @  [ipaddress]  Id:    77
# Query_time: 35.757909  Lock_time: 0.000054 Rows_sent: 2  Rows_examined: 199008
SET timestamp=1556916293;
SELECT post_id, meta_value FROM wp_postmeta
                WHERE meta_key = '_wp_attached_file'
                AND meta_value IN ( 'family-guy-vestigial-peter-slice.jpg','2015/08/bobs-burgers-image.jpg','2015/08/bobs-burgers-image.jpg' );

为什么它不读取所有查询?我的连接有问题吗?

4

1 回答 1

0

我也有同样的问题。事实证明,SQL 中存储了一些额外的时间戳(通过这个变量:https ://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_log_timestamps )。

这使得 pt-query-digest 看不到单个查询。它应该很容易通过关闭时间戳变量或删除时间戳来修复:

2019-10-28T11:17:18.412 # Time: 2019-10-28T11:17:18.412214
# User@Host: foo[foo] @  [192.168.8.175]  Id: 467836
# Query_time: 5.839596  Lock_time: 0.000029 Rows_sent: 1  Rows_examined: 0
use foo;
SET timestamp=1572261432;
SELECT COUNT(*) AS `count` FROM `foo`.`invoices` AS `Invoice`   WHERE 1 = 1;

通过删除第一个时间戳(2019-10-28T11:17:18.412部分),它再次工作。

于 2019-10-29T13:03:06.920 回答