oracle实用sql(5)--session相关信息


点击(此处)折叠或打开

  1. --Sessions
  2. SELECT round(bitand(s.ownerid, 65535)) parent_session_sid, round(bitand(s.ownerid,16711680)/65536) parent_session_instid, rawtohex(SADDR) as saddr,s.SID, s.SERIAL#, s.AUDSID, rawtohex(PADDR) as paddr,s.USER#, s.USERNAME, s.COMMAND, s.OWNERID, s.TADDR, s.LOCKWAIT, s.STATUS, s.SERVER, s.SCHEMA#, s.SCHEMANAME, s.OSUSER, s.PROCESS, s.MACHINE, s.PORT, s.TERMINAL, UPPER(s.PROGRAM) PROGRAM, s.TYPE, s.SQL_ADDRESS, s.SQL_HASH_VALUE, s.SQL_ID, s.SQL_CHILD_NUMBER, s.SQL_EXEC_START, s.SQL_EXEC_ID, s.PREV_SQL_ADDR, s.PREV_HASH_VALUE, s.PREV_SQL_ID, s.PREV_CHILD_NUMBER, s.PREV_EXEC_START, s.PREV_EXEC_ID, s.PLSQL_ENTRY_OBJECT_ID, s.PLSQL_ENTRY_SUBPROGRAM_ID, s.PLSQL_OBJECT_ID, s.PLSQL_SUBPROGRAM_ID, s.MODULE, s.MODULE_HASH, s.ACTION, s.ACTION_HASH, s.CLIENT_INFO, s.FIXED_TABLE_SEQUENCE, s.ROW_WAIT_OBJ#, s.ROW_WAIT_FILE#, s.ROW_WAIT_BLOCK#, s.ROW_WAIT_ROW#, s.TOP_LEVEL_CALL#, s.LOGON_TIME, s.LAST_CALL_ET, s.PDML_ENABLED, s.FAILOVER_TYPE, s.FAILOVER_METHOD, s.FAILED_OVER, s.RESOURCE_CONSUMER_GROUP, s.PDML_STATUS, s.PDDL_STATUS, s.PQ_STATUS, s.CURRENT_QUEUE_DURATION, s.CLIENT_IDENTIFIER, s.BLOCKING_SESSION_STATUS, s.BLOCKING_INSTANCE, s.BLOCKING_SESSION, s.FINAL_BLOCKING_SESSION_STATUS, s.FINAL_BLOCKING_INSTANCE, s.FINAL_BLOCKING_SESSION, s.SEQ#, s.EVENT#, s.EVENT, s.P1TEXT, s.P1, s.P1RAW, s.P2TEXT, s.P2, s.P2RAW, s.P3TEXT, s.P3, s.P3RAW, s.WAIT_CLASS_ID, s.WAIT_CLASS#, s.WAIT_CLASS, s.WAIT_TIME, s.SECONDS_IN_WAIT, s.STATE, s.WAIT_TIME_MICRO, s.TIME_REMAINING_MICRO, s.TIME_SINCE_LAST_WAIT_MICRO, s.SERVICE_NAME, s.SQL_TRACE, s.SQL_TRACE_WAITS, s.SQL_TRACE_BINDS, s.SQL_TRACE_PLAN_STATS, s.SESSION_EDITION_ID, s.CREATOR_ADDR, s.CREATOR_SERIAL#, s.ECID
  3. FROM V$SESSION S
  4.  WHERE ( (s.USERNAME is not null) and (NVL(s.osuser,'x') <> 'SYSTEM') and (s.type <> 'BACKGROUND') )
  5. order by "PROGRAM", OWNERID;
  6. --从上面前台sessions中找到某个session id,替换下面所有SID的值,然后执行下方所有语句,了解session对应的相关信息
  7. --Session
  8. SELECT rawtohex(s.SADDR) as saddr, s.AUDSID, s.Client_Info, s.Command, s.Last_Call_ET, s.LockWait, s.Logon_Time, s.Machine, s.Module,
  9. s.OSUser, rawtohex(s.PADDR) as paddr, s.Process, s.Program, s.SchemaName, s.Serial#, s.Server, s.SID, s.Status, s.Terminal, s.Type,
  10. s.Action, s.UserName, s.Failover_Method, s.Failed_Over, s.Failover_Type, s.PDML_Enabled, s.PDDL_Status, s.PDML_Status, s.PQ_Status,
  11. s.Resource_Consumer_Group, s.Client_Identifier, s.SQL_Child_Number, s.SQL_ID, s.Service_Name, s.State, s.Event, s.Seconds_In_Wait,
  12. s.Wait_Time, s.Wait_Class_ID, s.Wait_Class#, s.Wait_Class, s.P1Text, s.P1, s.P2Text, s.P2, s.P3Text, s.P3, s.SQL_Trace,
  13. sci.Authentication_type, sci.Client_Charset, sci.Client_Version
  14. FROM V$SESSION S,
  15.       (SELECT DISTINCT SID, SERIAL#, AUTHENTICATION_TYPE, CLIENT_CHARSET, CLIENT_VERSION FROM V$SESSION_CONNECT_INFO where SID = 32) SCI
  16. WHERE ( S.SID = 32 )
  17.  AND ( (s.USERNAME is not null) and (NVL(s.osuser,'x') <> 'SYSTEM') and (s.type <> 'BACKGROUND') )
  18. and s.sid = sci.sid (+)
  19. and s.serial# = sci.serial# (+);

  20. --Process
  21. SELECT * FROM V$PROCESS WHERE addr=(select paddr from v$session where sid=32);
  22. --IO
  23. SELECT * FROM V$SESS_IO WHERE SID = 32;
  24. --Current Waits
  25. SELECT SID, SEQ#, EVENT, WAIT_TIME, SECONDS_IN_WAIT, STATE, p1, p1text, p2, p2text, p3, p3text, wait_time_micro, time_since_last_wait_micro
  26. FROM v$session_wait
  27. WHERE SID = 32
  28. ORDER BY SID, SECONDS_IN_WAIT desc;
  29. --Total Waits
  30. SELECT SID, EVENT, TOTAL_WAITS, TOTAL_TIMEOUTS, TIME_WAITED, AVERAGE_WAIT
  31.          , MAX_WAIT
  32.          , TIME_WAITED_MICRO
  33. FROM v$session_event
  34. Where SID = 32
  35. ORDER BY SID, TIME_WAITED desc;
  36. --Current Sql
  37. select *
  38.   from v$sql
  39.  where (sql_id,child_number) =
  40.        (select decode(sql_id, null, prev_sql_id, sql_id) sql_id,
  41.                decode(sql_child_number,null,prev_child_number,sql_child_number) sql_child_number
  42.           from v$session
  43.          where sid = '32');
  44. --Open Cursors
  45. select o.sid, o.sql_text, o.address, o.hash_value, o.user_name, s.schemaname, o.sql_id
  46. from v$open_cursor o, v$session s
  47. where o.saddr = s.saddr
  48. and o.sid = s.sid
  49. and ( O.SID = 32);
  50. --Access
  51. SELECT sid, owner, type, object FROM v$access WHERE SID = 32;
  52. --Locks
  53. SELECT SID, DECODE(lk.TYPE, 'MR', 'Media Recovery', 'RT', 'Redo Thread', 'UN', 'User Name', 'DX', 'Distributed Xaction',
  54.         'CF', 'Control File', 'IS', 'Instance State', 'FS', 'File Set', 'IR', 'Instance Recovery', 'ST', 'Disk Space Transaction',
  55.         'TS', 'Temp Segment', 'IV', 'Library Cache Invalidation', 'LS', 'Log Start or Switch', 'RW', 'Row Wait', 'SQ', 'Sequence Number',
  56.         'TE', 'Extend Table', 'TT', 'Temp Table', 'BL','Buffer hash table instance', 'CI','Cross-instance function invocation instance',
  57.         'CU','Cursor bind', 'DF','Data file instance', 'DL','Direct loader parallel index create', 'DM','Mount/startup db primary/secondary instance',
  58.         'DR','Distributed recovery process', 'HW','Space management operations on a specific segment', 'IN','Instance number', 'JQ','Job queue',
  59.         'KK','Thread kick', 'LA','Library cache lock instance lock namespace A', 'LB','Library cache lock instance lock namespace B',
  60.         'LC','Library cache lock instance lock namespace C', 'LD','Library cache lock instance lock namespace D',
  61.         'LE','Library cache lock instance lock namespace E', 'LF','Library cache lock instance lock namespace F',
  62.         'LG','Library cache lock instance lock namespace G', 'LH','Library cache lock instance lock namespace H',
  63.         'LI','Library cache lock instance lock namespace I', 'LJ','Library cache lock instance lock namespace J',
  64.         'LK','Library cache lock instance lock namespace K', 'LL','Library cache lock instance lock namespace L',
  65.         'LM','Library cache lock instance lock namespace M', 'LN','Library cache lock instance lock namespace N',
  66.         'LO','Library cache lock instance lock namespace O', 'LP','Library cache lock instance lock namespace P',
  67.         'MM','Mount definition global enqueue', 'NA','Library cache pin instance A', 'NB','Library cache pin instance B',
  68.         'NC','Library cache pin instance C', 'ND','Library cache pin instance D', 'NE','Library cache pin instance E',
  69.         'NF','Library cache pin instance F', 'NG','Library cache pin instance G', 'NH','Library cache pin instance H',
  70.         'NI','Library cache pin instance I', 'NJ','Library cache pin instance J', 'NK','Library cache pin instance K',
  71.         'NL','Library cache pin instance L', 'NM','Library cache pin instance M', 'NN','Library cache pin instance N',
  72.         'NO','Library cache pin instance O', 'NP','Library cache pin instance P', 'NQ','Library cache pin instance Q',
  73.         'NR','Library cache pin instance R', 'NS','Library cache pin instance S', 'NT','Library cache pin instance T',
  74.         'NU','Library cache pin instance U', 'NV','Library cache pin instance V', 'NW','Library cache pin instance W',
  75.         'NX','Library cache pin instance X', 'NY','Library cache pin instance Y', 'NZ','Library cache pin instance Z',
  76.         'PF','Password File', 'PI',' PS Parallel operation', 'PR','Process startup', 'QA','Row cache instance A', 'QB',
  77.         'Row cache instance B', 'QC','Row cache instance C', 'QD','Row cache instance D', 'QE','Row cache instance E',
  78.         'QF','Row cache instance F', 'QG','Row cache instance G', 'QH','Row cache instance H', 'QI','Row cache instance I',
  79.         'QJ','Row cache instance J', 'QK','Row cache instance K', 'QL','Row cache instance L', 'QM','Row cache instance M',
  80.         'QN','Row cache instance N', 'QO','Row cache instance O', 'QP','Row cache instance P', 'QQ','Row cache instance Q',
  81.         'QR','Row cache instance R', 'QS','Row cache instance S', 'QT','Row cache instance T', 'QU','Row cache instance U',
  82.         'QV','Row cache instance V', 'QW','Row cache instance W', 'QX','Row cache instance X', 'QY','Row cache instance Y',
  83.         'QZ','Row cache instance Z', 'SC','System commit number instance', 'SM','SMON', 'SN','Sequence number instance',
  84.         'SS','Sort segment', 'SV','Sequence number value', 'TA','Generic enqueue', 'US','Undo segment DDL', 'WL','Being-written redo log instance', lk.TYPE) lock_type,
  85.         DECODE(lk.lmode, 0, 'None', 1, 'Null', 2, 'Row-S (SS)', 3, 'Row-X (SX)', 4, 'Share', 5, 'S/Row-X (SSX)', 6, 'Exclusive', TO_CHAR(lk.lmode)) mode_held,
  86.         DECODE(lk.request, 0, 'None', 1, 'Null', 2, 'Row-S (SS)', 3, 'Row-X (SX)', 4, 'Share', 5, 'S/Row-X (SSX)', 6, 'Exclusive', TO_CHAR(lk.request)) mode_requested,
  87.         lk.id1 lock_id1, lk.id2 lock_id2
  88. FROM v$lock lk
  89. WHERE SID = 32
  90. ORDER BY SID;
  91. --Rollback Segment Usage
  92. SELECT r.segment_name, r.tablespace_name, t.status, t.cr_get, t.phy_io, t.used_ublk, t.noundo, t.start_time
  93. FROM sys.v_$transaction t, dba_rollback_segs r
  94. WHERE t.xidusn = r.segment_id
  95. and t.addr =(select taddr from v$session where sid=32)
  96. ORDER BY t.start_time;
  97. --Long Ops
  98. SELECT SID, decode(totalwork, 0, 0, round(100 * sofar/totalwork, 2)) "Percent", message "Message", start_time, elapsed_seconds, time_remaining
  99. from v$Session_longops
  100. where (SID = 32 )
  101. ORDER BY SID;
  102. --Statistics
  103. SELECT a.sid,
  104.        decode(b.class,
  105.               1,
  106.               'User',
  107.               2,
  108.               'Redo',
  109.               4,
  110.               'Enqueue',
  111.               8,
  112.               'Cache',
  113.               16,
  114.               'OS',
  115.               32,
  116.               'ParallelServer',
  117.               64,
  118.               'SQL',
  119.               128,
  120.               'Debug',
  121.               72,
  122.               'SQL & Cache',
  123.               40,
  124.               'ParallelServer & Cache') class,
  125.        b.name,
  126.        a.value
  127.   from v$sesstat a, v$statname b
  128.  where a.statistic# = b.statistic#
  129.    and b.name in ('table scans (long tables)',
  130.                   'bytes received via SQL*Net from client',
  131.                   'bytes received via SQL*Net from dblink',
  132.                   'consistent changes',
  133.                   'consistent gets',
  134.                   'CPU used by this session',
  135.                   'physical reads',
  136.                   'physical writes',
  137.                   'session pga memory',
  138.                   'session pga memory max',
  139.                   'session uga memory',
  140.                   'session logical reads',
  141.                   'session uga memory max',
  142.                   'sorts (disk)',
  143.                   'sorts (memory)',
  144.                   'table fetch continued row',
  145.                   'opened cursors cumulative',
  146.                   'opened cursors current',
  147.                   'DDL statements parallelized',
  148.                   'DML statements parallelized',
  149.                   'queries parallelized',
  150.                   'buffer is not pinned count',
  151.                   'parse time cpu',
  152.                   'redo blocks written',
  153.                   'redo buffer allocation retries',
  154.                   'redo entries',
  155.                   'redo log space requests',
  156.                   'redo size',
  157.                   'redo synch time',
  158.                   'redo synch writes',
  159.                   'redo wastage',
  160.                   'redo write time',
  161.                   'redo writer latching time',
  162.                   'redo writes')
  163.    and (SID = 32)
  164.  ORDER BY a.sid;

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/28539951/viewspace-2114097/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/28539951/viewspace-2114097/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值