查询oracle比较慢的session和sql
--查询最慢的sql
select * from (
select parsing_user_id,executions,sorts
command_type,disk_reads,sql_text from v$sqlarea order by disk_reads desc
)where rownum<10
--查询对应session
select SE.SID,SE.SERIAL#,PR.SPID,
SE.USERNAME,SE.STATUS,SE.TERMINAL,
SE.PROGRAM,SE.MODULE,
SE.SQL_ADDRESS,ST.EVENT,
ST.P1TEXT,SI.PHYSICAL_READS,SI.BLOCK_CHANGES from v$session se,v$session_wait st,
v$sess_io si,v$process pr
where st.SID=se.SID and st.SID=si.SID
AND SE.PADDR=PR.ADDR
AND SE.SID>6
AND ST.WAIT_TIME=0
AND ST.EVENT NOT LIKE '%SQL%'
ORDER BY PHYSICAL_READS DESC;
SELECT sql_address FROM V$SESSION SS,V$SQLTEXT TT
WHERE SS.SQL_HASH_VALUE=TT.HASH_VALUE AND SID=439;
v$sqltext:存储的是完整的SQL,SQL被分割
v$sqlarea:存储的SQL 和一些相关的信息,比如累计的执行次数,逻辑读,物理读等统计信息(统计)
v$sql:内存共享SQL区域中已经解析的SQL语句。(即时)
根据sid查找完整sql语句:
select sql_text from v$sqltext a where a.hash_value = (select sql_hash_value from v$session b where b.sid = '&sid' )
order by piece asc
select a.CPU_TIME,--CPU时间 百万分之一(微秒)
a.OPTIMIZER_MODE,--优化方式
a.EXECUTIONS,--执行次数
a.DISK_READS,--读盘次数
a.SHARABLE_MEM,--占用shared pool的内存多少
a.BUFFER_GETS,--读取缓冲区的次数
a.COMMAND_TYPE,--命令类型(3:select,2:insert;6:update;7delete;47:pl/sql程序单元)
a.SQL_TEXT,--Sql语句
a.SHARABLE_MEM,
a.PERSISTENT_MEM,
a.RUNTIME_MEM,
a.PARSE_CALLS,
a.DISK_READS,
a.DIRECT_WRITES,
a.CONCURRENCY_WAIT_TIME,
a.USER_IO_WAIT_TIME
from SYS.V_$SQLAREA a
WHERE PARSING_SCHEMA_NAME = 'CHEA_FILL'--表空间
order by a.CPU_TIME desc
引用:http://jenniferok.iteye.com/blog/700985
a.executions exec,a.disk_reads/decode(a.executions,0,1,a.executions) rds_exec_ratio,
a.sql_text Statement
from v$sqlarea a,dba_users b
where a.parsing_user_id=b.user_id
and a.disk_reads > 100000
order by a.disk_reads desc;
列出使用频率最高的5个查询:
from (select sql_text,executions,
rank() over
(order by executions desc) exec_rank
from v$sql)
where exec_rank <=5;
select disk_reads,sql_text
from (select sql_text,disk_reads,
dense_rank() over
(order by disk_reads desc) disk_reads_rank
from v$sql)
where disk_reads_rank <=5;
找出需要大量缓冲读取(逻辑读)操作的查询:
from (select sql_text,buffer_gets,
dense_rank() over
(order by buffer_gets desc) buffer_gets_rank
from v$sql)
where buffer_gets_rank<=5;
SQL_TEXT |
VARCHAR2(1000) |
First thousand characters of the SQL text for the current cursor |
SQL_ID |
VARCHAR2(13) |
SQL identifier of the parent cursor in the library cache |
SHARABLE_MEM |
NUMBER |
Amount of shared memory used by a cursor. If multiple child cursors exist, then the sum of all shared memory used by all child cursors. |
PERSISTENT_MEM |
NUMBER |
Fixed amount of memory used for the lifetime of an open cursor. If multiple child cursors exist, the fixed sum of memory used for the lifetime of all the child cursors. |
RUNTIME_MEM |
NUMBER |
Fixed amount of memory required during execution of a cursor. If multiple child cursors exist, the fixed sum of all memory required during execution of all the child cursors. |
SORTS |
NUMBER |
Sum of the number of sorts that were done for all the child cursors |
VERSION_COUNT |
NUMBER |
Number of child cursors that are present in the cache under this parent |
LOADED_VERSIONS |
NUMBER |
Number of child cursors that are present in the cache and have their context heap (KGL heap 6) loaded |
OPEN_VERSIONS |
NUMBER |
The number of child cursors that are currently open under this current parent |
USERS_OPENING |
NUMBER |
Number of users that have any of the child cursors open |
FETCHES |
NUMBER |
Number of fetches associated with the SQL statement |
EXECUTIONS |
NUMBER |
Total number of executions, totalled over all the child cursors |
END_OF_FETCH_COUNT |
NUMBER |
Number of times this cursor was fully executed since the cursor was brought into the library cache. The value of this statistic is not incremented when the cursor is partially executed, either because it failed during the execution or because only the first few rows produced by this cursor are fetched before the cursor is closed or re-executed. By definition, the value of the END_OF_FETCH_COUNT column should be less or equal to the value of the EXECUTIONS column. |
USERS_EXECUTING |
NUMBER |
Total number of users executing the statement over all child cursors |
LOADS |
NUMBER |
Number of times the object was loaded or reloaded |
FIRST_LOAD_TIME |
VARCHAR2(19) |
Timestamp of the parent creation time |
INVALIDATIONS |
NUMBER |
Total number of invalidations over all the child cursors |
PARSE_CALLS |
NUMBER |
Sum of all parse calls to all the child cursors under this parent |
DISK_READS |
NUMBER |
Sum of the number of disk reads over all child cursors |
DIRECT_WRITES |
NUMBER |
Sum of the number of direct writes over all child cursors |
BUFFER_GETS |
NUMBER |
Sum of buffer gets over all child cursors |
APPLICATION_WAIT_TIME |
NUMBER |
Application wait time |
CONCURRENCY_WAIT_TIME |
NUMBER |
Concurrency wait time |
CLUSTER_WAIT_TIME |
NUMBER |
Cluster wait time |
USER_IO_WAIT_TIME |
NUMBER |
User I/O Wait Time |
PLSQL_EXEC_TIME |
NUMBER |
PL/SQL execution time |
JAVA_EXEC_TIME |
NUMBER |
Java execution time |
ROWS_PROCESSED |
NUMBER |
Total number of rows processed on behalf of this SQL statement |
COMMAND_TYPE |
NUMBER |
Oracle command type definition |
OPTIMIZER_MODE |
VARCHAR2(25) |
Mode under which the SQL statement was executed |
PARSING_USER_ID |
NUMBER |
User ID of the user that has parsed the very first cursor under this parent |
PARSING_SCHEMA_ID |
NUMBER |
Schema ID that was used to parse this child cursor |
KEPT_VERSIONS |
NUMBER |
Number of child cursors that have been marked to be kept using the DBMS_SHARED_POOL package |
ADDRESS |
RAW( |
相关推荐
这里使用了`sql_hash_value`字段来关联`v$session`和`v$sqltext`两个视图,其中`&sid`是一个输入参数,代表了要查询的会话的SID。`order by piece asc`是为了按照SQL语句的片段顺序排列。 #### 3. 监控当前会话的...
实用Toad抓Oracle中较慢的SQL 在企业级数据库管理中,SQL性能优化是一个至关重要的方面。尤其是在Oracle数据库中,慢SQL的存在可能会导致系统性能下降、响应时间延长甚至引发系统崩溃。因此,抓取运行较慢的SQL语句...
在Oracle数据库管理中,监控和优化SQL查询是确保系统性能稳定的关键环节之一。对于那些消耗大量资源的SQL语句进行记录和分析可以帮助DBA快速定位问题并采取相应的优化措施。本文将详细介绍如何通过特定的SQL查询来找...
这个脚本利用了Oracle的动态性能视图`V$SESSION`和`V$SQLAREA`,这些视图提供了关于当前会话和已编译SQL语句的信息。具体来说,我们关注以下几个方面: 1. `last_active_time`: 查询最后活跃的时间,以确定查询的...
1、目的:在实际工作中,有时需将某个程序执行的所有SQL查出来,而程序在Oracle中与会话均可对应,故可通过本文脚本对会话的所有SQL进行跟踪,转换后即可还原程序对Oracle的操作。 2、适用场景:在源码无法拿到,但...
根据提供的信息,我们可以总结出以下Oracle数据库中常用的SQL查询语句及它们的功能: ### 1. 查询表空间及其总大小 ...以上查询涵盖了Oracle数据库管理中常用的一些SQL语句,对于日常维护和性能调优非常有帮助。
通过这些SQL语句,我们可以获取Oracle数据库的实时和历史性能数据,从而对系统进行深入分析,找出性能瓶颈,进行优化。在实际应用中,还可以结合AWR(Automatic Workload Repository)和ASH(Active Session History...
该方法可以通过 V$SESSION 视图来实现,根据 TABLESPACE 和 BLOCKS 字段来排序,找出排序多的 SQL。 ### 方法七:通过当前等待事件 可以通过当前等待事件来找到 TOP_SQL。该方法可以通过 V$SESSION_WAIT 视图来...
这个查询可以通过`v$session`和`v$sqltext`视图的组合来获取SQL语句的片段信息。通常情况下,SQL语句会被分割成多个片段,该查询可以帮助我们查看这些片段的详细内容。注释中的`machine`过滤器可以根据实际需求进行...
根据给定的文件信息,以下是对“oracle常用经典SQL查询方案”的详细解析,涉及的知识点主要包括Oracle数据库中的数据字典视图、空间管理、对象管理、版本查询、数据库模式、性能监控等方面。 ### 1. 查询表空间大小...
可以使用以下SQL语句来查询刚执行过的SQL和IO信息: ```sql select a.sql_text, a.sql_fulltext, a.cpu_time, b.sid, b.serial#, b.username, b.machine, b.terminal, b.program, c.block_gets, ...
最后,教程可能包含一些高级主题,如性能优化、SQL动态性能视图(如V$SESSION和V$SQL)的使用,以及如何使用EXPLAIN PLAN分析查询执行计划。你还将学习如何使用Oracle的内置分析函数(如RANK(), DENSE_RANK(), ROW_...
简单描述Oracle v$sqlarea, v$sql, v$sqltext视图说明
本文将深入探讨如何通过SQL查询语句在Linux和Windows环境下获取Oracle跟踪文件,以及相关的知识点。 首先,`gettrace.sql`、`gettrace2.sql`和`gettraceforwindow.sql`这三份文件可能包含了不同的SQL脚本来查询跟踪...
总的来说,Oracle SQL自动调优是一个综合性的过程,涉及多种工具和技术,目的是最小化查询响应时间,最大化数据库吞吐量。通过熟练掌握这些调优方法,数据库管理员能够有效地解决性能问题,提升系统的整体性能。
Oracle 19C SQL调优是数据库管理员(DBA)日常工作中不可或缺的一部分,它涉及到优化SQL查询性能,提高数据库系统的整体效率。本指南针对Oracle 19C版本,提供了丰富的调优策略和技术,旨在帮助DBA们更好地管理和维护...
- **性能调优**:当数据库响应变慢时,查询`v$session_wait`可以帮助快速定位造成延迟的等待事件,并通过进一步分析`v$session`中的会话信息来确定受影响的会话,从而采取相应措施优化性能。 - **资源管理**:通过...
oracle的连接数查看和连接用户的查看.sql Sun30新建oracle用户.sql user_job.sql xaview.sql 修改分区索引.SQL 修改数据库核心字符集.txt 僵死进程查询.sql 创建ORACLE表空间.sql 回滚段等待.SQL 在数据库中建JOB....
### 查询Oracle正在运行的SQL和锁定的表 在Oracle数据库管理与维护中,了解当前正在运行的SQL语句以及被锁定的对象对于性能调优、问题排查等至关重要。本文将详细介绍如何通过Oracle内置视图来查询正在运行的SQL...