设为首页 收藏本站
查看: 849|回复: 0

[经验分享] 研究v$sqlarea,v$sql,v$sqltext

[复制链接]

尚未签到

发表于 2018-10-16 10:23:25 | 显示全部楼层 |阅读模式
以下内容转自http://lzfhope.blog.163.com/blog/static/63639922008101955913105

  通过看这个表的结构,可以了解共享池中,SQL是如何运行的,这样可以了解不少关键的信息.
  可以了解SQL全文,执行使用的内存,消耗的CPU,被装载的次数等等比较有意义的信息。
  通过这个视图,可以了解最近被执行最多次数的SQL语句,被最多用户执行的SQL语句.当然共享池要足够大,设计的语句也应该尽量考虑到共享(例如一个很简单的就是多考虑变量绑定),研究这个对于了解性能还是有一定作用的。
SQL_TEXT VARCHAR2(1000)

  SQL前一千个字符 内容.
  SQL_FULLTEXT CLOB
  SQL全文
  SQL_ID     VARCHAR2(13)

  SQL>  SHARABLE_MEM    NUMBER
  使用了多少共享内存(包含子游标所使用的)
  PERSISTENT_MEM    NUMBER
  打开的游标其生命周期所消耗的固定内存(包含子有效的固定内存)
  RUNTIME_MEM     NUMBER
  游标运行时候所需要的内容(包含子游标的)
  SORTS     NUMBER
  所有的排序测试(包含子游标的)
  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
  共有多少用户打开它(包含子游标)
  FETCHES NUMBER    Number
  Numberof fetches associated with the SQL statement
  EXECUTIONS    NUMBER
  总共执行次数(包含子游标)
  PX_SERVERS_EXECUTIONS     NUMBER
  Total number of executions performed by Parallel eXecution Servers. The
  value is 0 when the statement has never been executed in parallel.
  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
  共多少个用户执行(..)  (..)表示包含子游标,下同.
  LOADS    NUMBER
  对象被装载或者重载的次数
  FIRST_LOAD_TIME    VARCHAR2(19)
  第一次装载的时间.
  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 (in microseconds)
  CONCURRENCY_WAIT_TIME    NUMBER
  Concurrency wait time (in microseconds)
  CLUSTER_WAIT_TIME
  NUMBER    Cluster wait time (in microseconds)
  USER_IO_WAIT_TIME
  NUMBER    User I/O Wait Time (in microseconds)
  PLSQL_EXEC_TIME
  NUMBER    PL/SQL execution time (in microseconds)
  JAVA_EXEC_TIME     NUMBER
  Java execution time (in microseconds)
  ROWS_PROCESSED     NUMBER
  处理了多少条记录
  COMMAND_TYPE    NUMBER
  Oracle command type definition
  OPTIMIZER_MODE VARCHAR2(10)
  Mode under which the SQL statement was executed
  OPTIMIZER_COST     NUMBER
  Cost of this query given by the optimizer
  OPTIMIZER_ENV     RAW(703)
  Optimizer environment
  OPTIMIZER_ENV_HASH_VALUE    NUMBER
  Hash value for the optimizer environmen
  PARSING_USER_ID NUMBER

  User>  PARSING_SCHEMA_ID    NUMBER

  Schema>  PARSING_SCHEMA_NAME    VARCHAR2(30)
  Schema name 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(4 | 8)
  Address of the handle to the parent for this cursor
  HASH_VALUE    NUMBER
  Hash value of the parent statement in the library cache
  OLD_HASH_VALUE    NUMBER
  Old SQL hash value
  PLAN_HASH_VALUE    NUMBER

  Numerical representation of the SQL plan for this cursor. Comparing one PLAN_HASH_VALUE to another easily>  MODULE    VARCHAR2(64)
  Contains the name of the module that was executing at the time that the SQL statement was first parsed as set by calling DBMS_APPLICATION_INFO.SET_MODULE
  MODULE_HASH    NUMBER
  Hash value of the module that is named in the MODULE column
  ACTION    VARCHAR2(64)
  Contains the name of the action that was executing at the time that the
  SQL statement was first parsed as set by calling
  DBMS_APPLICATION_INFO.SET_ACTION
  ACTION_HASH    NUMBER
  Hash value of the action that is named in the ACTION column
  SERIALIZABLE_ABORTS    NUMBER
  Number of times the transaction fails to serialize, producing ORA-08177 errors, totalled over all the child cursors
  OUTLINE_CATEGORY    VARCHAR2(64)
  If an outline was applied during construction of the cursor, then this column displays the category of that outline. Otherwise the column is left
  blank.
  
  CPU_TIME    NUMBER
  分析,执行和提取所消耗的时间(单位为微秒)
  CPU time (in microseconds) used by this cursor for parsing, executing, and fetching
  ELAPSED_TIME    NUMBER
  客观上分析,执行和提取所消耗的时间(单位为微秒)
  这个时间通常比CPU_TIME长,因为可能还包含其它时间
  OUTLINE_SID    VARCHAR2(40)

  Outline session>  LAST_ACTIVE_CHILD_ADDRESS    RAW(4)
  Address (identifier) of the child cursor that was the last to be active in the group (that is, the child cursor on behalf of which statistics in V$SQL were updated)
  REMOTE    VARCHAR2(1)
  Indicates whether the cursor is remote mapped (Y) or not (N)
  OBJECT_STATUS    VARCHAR2(19)
  Status of the cursor:
  ■ VALID - Valid, authorized without errors
  ■ VALID_AUTH_ERROR - Valid, authorized with authorization errors
  ■ VALID_COMPILE_ERROR - Valid, authorized with compilation errors
  ■ VALID_UNAUTH - Valid, unauthorized
  ■ INVALID_UNAUTH - Invalid, unauthorized
  ■ INVALID - Invalid, unauthorized but keep the timestamp
  LITERAL_HASH_VALUE    NUMBER
  Hash value of the literals which are replaced with system-generated bind variables and are to be matched, when CURSOR_SHARING is used. This is not the hash value for the SQL statement. If CURSOR_SHARING is no used, then the value is 0.
  LAST_LOAD_TIME    DATE
  执行计划最后被此装载的时间.
  Time at which the query plan (heap 6) was loaded into the library cache
  IS_OBSOLETE     VARCHAR2(1)
  Indicates whether the cursor has become obsolete (Y) or not (N) happen if the number of child cursors is too large.
  CHILD_LATCH    NUMBER
  Child latch number that is protecting the cursor
  SQL_PROFILE    VARCHAR2(64)
  SQL profile
  PROGRAM_ID    NUMBER

  Program>  PROGRAM_LINE#    NUMBER
  Program line number
  EXACT_MATCHING_SIGNATURE    NUMBER
  The signature used when the CURSOR_SHARING parameter is set to EXACT
  FORCE_MATCHING_SIGNATURE    NUMBER
  The signature used when the CURSOR_SHARING parameter is set to FORCE
  LAST_ACTIVE_TIME    DATE
  最后换一次查询计划被激活的时间.
  Time at which the query plan was last active
  BIND_DATA    RAW(2000)
  Bind data
  其中PROGRAM_ID,PROGRAM_LINE#可以用于定位是那个程序(通常指过程,函数或者是其它包裹等),可以用于跟踪。
  SELECT T.USER_NAME ,e.SQL_FULLTEXT,E.PROGRAM_ID,E.PROGRAM_LINE#,X.OBJECT_NAME
  FROM V$OPEN_CURSOR T, V$SESSION D, v$sqlarea e
  JOIN  ALL_OBJECTS  X ON X.OBJECT_ID=E.PROGRAM_ID
  WHERE T.SID = D.SID
  and t.SQL_ID = e.SQL_ID
  AND T.USER_NAME IN ('DM', 'WH', 'IPD', 'MK')
关于共同点:

  1)都存储了sql内容
  2) 记录的都是位于内存中的sql内容
  3) 因为是内存,所以都不保留历史记录
不同点:

  1)存储的为止不都是相同。其中v$sql和v$sqlarea存储的sql都是位于shared sql area中的sql,而v$sqltext是位于sga中的sql。但文档没有明确说明这里的sga是否还包含了psa(私有sql区域--共享服务器模式下)。
  2)存储sql的方式也不同,v$sql和v$sqlarea都是用一行来存储sql全文,而v$sqltext用一行存储sql的一行。
  3)v$sql不存储包含group by 的sql语句。通常这个视图,在每个查询执行完成后更新,但对于执行很久的sql,它是每5秒更新一次,这点对于查看sql执行状态是有意义的。
  4)存储的明细不同--这是最基本的。
  后顺便提一下,v$sqltext_with_newline和v$sqltext是一样,不同的是前者并把换行符和tab替换为空格 ,这样更容易阅读。V$SQLSTATS和V$SQL,v$sqlarea一样都有提供CPU的统计数据.
有关内存结构请参见 http://lzfhope.blog.163.com/blog/static/6363992200863012124663/



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-622229-1-1.html 上篇帖子: SQL语句杂记(二) 下篇帖子: MS SQL SERVER批量恢复BAK文件
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表