• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

Oracle SQL Script: To Obtain Session Information

by admin

Purpose

This script reports information about the current user’s session. It should not be used when connected as user SYS. This is because audsid for user SYS as well as background processes is always 0 and, therefore, the script will return multiple entries in this case.

Configuration

Access Privileges

Requires SELECT privilege on v$process and v$session or SELECT_CATALOG_ROLE(Oracle8 and higher).

Usage

Copy the script to a file named tfssgrep.sql and execute it from SQL*Plus connected as the user you wish to report on.

sqlplus username/ @tftssinfo.sql

Script

def aps_prog    = 'mysess.sql'
def aps_title   = 'Session  Info'
col "Session Info" form A80

select 'Sid, Serial#, Aud sid : '|| s.sid||' , '||s.serial#||' , '||
       s.audsid||chr(10)|| 'DB User / OS User : '||s.username||
       '   /   '||s.osuser||chr(10)|| 'Machine - Terminal : '||
       s.machine||'  -  '|| s.terminal||chr(10)||
 'OS Process Ids : '||
       s.process||' (Client)  '||p.spid||' (Server)'|| chr(10)||
       'Client Program Name : '||s.program "Session Info"
  from v$process p,v$session s
 where p.addr = s.paddr
  and s.audsid = userenv('SESSIONID')
/

Sample Output

Session Info
--------------------------------------------------------------------------------
Sid, Serial#, Aud sid : 7 , 79 , 412
DB User / OS User : SCOTT   /   asantana
Machine - Terminal : stsun7  -  pts/98
OS Process Ids : 18820 (Client)  18831 (Server)
Client Program Name : sqlplus@stsun7 (TNS V1-V2)

Filed Under: oracle

Some more articles you might also be interested in …

  1. How to Create Undo Tablespace for a Newly Added RAC Instance (ORA-30012)
  2. Unable to Drop Undo tablespace Since Undo Segment is in Needs Recovery
  3. Operators in PL/SQL
  4. Oracle Database 12c New Feature – Move a Datafile Online
  5. Auditing with Oracle Database Vault Reports
  6. How to Clone PDB With Oracle Key Vault (OKV)
  7. How to Disable Oracle Net Tracing without stopping server process
  8. Oracle 12.2 : RMAN Cross-Platform Transport of PDB into Destination CDB
  9. How to limit access to oracle database so that only 1 user per schema is connected ( 1 Concurrent user per schema)
  10. How to Create and Manage Snapshot Standby Database

You May Also Like

Primary Sidebar

Recent Posts

  • protonvpn-cli Command Examples in Linux
  • protonvpn-cli connect Command Examples
  • procs Command Examples in Linux
  • prlimit: command not found

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright