Thursday, October 8, 2009

SQL Script to check whats going on in database


This is a simple SQL script to check for all sessions describing whats going on in the database. 
set pages 300
set lines 300
col OSUSER format a30
col SCHEMANAME format a25
col USERNAME format a25
col PROGRAM format a20
col COMMAND format a50
select
   osuser, schemaname,
   substr(s.username,1,18) username,
   substr(s.program,1,15) program,
   decode(s.command,
       0,'No Command',
       1,'Create Table',
       2,'Insert',
       3,'Select',
       6,'Update',
       7,'Delete',
       9,'Create Index',
      15,'Alter Table',
      21,'Create View',
      23,'Validate Index',
      35,'Alter Database',
      39,'Create Tablespace',
      41,'Drop Tablespace',
      40,'Alter Tablespace',
      53,'Drop User',
      62,'Analyze Table',
      63,'Analyze Index',
         s.command||': Other') command
from 
   v$session     s,
   v$process     p,
   v$transaction t,
   v$rollstat    r,
   v$rollname    n
where s.paddr = p.addr
and   s.taddr = t.addr (+)
and   t.xidusn = r.usn (+)
and   r.usn = n.usn (+)
and s.schemaname  not in ('SYS','SYSTEM')
order by 1
;

Example o/p:
OSUSER                       SCHEMANAME             USERNAME                    PROGRAM       COMMAND
-------------- ------------------------ --------------------       --------------------       ---------------
Info_USer                      INFO_TNJ             INFO_TNJ             pmrepagent.exe       No Command
Info_USer                      INFO_TNJ             INFO_TNJ             pmrepagent.exe       No Command
Info_USer                      INFO_TNJ             INFO_TNJ             pmrepagent.exe       No Command
Info_USer                      INFO_TNJ             INFO_TNJ             pmrepagent.exe       No Command
Info_USer                      INFO_TNJ             INFO_TNJ             pmrepagent.exe       No Command
Info_USer                      INFO_TNJ             INFO_TNJ             pmrepagent.exe       No Command
Info_USer                       INFO_TNJ             INFO_TNJ             pmrepagent.exe       Select
Info_USer                      INFO_TNJ             INFO_TNJ             pmrepagent.exe       No Command
Info_USer                      INFO_TNJ             INFO_TNJ             pmrepagent.exe       No Command
Info_USer                      INFO_TNJ             INFO_TNJ             pmrepagent.exe       No Command
Info_USer                      INFO_TNJ             INFO_TNJ             pmrepagent.exe       No Command
Info_USer                      INFO_TNJ             INFO_TNJ             pmrepagent.exe       Select
Info_USer                      INFO_TNJ             INFO_TNJ             pmrepagent.exe       No Command
Info_USer                      INFO_TNJ             INFO_TNJ             pmrepagent.exe       No Command
Info_USer                      INFO_TNJ             INFO_TNJ             pmrepagent.exe       No Command
Info_USer                      INFO_TNJ             INFO_TNJ             pmrepagent.exe       No Command
Info_USer                      INFO_TNJ             INFO_TNJ             pmrepagent.exe       No Command
oracle                             DBSNMP               DBSNMP               emagent@uxsserv    No Command

18 rows selected. 
SQL>

No comments:

Post a Comment