Sunday, June 23, 2013

How To Identify Related DeadLock Sqls in LMD Trace file

After oracle db 11gR2, the dead lock sql information will be collected in LMD trace file for RAC
You will see such infor in alert logs

2013-05-17 13:00:45.065000 -05:00
Global Enqueue Services Deadlock detected. More info in file

/test/oradiag/diag/rdbms/testadc/test1/trace/test_lmd0_1825.trc

This trc file can be appended to record many days deadlock infor before db bounce

There are quite many infor in the trc file,quite a few sql in the trc. Sometimes you are confused by what are related sql for the deadlocks. If you are not checking carefully, you may end up put unrelated sql into your conclusions. here are important parts to look

Submitting asynchronized dump request [28]. summary=[ges process stack dump (kjdglblkrdm1)].
Global blockers dump end:-----------------------------------
Global Wait-For-Graph(WFG) at ddTS[0.6de0] :
BLOCKED 0x44ef30548 5 wq 2 cvtops x1 TX 0x200005.0x110998(ext 0x6,0x0)[7B000-0001-000006E1] inst 1
BLOCKER 0x45144f800 5 wq 1 cvtops x28 TX 0x200005.0x110998(ext 0x6,0x0)[7D000-0003-00000009] inst 3
BLOCKED 0x44e1a78a0 5 wq 2 cvtops x1 TX 0x10017.0x2ebd13(ext 0x1,0x0)[7D000-0003-00000009] inst 3
BLOCKER 0x45164caf0 5 wq 1 cvtops x28 TX 0x10017.0x2ebd13(ext 0x1,0x0)[8F000-0001-00000010] inst 1
BLOCKED 0x44ef308e8 5 wq 2 cvtops x1 TX 0x200005.0x110998(ext 0x6,0x0)[8F000-0001-00000010] inst 1
BLOCKER 0x44ef30548 5 wq 2 cvtops x1 TX 0x200005.0x110998(ext 0x6,0x0)[7B000-0001-000006E1] inst 1 



The 3rd column indicates it TX mode 5 lock
The last column indicates which rac node
 
search trc file for 0x44ef30548 0x45144f800 0x45164caf0 0x44ef308e8 
record the sql you find, they are related deadlock sql
Sometimes you will see same sql for all of the deadlocks. That's because you have many midtiers which are doing same job at the same time and may cause conflicts if applications are not well designed.

Wednesday, June 19, 2013

Oracle WebCenter Content Batch Monitor Sql

If you happen to use Oracle WebCenter Content and use it's replication technology , one of key monitors will be on indexer/archiver
The batch information of replication indicates usage pattern, ucm performace .....etc
A few sql to share how to monitor batches in Oracle WebCenter Content.
Obviously you can twist them with different time period.

How many batches per day

select count( distinct  substr(a.dbatchfile, 1, instr(a.dbatchfile, '/') - 1) ) num_batchfile  from archivehistory a where   dactiondate > sysdate - 1 

Total size of batches per day

select         sum(d.dfilesize)/1024/1024  totalsize_MB
  from archivehistory a, documents d
  where a.did = d.did
   and d.disprimary = 1
   and a.dactiondate > sysdate - 1

 Average size of batches per day

select
(
select  sum(d.dfilesize)/1024/1024  totalsize_MB
  from archivehistory a, documents d
  where a.did = d.did
   and d.disprimary = 1
   and a.dactiondate > sysdate - 1
   )
/
  (
   select count( distinct  substr(a.dbatchfile, 1, instr(a.dbatchfile, '/') - 1) ) num_batchfile  from archivehistory a where   dactiondate > sysdate - 1 
    )  avg_size_MB from dual 

Tuesday, June 18, 2013

How To Check RAC Interconnect is uing UDP or RDS

A simple to know is to use skgxpinfo  under CRS Home

CRS % skgxpinfo -v
Oracle RDS/IP (generic)

CRS % skgxpinfo -v
Oracle UDP/IP (generic)

Monday, June 17, 2013

A Sql to find Long Idle Sessions on DB

Just share a  sql below is about to find jdbc connections with idle for 8 days(28800/3600)

select username,sid,serial#, (sysdate - prev_exec_start)*24*3600 last_call_during  from v$session where program like '%JDBC%' and event ='SQL*Net message from client'
and  status = 'INACTIVE' and (sysdate - prev_exec_start)*24*3600 > 28800

Thursday, June 13, 2013

Listener Can't start Due to CRS Issue

Sometimes we can't start listeners, see this error in logs:

NL-08014: Failed to initialize Diagnosability framework, falling back to old network tracing/logging
 NL-08002: Diagnosability  context creation failed

its due to crs is not running fine.
shutdown crs, then we can start

Thursday, June 06, 2013

Some Examples of TCPDUMP

These are just examples of tcpdump for reference:

tcpdump -i bond0 -x -s0 -w tcp_dump.log host ldappool2.test.com

tcpdump dst host280-01.us.test.com and src not aderidde-lnx.us.test.com and src host-03 or src host15-03 or src host16-03 or src host03-03 or src host04-03 or src host05-03  -w  /admin/TCPDUMP_dst_host280-01

tcpdump dst host06.us.test.com

Tuesday, June 04, 2013

Examples To Get Definition of DB Objects

Normal DB objects we can get definition from  dbms_metadata.get_ddl():

SELECT dbms_metadata.get_ddl('FUNCTION', 'WHOAMI') FROM dual;

Tablespace
SELECT dbms_metadata.get_ddl('TABLESPACE', 'TEST_DATA') FROM dual;

select  dbms_metadata.get_ddl('INDEX','TEST') from dual;

 select  dbms_metadata.get_ddl('DB_LINK','TEST.COM') from dual;

 select  dbms_metadata.get_ddl('USER','TEST') from dual;

select  dbms_metadata.get_ddl('PROCEDURE','TEST_STRUCTURE') from dual;

select  dbms_metadata.get_ddl('FUNCTION','TEST_FUNC') from dual;

select  dbms_metadata.get_ddl('TABLE','TEST' ) from dual;


For  Oracle TEXT, we need to use specific package:
set long 500000
set pages 999
select ctx_report.create_index_script('FT_TESTTEXT2') from dual;

set long 50000
set pages 9999
select dbms_metadata.get_ddl('TABLE', 'DR$FT_TESTTEXT2MI') from dual;
select dbms_metadata.get_ddl('TABLE', 'DR$FT_TESTTEXT2$I') from dual;

Monday, June 03, 2013

How To Run Oracle Text Query From Sqlplus

Sometimes we need to debug some Text queries, we need to run them on sqlplus
Here are some examples:

set serveroutput on;
 ALTER SESSION SET EVENTS '30579 trace name context forever, level 2';

 declare
 text_result clob;
 begin
dbms_lob.createtemporary(text_result, true, DBMS_LOB.CALL);
 ctx_query.result_set('TEST_IDCTEXT2', 'computer',
 '<ctx_result_set_descriptor><count exact="false"/><group
 sdata="sdDrillDown"><count exact="true"/></group><hitlist start_hit_num="1"
 end_hit_num="2" order="dInDate Desc"><sdata name="dID"/><sdata
 name="sddDocName"/><rowid /></hitlist></ctx_result_set_descriptor>',
 text_result);
 dbms_output.put_line(dbms_lob.substr(text_result,200,1));
 dbms_output.put_line('hello');
 dbms_lob.freetemporary(text_result);
 end;
 /

SELECT DDOCNAME  FROM idctext2 WHERE CONTAINS(otsmeta,  '((((DEFINESCORE((henry), RELEVANCE * .01)) ))) * 10.0 * 10.0')>0;


SELECT DDOCNAME  FROM idctext2 WHERE CONTAINS(otsmeta,  '((((DEFINESCORE((test), RELEVANCE * .1)) )))  and  (((((EMPL%) WITHIN
dDocAccount)) or (((CATEST1%) WITHIN dDocAccount)) or (((GIT/GLOBAL#0023IT#0023ONLY%) WITHIN dDocAccount)) or (((GIT/ALL%) WITHIN dDocAccount)) or (((idcnull) WITHIN dDocAccount)))) ')>0;

Sunday, June 02, 2013

Check Flashback Space Usage

A simple sql to show the percentage

SELECT (CASE WHEN PERCENT_USED> 100 THEN 0 ELSE (100-PERCENT_USED) END) PERCENT_FREE
  FROM (SELECT (SUM(PERCENT_SPACE_USED)-SUM(PERCENT_SPACE_RECLAIMABLE)) PERCENT_USED
  FROM V$FLASH_RECOVERY_AREA_USAGE); 

How To Check Cardinality Of A Table

There are 2 db views you can get  cardinality  information
user_tab_col_statistics 
dba_tab_col_statistics 

Check Num_Distinct and Density

The "Density" = "Num_Distinct" / "Total Number of Rows"

Please also pay attention when is the last analyzed time in the view.

Add Hidden Init DB Parameters

You need to add double quote for the parameters. examples:

alter system set "_external_scn_logging_threshold_seconds"=600 scope=spfile sid='*'; 
alter system set "_external_scn_rejection_delta_threshold_minutes"=10080 scope=both sid='*';