Wednesday, August 6, 2008

V$SESSION

V$SESSION displays session information for each current session.

Column

Datatype

Description

SADDR

RAW(4 | 8)

Session address

SID

NUMBER

Session identifier

SERIAL#

NUMBER

Session serial number. Used to uniquely identify a session's objects. Guarantees that session-level commands are applied to the correct session objects if the session ends and another session begins with the same session ID.

AUDSID

NUMBER

Auditing session ID

PADDR

RAW(4 | 8)

Address of the process that owns the session

USER#

NUMBER

Oracle user identifier

USERNAME

VARCHAR2(30)

Oracle username

COMMAND

NUMBER

Command in progress (last statement parsed); for a list of values. These values also appear in the AUDIT_ACTIONS table.

OWNERID

NUMBER

Identifier of the user who owns the migratable session; the column contents are invalid if the value is 2147483644

For operations using Parallel Slaves, interpret this value as a 4-byte value. The low-order 2 bytes represent the session number and the high-order bytes represent the instance ID of the query coordinator.

TADDR

VARCHAR2(8)

Address of the transaction state object

LOCKWAIT

VARCHAR2(8)

Address of the lock the session is waiting for; NULL if none

STATUS

VARCHAR2(8)

Status of the session:

· ACTIVE - Session currently executing SQL

· INACTIVE

· KILLED - Session marked to be killed

· CACHED - Session temporarily cached for use by Oracle*XA

· SNIPED - Session inactive, waiting on the client

SERVER

VARCHAR2(9)

Server type:

· DEDICATED

· SHARED

· PSEUDO

· NONE

SCHEMA#

NUMBER

Schema user identifier

SCHEMANAME

VARCHAR2(30)

Schema user name

OSUSER

VARCHAR2(30)

Operating system client user name

PROCESS

VARCHAR2(24)

Operating system client process ID

MACHINE

VARCHAR2(64)

Operating system machine name

TERMINAL

VARCHAR2(30)

Operating system terminal name

PROGRAM

VARCHAR2(48)

Operating system program name

TYPE

VARCHAR2(10)

Session type

SQL_ADDRESS

RAW(4 | 8)

Used with SQL_HASH_VALUE to identify the SQL statement that is currently being executed

SQL_HASH_VALUE

NUMBER

Used with SQL_ADDRESS to identify the SQL statement that is currently being executed

SQL_ID

VARCHAR2(13)

SQL identifier of the SQL statement that is currently being executed

SQL_CHILD_NUMBER

NUMBER

Child number of the SQL statement that is currently being executed

SQL_EXEC_START

DATE

Time when the execution of the SQL currently executed by this session started; NULL if SQL_ID is NULL

SQL_EXEC_ID

NUMBER

SQL execution identifier; NULL if SQL_ID is NULL or if the execution of that SQL has not yet started (see V$SQL_MONITOR)

PREV_SQL_ADDR

RAW(4 | 8)

Used with PREV_HASH_VALUE to identify the last SQL statement executed

PREV_HASH_VALUE

NUMBER

Used with SQL_HASH_VALUE to identify the last SQL statement executed

PREV_SQL_ID

VARCHAR2(13)

SQL identifier of the last SQL statement executed

PREV_CHILD_NUMBER

NUMBER

Child number of the last SQL statement executed

PREV_EXEC_START

DATE

SQL execution start of the last executed SQL statement

PREV_EXEC_ID

NUMBER

SQL execution identifier of the last executed SQL statement

PLSQL_ENTRY_OBJECT_ID

NUMBER

Object ID of the top-most PL/SQL subprogram on the stack; NULL if there is no PL/SQL subprogram on the stack

PLSQL_ENTRY_SUBPROGRAM_ID

NUMBER

Subprogram ID of the top-most PL/SQL subprogram on the stack; NULL if there is no PL/SQL subprogram on the stack

PLSQL_OBJECT_ID

NUMBER

Object ID of the currently executing PL/SQL subprogram; NULL if executing SQL

PLSQL_SUBPROGRAM_ID

NUMBER

Subprogram ID of the currently executing PL/SQL object; NULL if executing SQL

MODULE

VARCHAR2(48)

Name of the currently executing module as set by calling the DBMS_APPLICATION_INFO.SET_MODULE procedure

MODULE_HASH

NUMBER

Hash value of the MODULE column

ACTION

VARCHAR2(32)

Name of the currently executing action as set by calling the DBMS_APPLICATION_INFO.SET_ACTION procedure

ACTION_HASH

NUMBER

Hash value of the ACTION column

CLIENT_INFO

VARCHAR2(64)

Information set by the DBMS_APPLICATION_INFO.SET_CLIENT_INFO procedure

FIXED_TABLE_SEQUENCE

NUMBER

This contains a number that increases every time the session completes a call to the database and there has been an intervening select from a dynamic performance table. This column can be used by performance monitors to monitor statistics in the database. Each time the performance monitor looks at the database, it only needs to look at sessions that are currently active or have a higher value in this column than the highest value that the performance monitor saw the last time. All the other sessions have been idle since the last time the performance monitor looked at the database.

ROW_WAIT_OBJ#

NUMBER

Object ID for the table containing the row specified in ROW_WAIT_ROW#

ROW_WAIT_FILE#

NUMBER

Identifier for the datafile containing the row specified in ROW_WAIT_ROW#. This column is valid only if the session is currently waiting for another transaction to commit and the value of ROW_WAIT_OBJ# is not -1.

ROW_WAIT_BLOCK#

NUMBER

Identifier for the block containing the row specified in ROW_WAIT_ROW#. This column is valid only if the session is currently waiting for another transaction to commit and the value of ROW_WAIT_OBJ# is not -1.

ROW_WAIT_ROW#

NUMBER

Current row being locked. This column is valid only if the session is currently waiting for another transaction to commit and the value of ROW_WAIT_OBJ# is not -1.

LOGON_TIME

DATE

Time of logon

LAST_CALL_ET

NUMBER

If the session STATUS is currently ACTIVE, then the value represents the elapsed time (in seconds) since the session has become active.

If the session STATUS is currently INACTIVE, then the value represents the elapsed time (in seconds) since the session has become inactive.

PDML_ENABLED

VARCHAR2(3)

This column has been replaced by the PDML_STATUS column

FAILOVER_TYPE

VARCHAR2(13)

Indicates whether and to what extent transparent application failover (TAF) is enabled for the session:

· NONE - Failover is disabled for this session

· SESSION - Client is able to fail over its session following a disconnect

· SELECT - Client is able to fail over queries in progress as well

FAILOVER_METHOD

VARCHAR2(10)

Indicates the transparent application failover method for the session:

· NONE - Failover is disabled for this session

· BASIC - Client itself reconnects following a disconnect

· PRECONNECT - Backup instance can support all connections from every instance for which it is backed up

FAILED_OVER

VARCHAR2(3)

Indicates whether the session is running in failover mode and failover has occurred (YES) or not (NO)

RESOURCE_CONSUMER_GROUP

VARCHAR2(32)

Name of the session's current resource consumer group

PDML_STATUS

VARCHAR2(8)

If ENABLED, the session is in a PARALLEL DML enabled mode. If DISABLED, PARALLEL DML enabled mode is not supported for the session. If FORCED, the session has been altered to force PARALLEL DML.

PDDL_STATUS

VARCHAR2(8)

If ENABLED, the session is in a PARALLEL DDL enabled mode. If DISABLED, PARALLEL DDL enabled mode is not supported for the session. If FORCED, the session has been altered to force PARALLEL DDL.

PQ_STATUS

VARCHAR2(8)

If ENABLED, the session is in a PARALLEL QUERY enabled mode. If DISABLED, PARALLEL QUERY enabled mode is not supported for the session. If FORCED, the session has been altered to force PARALLEL QUERY.

CURRENT_QUEUE_DURATION

NUMBER

If queued (1), the current amount of time the session has been queued. If not currently queued, the value is 0.

CLIENT_IDENTIFIER

VARCHAR2(64)

Client identifier of the session

BLOCKING_SESSION_STATUS

VARCHAR2(11)

Blocking session status:

· VALID

· NO HOLDER

· GLOBAL

· NOT IN WAIT

· UNKNOWN

BLOCKING_INSTANCE

NUMBER

Instance identifier of the blocking session

BLOCKING_SESSION

NUMBER

Session identifier of the blocking session

SEQ#

NUMBER

A number that uniquely identifies the current or last wait (incremented for each wait)

EVENT#

NUMBER

Event number

EVENT

VARCHAR2(64)

Resource or event for which the session is waiting

P1TEXT

VARCHAR2(64)

Description of the first wait event parameter

P1

NUMBER

First wait event parameter (in decimal)

P1RAW

RAW(8)

First wait event parameter (in hexadecimal)

P2TEXT

VARCHAR2(64)

Description of the second wait event parameter

P2

NUMBER

Second wait event parameter (in decimal)

P2RAW

RAW(8)

Second wait event parameter (in hexadecimal)

P3TEXT

VARCHAR2(64)

Description of the third wait event parameter

P3

NUMBER

Third wait event parameter (in decimal)

P3RAW

RAW(8)

Third wait event parameter (in hexadecimal)

WAIT_CLASS_ID

NUMBER

Identifier of the class of the wait event

WAIT_CLASS#

NUMBER

Number of the class of the wait event

WAIT_CLASS

VARCHAR2(64)

Name of the class of the wait event

WAIT_TIME

NUMBER

If the session is currently waiting, then the value is 0. If the session is not in a wait, then the value is as follows:

· > 0 - Value is the duration of the last wait in hundredths of a second

· -1 - Duration of the last wait was less than a hundredth of a second

· -2 - Parameter TIMED_STATISTICS was set to false

This column has been deprecated in favor of the columns WAIT_TIME_MICRO and STATE.

SECONDS_IN_WAIT

NUMBER

If the session is currently waiting, then the value is the amount of time waited for the current wait. If the session is not in a wait, then the value is the amount of time since the start of the last wait.

This column has been deprecated in favor of the columns WAIT_TIME_MICRO and TIME_SINCE_LAST_WAIT_MICRO.

STATE

VARCHAR2(19)

Wait state:

· WAITING - Session is currently waiting

· WAITED UNKNOWN TIME - Duration of the last wait is unknown; this is the value when the parameter TIMED_STATISTICS is set to false

· WAITED SHORT TIME - Last wait was less than a hundredth of a second

· WAITED KNOWN TIME - Duration of the last wait is specified in the WAIT_TIME column

WAIT_TIME_MICRO

NUMBER

Amount of time waited (in microseconds). If the session is currently waiting, then the value is the time spent in the current wait. If the session is currently not in a wait, then the value is the amount of time waited in the last wait.

TIME_REMAINING_MICRO

NUMBER

Value is interpreted as follows:

· > 0 - Amount of time remaining for the current wait (in microseconds)

· 0 - Current wait has timed out

· -1 - Session can indefinitely wait in the current wait

· NULL - Session is not currently waiting

TIME_SINCE_LAST_WAIT_MICRO

NUMBER

Time elapsed since the end of the last wait (in microseconds). If the session is currently in a wait, then the value is 0.

SERVICE_NAME

VARCHAR2(64)

Service name of the session

SQL_TRACE

VARCHAR2(8)

Indicates whether SQL tracing is enabled (ENABLED) or disabled (DISABLED)

SQL_TRACE_WAITS

VARCHAR2(5)

Indicates whether wait tracing is enabled (TRUE) or not (FALSE)

SQL_TRACE_BINDS

VARCHAR2(5)

Indicates whether bind tracing is enabled (TRUE) or not (FALSE)

SQL_TRACE_PLAN_STATS

VARCHAR2(10)

Frequency at which row source statistics are dumped in the trace files for each cursor:

· never

· first_execution

· all_executions

SESSION_EDITIONID

NUMBER

Reserved for future use

CREATOR_ADDR

RAW(4 | 8)

Address of the creating process or circuit

CREATOR_SERIAL#

NUMBER

Serial number of the creating process or circuit

*The P1RAW, P2RAW, and P3RAW columns display the same values as the P1, P2, and P3 columns, except that the numbers are displayed in hexadecimal.

COMMAND Column of V$SESSION and Corresponding Commands

Number

Command

Number

Command

1

CREATE TABLE

2

INSERT

3

SELECT

4

CREATE CLUSTER

5

ALTER CLUSTER

6

UPDATE

7

DELETE

8

DROP CLUSTER

9

CREATE INDEX

10

DROP INDEX

11

ALTER INDEX

12

DROP TABLE

13

CREATE SEQUENCE

14

ALTER SEQUENCE

15

ALTER TABLE

16

DROP SEQUENCE

17

GRANT OBJECT

18

REVOKE OBJECT

19

CREATE SYNONYM

20

DROP SYNONYM

21

CREATE VIEW

22

DROP VIEW

23

VALIDATE INDEX

24

CREATE PROCEDURE

25

ALTER PROCEDURE

26

LOCK

27

NO-OP

28

RENAME

29

COMMENT

30

AUDIT OBJECT

31

NOAUDIT OBJECT

32

CREATE DATABASE LINK

33

DROP DATABASE LINK

34

CREATE DATABASE

35

ALTER DATABASE

36

CREATE ROLLBACK SEG

37

ALTER ROLLBACK SEG

38

DROP ROLLBACK SEG

39

CREATE TABLESPACE

40

ALTER TABLESPACE

41

DROP TABLESPACE

42

ALTER SESSION

43

ALTER USER

44

COMMIT

45

ROLLBACK

46

SAVEPOINT

47

PL/SQL EXECUTE

48

SET TRANSACTION

49

ALTER SYSTEM

50

EXPLAIN

51

CREATE USER

52

CREATE ROLE

53

DROP USER

54

DROP ROLE

55

SET ROLE

56

CREATE SCHEMA

57

CREATE CONTROL FILE

59

CREATE TRIGGER

60

ALTER TRIGGER

61

DROP TRIGGER

62

ANALYZE TABLE

63

ANALYZE INDEX

64

ANALYZE CLUSTER

65

CREATE PROFILE

66

DROP PROFILE

67

ALTER PROFILE

68

DROP PROCEDURE

70

ALTER RESOURCE COST

71

CREATE MATERIALIZED VIEW LOG

72

ALTER MATERIALIZED VIEW LOG

73

DROP MATERIALIZED VIEW LOG

74

CREATE MATERIALIZED VIEW

75

ALTER MATERIALIZED VIEW

76

DROP MATERIALIZED VIEW

77

CREATE TYPE

78

DROP TYPE

79

ALTER ROLE

80

ALTER TYPE

81

CREATE TYPE BODY

82

ALTER TYPE BODY

83

DROP TYPE BODY

84

DROP LIBRARY

85

TRUNCATE TABLE

86

TRUNCATE CLUSTER

91

CREATE FUNCTION

92

ALTER FUNCTION

93

DROP FUNCTION

94

CREATE PACKAGE

95

ALTER PACKAGE

96

DROP PACKAGE

97

CREATE PACKAGE BODY

98

ALTER PACKAGE BODY

99

DROP PACKAGE BODY

100

LOGON

101

LOGOFF

102

LOGOFF BY CLEANUP

103

SESSION REC

104

SYSTEM AUDIT

105

SYSTEM NOAUDIT

106

AUDIT DEFAULT

107

NOAUDIT DEFAULT

108

SYSTEM GRANT

109

SYSTEM REVOKE

110

CREATE PUBLIC SYNONYM

111

DROP PUBLIC SYNONYM

112

CREATE PUBLIC DATABASE LINK

113

DROP PUBLIC DATABASE LINK

114

GRANT ROLE

115

REVOKE ROLE

116

EXECUTE PROCEDURE

117

USER COMMENT

118

ENABLE TRIGGER

119

DISABLE TRIGGER

120

ENABLE ALL TRIGGERS

121

DISABLE ALL TRIGGERS

122

NETWORK ERROR

123

EXECUTE TYPE

157

CREATE DIRECTORY

158

DROP DIRECTORY

159

CREATE LIBRARY

160

CREATE JAVA

161

ALTER JAVA

162

DROP JAVA

163

CREATE OPERATOR

164

CREATE INDEXTYPE

165

DROP INDEXTYPE

167

DROP OPERATOR

168

ASSOCIATE STATISTICS

169

DISASSOCIATE STATISTICS

170

CALL METHOD

171

CREATE SUMMARY

172

ALTER SUMMARY

173

DROP SUMMARY

174

CREATE DIMENSION

175

ALTER DIMENSION

176

DROP DIMENSION

177

CREATE CONTEXT

178

DROP CONTEXT

179

ALTER OUTLINE

180

CREATE OUTLINE

181

DROP OUTLINE

182

UPDATE INDEXES

183

ALTER OPERATOR

Note:

  1. The following query identifies CPU usage Per schema in a simple resource plan scenario (Metalink note 728613.1):

select sum(r.CONSUMED_CPU_TIME) "CONSUMED CPU TIME" , s.username "SCHEMA"

from V$RSRC_SESSION_INFO r, v$session s

where r.sid = s.sid group by username;

  1. Generate sql to kill a session:

select 'alter system disconnect session '''||s.sid||','||s.serial#||''' immediate;'

from V$PROCESS p, V$SESSION s

where s.paddr = p.addr and s.username = upper ('&killme');

select 'alter system kill session '''||s.sid||','||s.serial#||''' immediate;'

from V$PROCESS p, V$SESSION s

where s.paddr = p.addr and s.username = upper ('&killme');

  1. List the old sessions:

select s.osuser, p.spid, s.username, s.sid, s.serial#,

to_char(s.logon_time,'Dy dd Mon HH24:MI:SS') start_time,

s.status, s.machine, s.MODULE

from V$PROCESS p, V$SESSION s

where s.paddr = p.addr and s.username is not null

and s.status = 'INACTIVE' and s.logon_time <>

  1. Show current users:

select s.osuser, p.spid, s.username, s.sid, s.serial#,

to_char(s.logon_time,'Dy dd Mon HH24:MI:SS') start_time, s.status,

s.machine, s.MODULE

from V$PROCESS p,V$SESSION s

where s.paddr = p.addr and s.username is not null

order by logon_time,1;

  1. Show the number of current commits:

select command, count(command)

from V$SESSION

where command = '44'

group by command

order by 1;

  1. List stale connections:

select to_char(logon_time,'Dy dd Mon HH24:MI') logon_time,

sid || ',' || serial# sid_serial, username, osuser,

trunc(last_call_et/60/60) last_call, status, program, module

from V$SESSION

where type != 'BACKGROUND' and username is not null

and trunc(last_call_et/60/60) > 1

order by 5;

  1. Show how users are logging on

select program,count(program)

from V$SESSION

group by program

order by program;

  1. List current sessions and their sql statements:

select vp.username os_user, vp.spid server_pid, vs.process client_pid,

vs.sid||','||vs.serial# SID_Serial, vs.terminal,

vs.username oracle_username, vs.status,

to_char(vs.LOGON_TIME, 'dd/mon hh:mi') logon_time,

to_char(trunc(sysdate) + (vs.LAST_CALL_ET/(24*3600)), 'hh24:mi') Idle_time,

vl2.sid lock_sid,

to_char(trunc(sysdate) + (vl1.ctime/(24*3600)), 'hh24:mi') Wait_time

from V$PROCESS vp, V$SESSION vs, V$LOCK vl1, V$LOCK vl2

where vp.addr = vs.paddr

and vs.lockwait = vl1.kaddr(+)

and vl1.id1=vl2.id1(+)

and vl2.lmode(+)!=0

and vs.paddr not in (select paddr from V$BGPROCESS)

order by 7, 9 -- Status, Idle Time

select vs.sid||','||vs.serial# SID_Serial,

vs.status, vs.module, st.sql_text

from V$SESSION vs, V$SQLTEXT st

where st.address = decode(vs.sql_address, hextoraw('00'), vs.prev_sql_addr, vs.sql_address)

and st.hash_value = decode(vs.sql_hash_value, 0, vs.prev_hash_value, vs.sql_hash_value)

and vs.paddr not in (select paddr from V$BGPROCESS) -- exclude background processes

order by vs.status, vs.last_call_et, 1, st.piece

  1. List current running sql statements:

SELECT u.sid, u.username, s.sql_text

FROM V$SQL s, V$SESSION u

WHERE s.hash_value = u.sql_hash_value

AND sql_text not like '%from v$sql s, v$session u%'

ORDER BY u.sid;

  1. Troubleshooting enq: TX - row lock contention

--for which SQL currently is waiting to,

select sid, sql_text

from v$session s, v$sql q

where sid in (select sid

from v$session where state in ('WAITING')

and wait_class != 'Idle' and event='enq: TX - row lock contention'

and (q.sql_id = s.sql_id or q.sql_id = s.prev_sql_id)

);

--The blocking session is:

select blocking_session, sid, serial#, wait_class, seconds_in_wait

from v$session

where blocking_session is not NULL

order by blocking_session;

  1. find out What session has locked a PL/SQL package

select x.sid

from v$session x, v$sqltext y

where x.sql_address = y.address

and y.sql_text like '%%';

Oracle data dictionary views

Oracle dynamic performance views

Last updated: July 07, 2009

No comments:

Post a Comment