Search notes:

Oracle: V$SESSION

Each record in v$session shows information about a «current» session.

Search for session by operating system user and/or program name

v$sessions records the operating system user name and the program name with which he/she connects to Oracle in the columns username and program.
The Oracle user name (schema) with which a user connected to Oracle is recorded in username.
With this information, it is possible to find an «interesting» session:
select /*+ ordered */
-- ses.sid,
-- ses.saddr,
-- ses.serial#,
   ses.program,
-- ses.osuser,
   ses.event,
   round(ses.wait_time_micro/1000/1000, 2) wait_s,   
-- ses.sql_id,
-- ses.prev_sql_id,
   ses.logon_time,
   substr(sql.sql_text, 1, 50)             cur_sql_text,
   substr(sqp.sql_text, 1, 50)             prev_sql_text
from
   v$session  ses                                    left join
   v$sqlarea  sql on ses.sql_id      = sql.sql_id    left join
   v$sqlarea  sqp on ses.prev_sql_id = sqp.sql_id
where
  osuser   = 'rene'          and
--program  = 'SQL Developer' and
  program  = 'sqlplus.exe';
Github repository oracle-patterns, path: /Installed/dynamic-performance-views/session/find-my-interesting-sessions.sql

Blocking sessions

If a sesssion cannot continue with the current execution because it is blocked by another session, the blocked session records the instance and session id of the blocking session in the columns blocking_instance and blocking_session.
--
-- See also v$session_blockers
--
select 
  ses.sid                      blocked_sid,
  ses.username                 blocked_username,
  ses.osuser                   blocked_osuser,
  ses.blocking_session_status  blocked_session_status, -- VALID:There is a blocking session
  --
  bls.sid                      blocking_sid,
  bls.username                 blocking_username,
  bls.osuser                   blocking_osuser,
  --
  ses.event                    blocked_event,
  bls.event                    blocking_event,
  --
  ses.sql_id                   blocked_sql_id,
  bls.sql_id                   blocking_sql_Id
from
  gv$session ses                                           join
  gv$session bls on ses.blocking_session  = bls.sid  and
                    ses.blocking_instance = bls.inst_id;
Github repository oracle-patterns, path: /Installed/dynamic-performance-views/session/blocked-blocking.sql

audsid

The column audsid can be joined with sys_context('userenv','SESSIONID') to find out which session is the "own one".
Alternatively, dbms_support.mysid can be used: where sid = sys.dbms_support.mysid.
Identifying one's own session

Columns MODULE, ACTION, CLIENT_INFO and CLIENT_IDENTIFIER

The values of the columns module, action and client_info can be set with procedures set_module, set_client_info and set_action of the dbms_application_info package
(See v$session_longops for an example).
The value of client_identifier can be set with dbms_session.set_identifier.
begin

  dbms_application_info.set_module (
    module_name => 'tq84_module',
    action_name => 'tq84_action'
  );

end;
/

select
  sid,
  to_number(sys_context('userenv', 'sid')) sid_verify,
  action
from
  v$session
where
  module = 'tq84_module';
Github repository oracle-patterns, path: /Installed/dynamic-performance-views/session/module-action.sql
RMAN sets the value of client_info to something that can be queried with client_info like '%rman%'.
See also Set action, client_identifier, client_info and module in v$session with ADO.NET (C#)

module_hash

It turns out that the value of module_hash is equal to ora_hash(module). Thus, the following select statement does not return a record:
select
  module, 
  module_hash,
  ora_hash(module)
from
  v$session
where
  module_hash != ora_hash(module);
Github repository oracle-patterns, path: /Installed/dynamic-performance-views/session/module_hash.sql

sql_exec_id

As Tanel Poder points out, the value of sql_exec_id seems to start with 224 for every sql_id when Oracle is started.
sql_exec_id is also found in v$active_session_history and v$open_cursor.

Joins

Some v$ views that can be joined to include:
select /*+ ordered */
  ses.sid,
  ses.logon_time   ses_logontime,
  prc.pid          prc_pid,        -- Oracle process identifier
--prc.sosid        prc_sosid,      -- OS process/thread identifier
  prc.spid         prc_spid,       -- OS process identifier
--prc.stid         prc_stid,       -- OS thread identifier
--ses.paddr        prc_addr,
--ses.taddr        trx_addr,
  trx.start_time   trx_start_time,
  case when pxs.sid is not null then
    case
      when ses.sid = pxs.qcsid then 'Query coordinator'
      else 'Query server, QC is ' || pxs.qcsid
    end
  end  parallel_info,
  sqc.command_name,
--aud.name         aud_name,
  sql.sql_text     sql_text
from
  v$session     ses                                                   join
  v$process     prc on ses.paddr           = prc.addr            left join
  v$transaction trx on ses.taddr           = trx.addr            left join
  v$sql         sql on ses.sql_address     = sql.address      and  
                       ses.sql_hash_value  = sql.hash_value      left join
  v$sqlcommand  sqc on ses.command         = sqc.command_type    left join
  v$px_session  pxs on ses.sid             = pxs.sid          and
                       ses.serial#         = pxs.serial#         left join
  audit_actions aud on ses.command         = aud.action
order by
  ses.sid
;
Github repository oracle-patterns, path: /Installed/dynamic-performance-views/session/joins.sql
An attempt to find views that can be joined to v$session with a select statement is here.

Joining V$SESSION to V$SQL

There are (at least) three separate ways to join v$session to v$sql:
select
   count(ses.sid   ) cnt_ses,
   count(sql.sql_id) cnt_sql
from
   v$session ses left join v$sql sql on ses.sql_id         = sql.sql_id     and ses.sql_child_number = sql.child_number
-- v$session ses left join v$sql sql on ses.sql_address    = sql.address    and ses.sql_child_number = sql.child_number
-- v$session ses left join v$sql sql on ses.sql_hash_value = sql.hash_value and ses.sql_child_number = sql.child_number
;

sid

Join sid with v$sesstat to get some statistical information for a particular sesssion.

sid, serial

sid and serial# can be used in a statement to to kill a session.

type

The value of type can be used to identify background (type='BACKGROUND') and foreground (type='USER') processes.

Waiting sessions

What a session is waiting for can be queried with v$session_wait

SADDR

The value of saddr (the session address) might be joined to

Columns

SADDR The session address (RAW)
SID Session ID (unique number for a given point in time)
SERIAL# The combination of SERIAL# and SID is unique across time
AUDSID The Session ID of session that audits a session
PADDR Address of the process (RAW), can be used to join with v$process
USER# ID of the user who is connected to the session
USERNAME Name of the user
COMMAND Type of command (select command_name from v$sqlcommand where command_type = command)
OWNERID ID of the user who owns the migratable session.
TADDR Address (RAW) of the transaction, join with v$transaction.
LOCKWAIT Address of the lock that the session is waiting for, NULL if not waiting.
STATUS ACTIVE, INACTIVE, KILLED, CACHED or SNIPED
SERVER DEDICATED, SHARED, PSEUDO, POOLED or NONE
SCHEMA#
SCHEMANAME
OSUSER Name of operating system user who is connected to session
PROCESS Operating system process id (PID)
MACHINE
PORT
TERMINAL
PROGRAM
TYPE
SQL_ADDRESS, SQL_HASH_VALUE SQL_ADDRESS and SQL_HASH_VALUE identify the SQL statement that is currently executed by the session (join with v$sql)
SQL_ID
SQL_CHILD_NUMBER
SQL_EXEC_START
SQL_EXEC_ID
PREV_SQL_ADDR
PREV_HASH_VALUE
PREV_SQL_ID
PREV_CHILD_NUMBER
PREV_EXEC_START
PREV_EXEC_ID
PLSQL_ENTRY_OBJECT_ID
PLSQL_ENTRY_SUBPROGRAM_ID
PLSQL_OBJECT_ID
PLSQL_SUBPROGRAM_ID
MODULE
MODULE_HASH
ACTION
ACTION_HASH
CLIENT_INFO
FIXED_TABLE_SEQUENCE
ROW_WAIT_OBJ#
ROW_WAIT_FILE#
ROW_WAIT_BLOCK#
ROW_WAIT_ROW#
TOP_LEVEL_CALL#
LOGON_TIME
LAST_CALL_ET
PDML_ENABLED Replaced by PDML_STATUS
FAILOVER_TYPE NONE, SESSION, SELECT, TRANSACTION or AUTO
FAILOVER_METHOD
FAILED_OVER
RESOURCE_CONSUMER_GROUP
PDML_STATUS, ENABLED, DISABLED or FORCED. PDML = Parallel DML. Replaces PDML_ENABLED
PDDL_STATUS ENABLED, DISABLED or FORCED. PDDL = Parallel DDL
PQ_STATUS ENABLED, DISABLED or FORCED. PQ = Parallel Query.
CURRENT_QUEUE_DURATION
CLIENT_IDENTIFIER
BLOCKING_SESSION_STATUS
BLOCKING_INSTANCE
BLOCKING_SESSION
FINAL_BLOCKING_SESSION_STATUS
FINAL_BLOCKING_INSTANCE
FINAL_BLOCKING_SESSION
SEQ#
EVENT# Column value replicated from v$session_wait.
EVENT Column value replicated from v$session_wait.
P1TEXT Column value replicated from v$session_wait.
P1 Column value replicated from v$session_wait.
P1RAW Column value replicated from v$session_wait.
P2TEXT Column value replicated from v$session_wait.
P2 Column value replicated from v$session_wait.
P2RAW Column value replicated from v$session_wait.
P3TEXT Column value replicated from v$session_wait.
P3 Column value replicated from v$session_wait.
P3RAW Column value replicated from v$session_wait.
WAIT_CLASS_ID Column value replicated from v$session_wait.
WAIT_CLASS# Column value replicated from v$session_wait.
WAIT_CLASS Column value replicated from v$session_wait.
WAIT_TIME Column value replicated from v$session_wait.
SECONDS_IN_WAIT Column value replicated from v$session_wait.
STATE Column value replicated from v$session_wait.
WAIT_TIME_MICRO Column value replicated from v$session_wait.
TIME_REMAINING_MICRO Column value replicated from v$session_wait.
TIME_SINCE_LAST_WAIT_MICRO Column value replicated from v$session_wait.
SERVICE_NAME
SQL_TRACE
SQL_TRACE_WAITS
SQL_TRACE_BINDS
SQL_TRACE_PLAN_STATS
SESSION_EDITION_ID
CREATOR_ADDR
CREATOR_SERIAL#
ECID
SQL_TRANSLATION_PROFILE_ID
PGA_TUNABLE_MEM The amount of tunable PGA memory, in bytes. v$process.pga_alloc_mem minus v$session.pga_tunable_mem is the amount of untunable memory.
SHARD_DDL_STATUS
CON_ID
EXTERNAL_NAME
PLSQL_DEBUGGER_CONNECTED

TODO

select
  count(         *      ),
  count(distinct saddr  ),
  count(distinct sid    ),
  count(distinct serial#),
  count(distinct paddr  ),
  count(         taddr  ),
  count(distinct taddr  )
from
  v$session;
Github repository oracle-patterns, path: /Installed/dynamic-performance-views/session/distinct_values.sql
alter session disable parallel ddl;
alter session disable parallel dml;
alter session disable parallel query;



select
  pdml_enabled,
  pdml_status,
  pddl_status,
  pq_status
from
  v$session where sid = sys_context('userenv', 'sid');
--
-- PDM PDML_STA PDDL_STA PQ_STATU
-- --- -------- -------- --------
-- NO  DISABLED DISABLED DISABLED



alter session enable parallel query;


select
  pdml_enabled,
  pdml_status,
  pddl_status,
  pq_status
from
  v$session where sid = sys_context('userenv', 'sid');
-- PDM PDML_STA PDDL_STA PQ_STATU
-- --- -------- -------- --------
-- NO  DISABLED DISABLED ENABLED




alter session enable parallel ddl;

select
  pdml_enabled,
  pdml_status,
  pddl_status,
  pq_status
from
  v$session where sid = sys_context('userenv', 'sid');
--
-- PDM PDML_STA PDDL_STA PQ_STATU
-- --- -------- -------- --------
-- NO  DISABLED ENABLED  ENABLED




alter session enable parallel dml;

select
  pdml_enabled,
  pdml_status,
  pddl_status,
  pq_status
from
  v$session where sid = sys_context('userenv', 'sid');
--
-- PDM PDML_STA PDDL_STA PQ_STATU
-- --- -------- -------- --------
-- YES ENABLED  ENABLED  ENABLED
Github repository oracle-patterns, path: /Installed/dynamic-performance-views/session/pdml-pddl-pq_status.sql

Some programs that might be seen connected to Oracle

select
 --count(*),
  program 
from
  v$session
where
  program not like 'oracle@%'
group by
  program
order by
  count(*) desc;
-- The query might find programs such as:
--   tabprotosrv.exe
--   Toad.exe
--   JDBC Thin Client
--   SQL Developer
--   EXCEL.EXE
--   MSACCESS.EXE
--   WIReportServer.exe
--   plsqldev.exe
--   WebIRichClient.exe
--   OMS
--   sqlplus.exe
--   DTExec.exe
--   Rgui.exe
--   APEX Listener
--   brioqry.exe  

See also

Oracle Dynamic Performance Views
ses.sql is a small SQL script, intended to be stored at a location that $SQLPATH points at, that displays some rudimentary information about sessions.
http://www.adp-gmbh.ch/ora/concepts/session.html
Joining v$session with v$sql to get the most recently executed SQL statement.
Oracle Manageability Monitor Lite Process (MMNL)
x$ksuse

Index