Monday, January 23, 2012

TO GET SESSION ID AND SEE WHICH QUERY IS HITTING DB


select
   c.owner,
   c.object_name,
   c.object_type,
   b.sid,
   b.serial#,
   b.status,
   b.osuser,
   b.machine
from
   v$locked_object a ,
   v$session b,
   dba_objects c
where
   b.sid = a.session_id
and
   a.object_id = c.object_id;



select a.sid, a.serial#, b.sql_text
    from v$session a, v$sqlarea b
    where a.sql_address=b.address
   and a.username='RMI';

select a.sid, a.serial#,a.time_remaining,a.elapsed_seconds,b.sql_text,b.users_executing
    from v$session_longops a, v$sqlarea b
    where a.sql_address=b.address
   and a.username='RMI';

TO CHECK RECYCLEBINN SPACE


select r.owner,
 count(distinct r.original_name) orig_obj,
 count(distinct r.object_name) objects,
 sum(bytes)/1024 kb
from dba_recyclebin r
 join dba_segments s
 on (r.owner = s.owner and r.object_name = s.segment_name)
group by r.owner;

Steps to apply the WebLogic patch


>>Weblogic patch location:
/mnt/Stage11i/linux/11g_GRID-64-bit/Weblogic_patch/WDJ7

>> First run the following script to set the environment variables:
>> /u01/app/oracle/Middleware/wlserver_10.3/server/bin/setWLSEnv.sh

>> Go to directory:
>> /u01/app/oracle/Middleware/utils/bsu

>> Issue the command to apply the patch:
>> ./bsu.sh -prod_dir=/u01/app/oracle/Middleware/wlserver_10.3 -patchlist=WDJ7 -verbose -install -patch_download_dir=/mnt/Stage11i/linux/11g_GRID-64-bit/Weblogic_patch/WDJ7

>> Check the patching status:
>> ./bsu.sh -view -status=applied -prod_dir=/u01/app/oracle/Middleware/wlserver_10.3

Check Statistics Advisor Jobs Status


col owner format a20
col job_name format a30
col start_date format a30
select owner,JOB_NAME,START_DATE ,ENABLED,RUN_COUNT,STOP_ON_WINDOW_CLOSE FROM DBA_SCHEDULER_JOBS WHERE JOB_NAME ='AUTO_SPACE_ADVISOR_JOB';

select owner,JOB_NAME,START_DATE ,ENABLED,RUN_COUNT,STOP_ON_WINDOW_CLOSE FROM DBA_SCHEDULER_JOBS WHERE JOB_NAME ='GATHER_STATS_JOB';

for metadata expdp & impdp


take export of metadata of schema only using expdp

>expdp directory=exp_dp dumpfile=j.dmp content=metadata_only schemas=<schema_name>

after that create sqlfile using impdp -

>impdp directory=exp_dp dumpfile=j.dmp logfile=imp_j.log sqlfile=j.sql include=view

You can filter the views only like above, you can get everything in the schema as follows:

>impdp directory=exp_dp dumpfile=j.dmp logfile=imp_j.log sqlfile=j.sql

Tablespace usage


for table space
====================
                                                                                                                                                                                               
                                           
set line 100
set pagesize 40
column dummy noprint
column pct_used format 999.9 heading "%|Used"
column name format a23 heading "Tablespace Name"
column Mbytes format 999,999,999,999 heading "Total_MB"
column used format 999,999,999,999 heading "Used_MB"
column free format 999,999,999,999 heading "Free_MB"
break on report
compute sum of kbytes on report
compute sum of free on report
compute sum of used on report

select nvl(b.tablespace_name,nvl(a.tablespace_name,'UNKOWN'))
name,
Mbytes_alloc Mbytes,
Mbytes_alloc-nvl(Mbytes_free,0) used,
nvl(Mbytes_free,0) free,
((Mbytes_alloc-nvl(Mbytes_free,0))/Mbytes_alloc)*100
pct_used
from ( select sum(bytes)/1024/1024 Mbytes_free,
tablespace_name
from sys.dba_free_space
group by tablespace_name ) a,
( select sum(bytes)/1024/1024 Mbytes_alloc,
tablespace_name
from sys.dba_data_files
group by tablespace_name )b
where a.tablespace_name (+) = b.tablespace_name
order by 4;



SELECT /* + RULE */  df.tablespace_name "Tablespace",
       df.bytes / (1024 * 1024) "Size (MB)",
       SUM(fs.bytes) / (1024 * 1024) "Free (MB)",
       Nvl(Round(SUM(fs.bytes) * 100 / df.bytes),1) "% Free",
       Round((df.bytes - SUM(fs.bytes)) * 100 / df.bytes) "% Used"
  FROM dba_free_space fs,
       (SELECT tablespace_name,SUM(bytes) bytes
          FROM dba_data_files
         GROUP BY tablespace_name) df
 WHERE fs.tablespace_name (+)  = df.tablespace_name
 GROUP BY df.tablespace_name,df.bytes
UNION ALL
SELECT /* + RULE */ df.tablespace_name tspace,
       fs.bytes / (1024 * 1024),
       SUM(df.bytes_free) / (1024 * 1024),
       Nvl(Round((SUM(fs.bytes) - df.bytes_used) * 100 / fs.bytes), 1),
       Round((SUM(fs.bytes) - df.bytes_free) * 100 / fs.bytes)
  FROM dba_temp_files fs,
       (SELECT tablespace_name,bytes_free,bytes_used
          FROM v$temp_space_header
         GROUP BY tablespace_name,bytes_free,bytes_used) df
 WHERE fs.tablespace_name (+)  = df.tablespace_name
 GROUP BY df.tablespace_name,fs.bytes,df.bytes_free,df.bytes_used
 ORDER BY 4 DESC;