Pavan DBA's Blog

The DBA Knowledge Store

Archive for the ‘Scripts’ Category

Script to list events in Oracle Database

Posted by Pavan DBA on August 23, 2012


Friends, many a times we will be setting events traces in our databases for various reasons. The below script will give advantage to know what are all the events turned on in our database

Listing All Events

Most events are numbered in the range 10000 to 10999. To dump all event messages in this range use

    SET SERVEROUTPUT ON
   
    DECLARE
      err_msg VARCHAR2(120);
    BEGIN
      dbms_output.enable (1000000);
      FOR err_num IN 10000..10999
      LOOP
        err_msg := SQLERRM (-err_num);
        IF err_msg NOT LIKE ‘%Message ‘||err_num||’ not found%’ THEN
          dbms_output.put_line (err_msg);
        END IF;
      END LOOP;
    END;
    /

On Unix systems event messages are in the formatted text file

    $ORACLE_HOME/rdbms/mesg/oraus.msg

To print detailed event messages (Unix only) use the following script

    event=10000
    while [ $event -ne 10999 ]
    do
        event=`expr $event + 1`
        oerr ora $event
    done

Listing Enabled Events

To check which events are enabled in the current session

    SET SERVEROUTPUT ON
    DECLARE
        l_level NUMBER;
    BEGIN
        FOR l_event IN 10000..10999
        LOOP
            dbms_system.read_ev (l_event,l_level);
            IF l_level > 0 THEN
                dbms_output.put_line (‘Event ‘||TO_CHAR (l_event)||
                ‘ is set at level ‘||TO_CHAR (l_level));
            END IF;
        END LOOP;
    END;
    /

Posted in Performance Tuning, Scripts | Tagged: , , | Leave a Comment »

script to analyze Disk IO’s

Posted by Pavan DBA on July 1, 2012


To Analyze the DISK I/o’s

==========================

 

prompt SESSIONS PERFORMING HIGH I/O > 50000

select p.spid, s.sid,s.process cli_process, s.status,t.disk_reads, s.last_call_et/3600 last_call_et_Hrs,
s.action,s.program,lpad(t.sql_text,30) “Last SQL”
from v$session s, v$sqlarea t,v$process p
where s.sql_address =t.address and
s.sql_hash_value =t.hash_value and
p.addr=s.paddr and
t.disk_reads > 10000
order by t.disk_reads desc;

Posted in Performance Tuning, Scripts | Tagged: | Leave a Comment »

script to check INACTIVE sessions with HIGH DISK IO

Posted by Pavan DBA on July 1, 2012


To check INACTIVE sessions with HIGH DISK IO

=============================================

select p.spid,s.username, s.sid,s.status,t.disk_reads, s.last_call_et/3600 last_call_et_Hrs,
s.action,s.program,s.machine cli_mach,s.process cli_process,lpad(t.sql_text,30) “Last SQL”
from gv$session s, gv$sqlarea t,v$process p
where s.sql_address =t.address and
s.sql_hash_value =t.hash_value and
p.addr=s.paddr and
t.disk_reads > 5000
and s.status=’INACTIVE’
and s.process=’1234′
order by S.PROGRAM;

Posted in Performance Tuning, Scripts | Tagged: , | Leave a Comment »

script to check tablespace free space for all db’s in server

Posted by Pavan DBA on May 24, 2012


***************************************************
script to check tablespace free space for all db’s in server
***************************************************

#!/bin/csh

setenv ORATAB /var/opt/oracle/oratab
foreach x (`cat ${ORATAB} | grep -v “^#”| grep “^[a-z]” | grep -v “demo” |grep -v _sp | grep -v “test”| awk -F:

‘{print $1}’`)
        setenv ORAENV_ASK 1
        setenv ORACLE_SID “$x”
        source /usr/local/default/oracle_sid.csh
            sqlplus -s <<EOF
        / as sysdba
col total_space format 999,999,999,999
col free_space format 999,999,999,999
col pct_used format 999.99
col value new_value sid
set termout off
set head off
select value from v\$parameter where name=’db_name’;
set termout on
ttitle sid ” – Tablespaces Free space information” skip 2

set head on
set lines 234
set pages 100

SELECT /* + RULE */  df.tablespace_name “Tablespace”,
       df.bytes / (1024 * 1024) “Size (MB)”,
       round(SUM(fs.bytes) / (1024 * 1024)) “Free (MB)”,
       Nvl(Round(SUM(fs.bytes) * 100 / df.bytes),1) “% Free”,
       Round((df.bytes – SUM(fs.bytes)) / 1024/1024) “Used space”,
       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
 order by  “% Used” desc
/
        exit
EOF
end

Note: This script is written in C shell. Do make changes if you are using other shell. Also, test it before…

Posted in Administration, Scripts | Tagged: | 4 Comments »

script to get row count of all tables in a schema

Posted by Pavan DBA on May 24, 2012


***************************************************
script to get row count of all tables in a schema
***************************************************
#!/bin/csh

            sqlplus -s <<EOF
username/password  
spool tablecount.log
select
      table_name,
      to_number(
        extractvalue(
          xmltype(dbms_xmlgen.getxml(‘select count(*) c from ‘||table_name))
          ,’/ROWSET/ROW/C’)
          )
          count
    from user_tables order by table_name;
spool off
        exit
EOF

Note: This script is written in C shell. Do necessary changes if you are using any other shell. Do test it before executing in prod env’s

Posted in Administration, Scripts | Tagged: | Leave a Comment »

 
%d bloggers like this: