SQL_Audit
获取 elapsed_time 排序最近 M 分钟内的 top N 的 SQL
root@sys
登陆查询,
获取 elapsed_time 排序最近M分钟内的topN的sql
SELECT
/*+READ_CONSISTENCY(WEAK), QUERY_TIMEOUT(100000000)*/
tenant_id,
tenant_name,
user_name,
db_name,
svr_ip,
plan_id,
plan_type,
affected_rows,
return_rows,
elapsed_time,
execute_time,
sql_id,
usec_to_time(request_time),
substr(
replace(query_sql, '\n', ' '),
1,
100
)
FROM
gv$ob_sql_audit
WHERE
1 = 1
AND request_time > (time_to_usec(now()) - 10 * 60 * 1000000)
AND is_inner_sql = 0
-- AND tenant_id = 1001
ORDER BY
elapsed_time DESC
LIMIT
10;
按 qps 排序获取业务租户最近 M 分钟执行次数最多的 top N的 SQL
root@sys
登陆查询,
SELECT
/*+READ_CONSISTENCY(WEAK), QUERY_TIMEOUT(100000000)*/
tenant_id,
sql_id,
COUNT(1) / 60 qps,
AVG(elapsed_time),
AVG(execute_time),
AVG(queue_time),
AVG(return_rows),
AVG(affected_rows),
substr(
replace(query_sql, '\n', ' '),
1,
100
) query_sql,
ret_code
FROM
gv$ob_sql_audit
WHERE
1 = 1
AND request_time > (time_to_usec(now()) - 10 * 60 * 1000000)
AND is_inner_sql = 0
AND tenant_id > 1000
GROUP BY
tenant_id,
sql_id,
query_sql,
ret_code
ORDER BY
qps DESC
LIMIT
10;