Search This Blog

Total Pageviews

Thursday 17 May 2018

 Oracle Object Detail  ... 


Oracle objects info ..

alter session set nls_date_format='dd-mm-yyyy hh24:mi';
set linesize 300
col owner       for a15
col object_type for a15
col object_name for a30
col temporary  for a10
col generated  for a20
select owner,
       object_name,
    -- subobject_name,
    -- object_id,
    -- data_object_id,
       object_type,
       created,
       last_ddl_time,
    -- timestamp,
       status,
       temporary,
       generated,
       secondary,
    -- namespace,
       edition_name
from   dba_objects
where  upper(object_name) like upper('%&OBJECT_NAME%')
order by owner, object_name;




alter session set nls_date_format='dd-mm-yyyy hh24:mi';
set linesize 300 pagesize 300 
col owner       for a15
col object_type for a15
col object_name for a30
col temporary  for a10
col generated  for a20
select owner,
       object_name,
    -- subobject_name,
    -- object_id,
    -- data_object_id,
       object_type,
       created,
       last_ddl_time,
    -- timestamp,
       status,
       temporary,
       generated,
       secondary,
    -- namespace,
       edition_name
from   dba_objects
where 1=1   
and last_ddl_time > sysdate -1   ---- last one day

order by owner, object_name;



compile the objects ...


alter session set nls_date_format='dd-mm-yyyy hh24:mi';
set pagesize 300 linesize 300 
col info for a80
select
decode( object_type, 'PACKAGE BODY',
'alter package ' || OWNER||'.'||OBJECT_NAME || ' compile body;',
'alter ' || OBJECT_TYPE || ' ' || OWNER||'.'||OBJECT_NAME || ' compile;' ) info ,
'-- ', status,created,last_ddl_time
from dba_objects a
where 1=1
and STATUS = 'INVALID' 
and OBJECT_TYPE in ( 'PACKAGE BODY', 'PACKAGE', 'FUNCTION', 'PROCEDURE','TRIGGER', 'VIEW' )
and owner not in ( 'SYS' , 'SYSTEM' , 'DBSNMP' , 'SYSMAN' , 'OUTLN' , 'MDSYS' , 'ORDSYS' , 'EXFSYS' , 'DMSYS' , 'WMSYS' , 'CTXSYS' , 'ANONYMOUS' , 'XDB' , 'ORDPLUGINS' , 'OLAPSYS' , 'PUBLIC','WWV_FLOW_PLATFORM' )
order by object_type,object_name;



Object with TableSpace 

set pagesize 300 linesize 150
col owner   for a25
col object_name  for a30
col SEGMENT_NAME for a25
select object_name,o.owner,tablespace_name ,o.object_type, o.status,count(*) from dba_objects o,dba_segments s
where 1=1
-- and STATUS='INVALID' 
--and o.OWNER='OWNER'
and s.segment_name = o.object_name 
and s.segment_type = o.object_type 
and s.owner = o.owner
 and  upper(object_name) like upper('%&OBJECT_NAME%')
group by object_name,o.owner,o.object_type, o.status ,tablespace_name 
order by owner
/

OBJECT_NAME                    OWNER                     TABLESPACE_NAME                OBJECT_TYPE             STATUS    COUNT(*)
------------------------------ ------------------------- ------------------------------ ----------------------- ------- ----------
EMP                            ANUJ                      TEST                           TABLE                   VALID            1
EMP                            ANUJ1                     USERS                          TABLE                   VALID            1
PK_EMP                         ANUJ1                     USERS                          INDEX                   VALID            1
EMP                            ANUJ10                    USERS                          TABLE                   VALID            1
PK_EMP                         ANUJ10                    USERS                          INDEX                   VALID            1
EMP                            ANUJ3                     USERS                          TABLE                   VALID            1





set linesize 500 pagesize 300
col OWNER for a20
col OBJECT_NAME  for a20
col stime for a27
select u.name as owner, o.name as object_name, 
 decode(o.type#, 0, 'NEXT OBJECT', 1, 'INDEX', 2, 'TABLE', 3, 'CLUSTER',
 4, 'VIEW', 5, 'SYNONYM', 6, 'SEQUENCE',
 7, 'PROCEDURE', 8, 'FUNCTION', 9, 'PACKAGE',
 11, 'PACKAGE BODY', 12, 'TRIGGER',
 13, 'TYPE', 14, 'TYPE BODY',
 19, 'TABLE PARTITION', 20, 'INDEX PARTITION', 21, 'LOB',
 22, 'LIBRARY', 23, 'DIRECTORY', 24, 'QUEUE',
 28, 'JAVA SOURCE', 29, 'JAVA CLASS', 30, 'JAVA RESOURCE',
 32, 'INDEXTYPE', 33, 'OPERATOR',
 34, 'TABLE SUBPARTITION', 35, 'INDEX SUBPARTITION',
 39, 'LOB PARTITION', 40, 'LOB SUBPARTITION',
 43, 'DIMENSION',
 44, 'CONTEXT', 47, 'RESOURCE PLAN',
 48, 'CONSUMER GROUP',
 51, 'SUBSCRIPTION', 52, 'LOCATION', 56, 'JAVA DATA', 'UNKNOWN') as type,
o.ctime, o.mtime,
 to_char(o.stime, 'DD-MM-YYYY HH24:MI:SS') stime,
 decode(o.status, 0, 'N/A', 1, 'VALID', 'INVALID') as status
 from sys.obj$ o, sys.user$ u
 where o.owner# = u.user#
 and o.linkname is null
 and (o.type# not in (1 , 10) or
 (o.type# = 1 and 1 = (select 1 from sys.ind$ i
 where i.obj# = o.obj#
 and i.type# in (1, 2, 3, 4, 6, 7, 9))))
 --and O.NAME like  '%Queue%'
 ;

Tuesday 8 May 2018

Kill session in AWS Oracle Database

Kill session in AWS Oracle Database ... 



Oracle AWS RDS kill session
connections on an RDS Oracle DB
Kill session in AWS Oracle Database

[oracle@rac01 ~]$ sqlplus 'vihaan@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=************.compute.amazonaws.com)(Port=1521))(CONNECT_DATA=(SID=orcl)))'

SQL*Plus: Release 12.2.0.1.0 Production on Sat May 5 14:58:57 2018

Copyright (c) 1982, 2016, Oracle. All rights reserved.

Enter password:

SQL>

*******************************************
This Will NOT work !!!!!!!!
set linesize 200 pagesize 300 
col kill for a70
select 'alter system kill session '''||sid||','||serial#||',@'||inst_id||''' immediate ;' kill,username,sql_id from gv$session 
where 1=1
-- and username='username'
-- and status = 'INACTIVE'
and type != 'BACKGROUND';
      
*********************************************

select LOGINS from V$INSTANCE;
 
we need to use this pakage rdsadmin.rdsadmin_util to kill session in oracle aws rds
 
exec rdsadmin.rdsadmin_util.kill(627,35083);
 

select SID, SERIAL#, STATUS,username from V$SESSION where STATUS='INACTIVE';

 SID SERIAL# STATUS USERNAME
---------- ---------- -------- ------------------------------
 40 61773 INACTIVE RDSADMIN
  

SQL> select SID, SERIAL#, STATUS,username from V$SESSION where STATUS='INACTIVE';

 SID SERIAL# STATUS USERNAME
---------- ---------- -------- ------------------------------
 40 61773 INACTIVE RDSADMIN

SQL> exec rdsadmin.rdsadmin_util.kill(40,61773);

PL/SQL procedure successfully completed.

SQL>
   

set linesize 200 pagesize 300
sql> select sid, serial#, status,username from v$session where status='INACTIVE';

 SID SERIAL# STATUS USERNAME
---------- ---------- -------- ------------------------------
 40 61773 INACTIVE RDSADMIN

SQL> exec rdsadmin.rdsadmin_util.kill(40,61773);

PL/SQL procedure successfully completed.
 
 

begin
 rdsadmin.rdsadmin_util.kill(
 sid => &sid, 
 serial => &serial_number,
 method => 'IMMEDIATE');
end;
/

SQL> exec rdsadmin.rdsadmin_util.kill(40,61777,'IMMEDIATE');

PL/SQL procedure successfully completed.


to Kill session !
begin
 rdsadmin.rdsadmin_util.kill(
 sid => &sid, 
 serial => &serial_number,
 method => 'IMMEDIATE');
end;
/

Via Script 

set linesize 200 pagesize 300
col kill for a70
select 'exec rdsadmin.rdsadmin_util.kill('|| sid ||',' || serial# || ');' kill from v$session where username in ('&Username'); 


-- session with Immediate !!!

set linesize 200 pagesize 300
select 'exec rdsadmin.rdsadmin_util.kill('||s.sid||','||s.serial#||', ''IMMEDIATE'''||');' kill , ' -- ',username ,status,blocking_session,state,final_blocking_session,sql_id
from v$session s
where 1=1 
-- and username = upper('')
 and STATUS != 'ACTIVE'
 and s.Type != 'BACKGROUND';
 
 
KILL '--' USERNAME STATUS BLOCKING_SESSION STATE FINAL_BLOCKING_SESSION SQL_ID
---------------------------------------------------------------------- ---- -------------------- -------- ---------------- ------------------- ---------------------- -------------
exec rdsadmin.rdsadmin_util.kill(40,61783, 'IMMEDIATE'); -- RDSADMIN INACTIVE WAITING

 
SQL> SQL> exec rdsadmin.rdsadmin_util.kill(40,61783, 'IMMEDIATE');

PL/SQL procedure successfully completed.



set linesize 300 
col username for a20
select 
'exec rdsadmin.rdsadmin_util.kill('||s.sid||','||s.serial#||', ''IMMEDIATE'''||');' kill ,
 ' -- ',
 s.inst_id,
 -- s.sid,
 -- s.serial#,
 p.spid,
 s.username,
 s.program,
 s.sql_id
 from gv$session s, gv$process p
 where 1=1 
 and p.addr = s.paddr 
 and p.inst_id = s.inst_id
and s.type != 'BACKGROUND' ;

KILL '--' INST_ID SPID USERNAME PROGRAM SQL_ID
---------------------------------------------------------------------- ---- ---------- ------------------------ -------------------- ------------------------------------------------ -------------
exec rdsadmin.rdsadmin_util.kill(40,61783, 'IMMEDIATE'); -- 1 27035 RDSADMIN JDBC Thin Client
exec rdsadmin.rdsadmin_util.kill(21,62867, 'IMMEDIATE'); -- 1 23889 VIHAAN sqlplus@rac01.*****.net (TNS V1-V3) 6v5f6v3upz5mu

Oracle DBA

anuj blog Archive