Pavan DBA's Blog

The DBA Knowledge Store

Archive for the ‘Scripts’ Category

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: | 2 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 »

script to check db status in rac env

Posted by Pavan DBA on May 24, 2012

***************************************************
script to check db status in rac env
***************************************************

#!/bin/csh

setenv ORATAB /var/opt/oracle/oratab
date
foreach x (`cat ${ORATAB} | grep -v “^#”| grep “^[a-z]” | grep -v “demo” | grep -v “_sp”|awk -F: ‘{print $1}’`)
        setenv ORAENV_ASK 1
        setenv ORACLE_SID “$x”
        source /usr/local/default/oracle_sid.csh
            $ORACLE_HOME/bin/sqlplus -s <<EOF
        / as sysdba
        set lines 132
        set pages 200
            set hea off
        set feedback off
        col machine for a30
        col host_name for a40
        select instance_name, host_name, logins, status from gv\$instance;
        exit
EOF
end

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

script to check db status in a server

Posted by Pavan DBA on May 24, 2012

***************************************************
script to check db status in a server
***************************************************

#!/bin/csh

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

‘{print $1}’`)
        setenv ORAENV_ASK 1
        setenv ORACLE_SID “$x”
        source /usr/local/default/oracle_sid.csh
            sqlplus -s <<EOF
        / as sysdba
        set lines 132 pages 200 hea off feedback off trims on
        col host_name for a20
                spool chk_dbstatus.log
        select instance_name, host_name, logins, version, status from v\$instance;
                spool off
        exit
EOF

Note: The above script is written using “C” shell, so if you are using any other shell, make necessary changes. Also as always first test it in lower environments

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

script to find redo generated by current sessions

Posted by Pavan DBA on March 30, 2012

#################################################

redo generated by current sessions

#################################################

 

select v$session.sid, username, value redo_size

from v$sesstat, v$statname, v$session

where v$sesstat.STATISTIC# = v$statname.STATISTIC#

and v$session.sid = v$sesstat.sid

and name = ‘redo size’

and value > 0

and username is not null

order by value

/

Posted in Performance Tuning, Scripts | Tagged: , , | 10 Comments »

 
Follow

Get every new post delivered to your Inbox.

Join 1,477 other followers