OBServer 的慢查询阈值默认为 100 ms,表示超过 100 ms 的慢查询才会记录在 OBServer 上。而 OBProxy 也有其慢查询的阈值,通过设置 OBProxy 的慢查询阈值,可以捕获到通过该 OBProxy 连接的相关慢查询。
OBProxy 慢查询相关参数
OBProxy 有慢查询日志打印功能,通过 OBProxy 的以下配置项来控制打印到日志中的 SQL 或事务的处理时间阈值:
slow_transaction_time_threshold:指慢查询或事务的整个生命周期的时间阈值,超过了该时间,就会打印相关日志。query_digest_time_threshold:指 OBProxy 得到 SQL 直到返回给客户端之前的这段时间的阈值,超过了该时间,也会打印相关日志。slow_query_time_threshold:OBProxy 上慢查询的阈值,默认是 500 ms,超过 500 ms 的 SQL 会打印相关的日志。该参数应当与 OBServer 的配置项trace_log_slow_query_watermark设置为相同的值。有关trace_log_slow_query_watermark的详细信息,请参见 《OceanBase 数据库 参考指南》的 配置项 章节。
有关以上配置的详细信息,请参见《OceanBase 数据库 管理员指南》中的 OBProxy 管理 章节。
修改 OBProxy 慢查询配置项
通过 OBProxy 登录 OceanBase 数据库的 sys 租户。
查看 OBProxy 当前配置。
obclient> SHOW proxyconfig LIKE 'slow_transaction_time_threshold'; obclient> SHOW proxyconfig LIKE 'slow_query_time_threshold'; obclient> SHOW proxyconfig LIKE 'query_digest_time_threshold';根据实际需求修改 OBProxy 配置项。
obclient> ALTER proxyconfig SET slow_transaction_time_threshold='100ms'; obclient> ALTER proxyconfig SET query_digest_time_threshold='5ms';说明
一般情况下,只需要修改配置项
slow_transaction_time_threshold。配置项slow_proxy_process_time_threshold使用默认值 2ms,slow_query_time_threshold使用默认值 500ms 适用于绝大多数场景。其中,大于
slow_proxy_process_time_threshold的请求或错误响应请求会打印到obproxy_digest.log日志中。2020-03-18 21:26:54.871053,postmen,,,,postmen40:postmen_new0497_3279:postmen_r497,OB_MYSQL,,postmen_push_msg_4977,COM_QUERY,SELECT,success,,SELECT id%2C gmt_create%2C gmt_modified%2C msg_id%2C principal_id%2C app_name%2C target_utdid%2C biz_id%2C host%2C status%2C expire_time%2C msg_data FROM postmen_push_msg_4977 WHERE principal_id = 'W/jEKoLOxnwDABWmhzjgmK1V' AND app_name = 'KOUBEI' AND expire_time > 1584538014858 AND status = 1,11765us,52us,0us,11632us,Y0-7F16DD5BEBC0,,大于
query_digest_time_threshold的请求,会打印到obproxy_slow.log日志中。2020-03-16 21:31:32.125967,postmen,,,,postmen20:postmen_new0200_3279:postmen_r200,OB_MYSQL,,,COM_LOGIN,,success,,,507680us,507049us,0us,515us,Y0-7F16DD5743A0,, 2020-03-16 21:31:49.561865,postmen,,,,postmen50:postmen_new0580_3279:postmen_r580,OB_MYSQL,,,COM_LOGIN,,success,,,1258599us,1249321us,0us,9130us,Y0-7F16DB9752C0,,