Thursday, April 4, 2013

Useful database session tracking scripts for DBA


-- Show Database Sessions for a certain node

SELECT s.audsid AUDSID,
       i.instance_name "Instance",

       s.machine "Machine",
       s.program "Program",
       s.module "Module",
       s.osuser "User",
       s.process "Process",
       s.status "Status",
       s.logon_time "Logon Time"
  FROM gv$session s, gv$instance i
 WHERE     s.audsid > 0
       AND s.inst_id = i.inst_id
       AND UPPER (s.machine) LIKE '%' || UPPER (&1) || '%';



-- Show Database Sessions for a certain instance

SELECT s.audsid AUDSID,
       i.instance_name "Instance",
       s.machine "Machine",
       s.program "Program",
       s.module "Module",
       s.osuser "User",
       s.process "Process",
       s.status "Status",
       s.logon_time "Logon Time"
  FROM gv$session s, gv$instance i
 WHERE     s.audsid > 0
       AND s.inst_id = i.inst_id
       AND UPPER (i.instance_name) LIKE '%' || UPPER (&1) || '%';



--Show the RDBMS options installed and their versions

SELECT banner FROM v$version;


-- Database Segment Storage Summary

SELECT owner ownr,
       segment_name name,
       segment_type TYPE,
       header_file hfil,
       header_block hblk,
       extents exts,
       blocks blks
  FROM dba_segments
 WHERE owner LIKE UPPER ('&ownr') AND segment_name LIKE UPPER ('&segt')