Oracle-数据库性能变慢问题分析
-- 查询最消耗资源的SQL
SELECT * FROM (
SELECT
sql_id,
executions,
parse_calls,
disk_reads,
buffer_gets,
elapsed_time,
cpu_time,
user_io_wait_time
FROM
v$sqlarea
ORDER BY
buffer_gets DESC
FETCH FIRST 10 ROWS ONLY
)
WHERE ROWNUM <= 10;
-- 查询最近运行时间最长的SQL
SELECT * FROM (
SELECT
sql_id,
executions,
parse_calls,
disk_reads,
buffer_gets,
elapsed_time,
cpu_time,
user_io_wait_time
FROM
v$sqlarea
ORDER BY
elapsed_time DESC
FETCH FIRST 10 ROWS ONLY
)
WHERE ROWNUM <= 10;
-- 查询最近使用CPU时间最长的SQL
SELECT * FROM (
SELECT
sql_id,
executions,
parse_calls,
disk_reads,
buffer_gets,
elapsed_time,
cpu_time,
user_io_wait_time
FROM
v$sqlarea
ORDER BY
cpu_time DESC
FETCH FIRST 10 ROWS ONLY
)
WHERE ROWNUM <= 10;
-- 查询最近等待IO的SQL
SELECT * FROM (
SELECT
sql_id,
executions,
parse_calls,
disk_reads,
buffer_gets,
elapsed_time,
cpu_time,
user_io_wait_time
FROM
v$sqlarea
ORDER BY
user_io_wait_time DESC
FETCH FIRST 10 ROWS ONLY
)
WHERE ROWNUM <= 10;
这段代码提供了四个查询示例,分别用于查找最消耗资源的SQL、最耗时的SQL、最消耗CPU的SQL和最需要等待IO的SQL。这些查询可以帮助数据库管理员和开发人员识别和优化数据库性能问题。
评论已关闭