User Tools

Site Tools


database_status

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
database_status [2018/12/06 21:05] – created 91.177.234.129database_status [2025/03/11 11:46] (current) – external edit 127.0.0.1
Line 1: Line 1:
-====== Database_Status ====== +  *  [[https://www.doag.org/formes/pubfiles/9199370/2017-NN-Frits_Hoogland-Who_shut_my_database_down__A_security_post_mortem_-Praesentation.pdf|Who shutdown my database - Frits Hoogland]] 
- +  * [[https://fritshoogland.wordpress.com/wp-content/uploads/2010/01/oracle-security-done-right.pdf|Secure Oracle database access on the (unix and linux) operating system level.]] 
-=====Check datafiles for their recovery status (compared with what is in the controlfile)=====+==== Show database resource limits and current usage ==== 
 +<code> 
 +set lines 1000 pages 100 
 +select resource_name 
 +,      current_utilization 
 +,      max_utilization 
 +,      limit_value 
 +from   v$resource_limit 
 +
 +</code> 
 +==== Check datafiles for their recovery status (compared with what is in the controlfile) ====
 Depending on how the database was last shut down (or recovered), this will show if data files are to of sync with the control file. Depending on how the database was last shut down (or recovered), this will show if data files are to of sync with the control file.
-<code>0@@</code>+<code> 
 +set lines 1000 pages 100 numwidth 15 
 +col name for a60 
 +col stats for a6 
 +col datafile_status for a18 
 +select 
 +a.name 
 +,a.status 
 +,a.file# 
 +,a.checkpoint_change# control_file_SCN 
 +,b.checkpoint_change# datafile_SCN 
 +,case 
 +when ((a.checkpoint_change# - b.checkpoint_change#) = 0) THEN 'Startup Normal' 
 +when ((b.checkpoint_change#) = 0) THEN 'File Missing?' 
 +when ((a.checkpoint_change# - b.checkpoint_change#) > 0) THEN 'Media Rec. Req.' 
 +when ((a.checkpoint_change# - b.checkpoint_change#) < 0) THEN 'Old Control File' 
 +else 'what the ?' 
 +end datafile_status 
 +from v$datafile a        -- control file SCN for datafile 
 +    ,v$datafile_header b -- datafile header SCN 
 +where a.file# = b.file# 
 +order by a.file# 
 +
 + 
 +</code>
  
-=====How to stop and start a database on a Solaris Veritas cluster=====+==== How to stop and start a database on a Solaris Veritas cluster ====
 Using command line... Using command line...
-<code>1@@</code>+<code> 
 +Cluster logfile\t\t/var/VRTSvcs/log/engine_A.log 
 +Cluster status\t\thastatus -sum 
 +Clear failed resource\thares -clear $SID_ORA -sys $host  
 +Start database\t\thares -online $SID_ORA -sys $host  
 +Start listener\t\thares -online $SID_LSNR -sys $host 
 +</code>
 or using a script... or using a script...
-<code>2@@</code+<code> 
-*[[Tablespaces]]+cat cluster_database.ksh start|stop <SID
 +  - !/bin/ksh 
 +  - set -x
  
-=====Following a database crash...===== +database=$2 
-Check the status of the datafiles and tablespaces. They might need recovering.<br />+PATH=$PATH:/opt/VRTSvcs/bin 
 +export PATH 
 +DATUM=`date +%Y%m%d` 
 +LOGFILE="/oracle/logs/cluster_scripts.${DATUM}.log" 
 +typeset -i count 
 +typeset -i seconds 
 +count=1 
 +seconds=0 
 + 
 +echo "`date +%Y%m%d-%H%M`: we will $1 database ${database}" | tee -a ${LOGFILE} 
 +          - #################################################################### 
 +  -  Run this script as root to stop/start Oracle database incl. listeners # 
 +          - #################################################################### 
 +  -  
 +case $1 in 
 +start) 
 +        #system=`hares -value ${database}_ORA LastOnline` 
 +        #if [[ -z "${system}" ]] 
 +        #then 
 +                #system=`uname -n` 
 +        #fi 
 +        diskgroup="`echo $database | tr [[A-Z]] [[a-z]]`dg" 
 +        system=`hares -state ${diskgroup} | grep ONLINE | nawk '{print $3}'
 +        if [[ -z "${system}" ]] 
 +        then 
 +                echo "resource group ${database} has not been started on any system in the cluster. Please request administrator to start resourcegroup" | tee -a ${LOGFILE} 
 +        fi 
 +        status=`hares -state ${database}_ORA -sys ${system} | nawk '{print $NF}'
 +        if [[ "${status}" = "FAULTED" ]] 
 +        then 
 +                echo "`date +%Y%m%d-%H%M`: Clearing faulted resource ${database}_ORA on system ${system}" | tee -a ${LOGFILE} 
 +                hares -clear ${database}_ORA -sys ${system} 2>&1 | tee -a ${LOGFILE} 
 +        fi 
 +        echo "`date +%Y%m%d-%H%M`: Onlining resource ${database}_ORA on system ${system}"  | tee -a ${LOGFILE} 
 +        hares -online ${database}_ORA -sys ${system} 2>&1 | tee -a ${LOGFILE} 
 +        sleep 5 
 +        temp=`hares -state ${database}_ORA | grep ONLINE | nawk '{print $3}'
 +        while [[ -z "${temp}" ]] 
 +        do 
 +                seconds=count*5 
 +                echo "`date +%Y%m%d-%H%M`: Database resource ${database}_ORA not yet online after ${seconds} seconds" | tee -a ${LOGFILE} 
 +                echo "`date +%Y%m%d-%H%M`: Status of resource ${database}_ORA" | tee -a ${LOGFILE} 
 +                hares -state ${database}_ORA 2>&1 | tee -a ${LOGFILE} 
 +                if [[ $seconds -gt 300 ]] 
 +                then 
 +                        echo "`date +%Y%m%d-%H%M`: Database resource ${database}_ORA still not online after ${seconds} seconds. We are exiting the script. Please check the Oracle alert log" | tee -a ${LOGFILE} 
 +                        exit 1 
 +                fi 
 +                sleep 5 
 +                temp=`hares -state ${database}_ORA | grep ONLINE | nawk '{print $3}'
 +                count=count+1 
 +        done 
 +        echo "`date +%Y%m%d-%H%M`: Database Resource ${database}_ORA is online on system ${system}" | tee -a ${LOGFILE} 
 +        system=`hares -value ${database}_LSNR LastOnline` 
 +        if [[ "${status}" = "FAULTED" ]] 
 +        then 
 +                echo "`date +%Y%m%d-%H%M`: Clearing faulted resource ${database}_LSNR on system ${system}" | tee -a ${LOGFILE} 
 +                hares -clear ${database}_LSNR -sys ${system} 
 +        fi 
 +        echo "`date +%Y%m%d-%H%M`: Onlining resource ${database}_LSNR on system ${system}"  | tee -a ${LOGFILE} 
 +        hares -online ${database}_LSNR -sys ${system} 2>&1 | tee -a ${LOGFILE} 
 +        count=1 
 +        sleep 5 
 +        temp=`hares -state ${database}_LSNR | grep ONLINE | nawk '{print $3}'
 +        while [[ -z "${temp}" ]] 
 +        do 
 +                seconds=count*5 
 +                echo "`date +%Y%m%d-%H%M`: Listener resource ${database}_LSNR not yet online after ${seconds} seconds" | tee -a ${LOGFILE} 
 +                echo "`date +%Y%m%d-%H%M`: Status of resource ${database}_LSNR" | tee -a ${LOGFILE} 
 +                hares -state ${database}_LSNR 2>&1 | tee -a ${LOGFILE} 
 +                if [[ $seconds -gt 300 ]] 
 +                then 
 +                        echo "`date +%Y%m%d-%H%M`: Listener resource ${database}_LSNR still not online after ${seconds} seconds. We are exiting the script. Please check the Listener alert log" | tee -a ${LOGFILE} 
 +                        exit 1 
 +                fi 
 +                sleep 5 
 +                temp=`hares -state ${database}_LSNR | grep ONLINE | nawk '{print $3}'
 +                count=count+1 
 +        done 
 +        echo "`date +%Y%m%d-%H%M`: Listener Resource ${database}_LSNR is online on system ${system}" | tee -a ${LOGFILE} 
 +        resources=`hares -dep | grep "${database}_LSNR$" | nawk '{print $2}'
 +        for res in ${resources} 
 +        do 
 +                echo "`date +%Y%m%d-%H%M`: Onlining resource ${res} on system ${system}" | tee -a ${LOGFILE} 
 +                hares -online ${res} -sys ${system} 
 +                sleep 5 
 +                echo "`date +%Y%m%d-%H%M`: Status of resource ${res}"  | tee -a ${LOGFILE} 
 +                hares -state ${res} 2>&1 | tee -a ${LOGFILE} 
 +        done 
 +        ;; 
 +stop) 
 +        typeset -i count 
 +        count=0 
 +        resources=`hares -dep | grep "${database}_LSNR$" | nawk '{print $2}'
 +        for res in ${resources} 
 +        do 
 +                echo "`date +%Y%m%d-%H%M`: Offlining resource ${res} on system ${system} which depends on resource ${database}_LSNR" | tee -a ${LOGFILE} 
 +                system=`hares -state ${res} | grep ONLINE | nawk '{print $3}'
 +                if [[ -n "${system}" ]] 
 +                then 
 +                        hares -offline ${res} -sys ${system} 2>&1 | tee -a ${LOGFILE} 
 +                fi 
 +                sleep 5 
 +                temp=`hares -state ${res} | tail +2 | grep -v OFFLINE | grep -v FAULTED | nawk '{print $3}'
 +                count=1 
 +                while [[ -n "${temp}" ]] 
 +                do 
 +                        seconds=count*5 
 +                        echo "`date +%Y%m%d-%H%M`: resource ${res} not yet offline after ${seconds} seconds" | tee -a ${LOGFILE} 
 +                        echo "`date +%Y%m%d-%H%M`: Status of resource ${res}" | tee -a ${LOGFILE} 
 +                        hares -state ${res} 2>&1 | tee -a ${LOGFILE} 
 +                        if [[ $seconds -gt 300 ]] 
 +                        then 
 +                                echo "`date +%Y%m%d-%H%M`: resource ${res} still not offline after ${seconds} seconds. We are exiting the script. Please check the alert log" | tee -a ${LOGFILE} 
 +                                exit 1 
 +                        fi 
 +                        sleep 5 
 +                        count=count+1 
 +                        temp=`hares -state ${res} | tail +2 | grep -v OFFLINE | grep -v FAULTED | nawk '{print$3}'
 +                done 
 +                FAULTED=`hares -state ${res} | grep FAULTED | nawk '{print $3}'
 +                if [[ -n "${FAULTED}" ]] 
 +                then 
 +                        hares -clear ${res} -sys ${system} 2>&1 | tee -a ${LOGFILE} 
 +                fi 
 +                echo "`date +%Y%m%d-%H%M`: Resource ${res} is offline on system ${system}" | tee -a ${LOGFILE} 
 +        done 
 + 
 +        system=`hares -state ${database}_LSNR | grep ONLINE | nawk '{print$3}'
 +        if [[ -n "${system}" ]] 
 +        then 
 +                echo "`date +%Y%m%d-%H%M`: Stopping ${database}_LSNR on ${system}" | tee -a ${LOGFILE} 
 +                hares -offline ${database}_LSNR -sys ${system} 2>&1 | tee -a ${LOGFILE} 
 +        fi 
 +        sleep 5 
 +        count=1 
 +        temp=`hares -state ${database}_LSNR | tail +2 | grep -v OFFLINE | grep -v FAULTED | nawk '{print$3}'
 +        while [[ -n "${temp}" ]] 
 +        do 
 +                seconds=count*5 
 +                echo "`date +%Y%m%d-%H%M`: Listener resource ${database}_LSNR not yet offline after ${seconds} seconds" | tee -a ${LOGFILE} 
 +                echo "`date +%Y%m%d-%H%M`: Status of resource ${database}_LSNR" | tee -a ${LOGFILE} 
 +                hares -state ${database}_LSNR 2>&1 | tee -a ${LOGFILE} 
 +                if [[ $seconds -gt 300 ]] 
 +                then 
 +                        echo "`date +%Y%m%d-%H%M`: Listener resource ${database}_LSNR still not offline after ${seconds} seconds. We are exiting the script. Please check the listener alert log" | tee -a ${LOGFILE} 
 +                        exit 1 
 +                fi 
 +                sleep 5 
 +                count=count+1 
 +                temp=`hares -state ${database}_LSNR | tail +2 | grep -v OFFLINE | grep -v FAULTED | nawk '{print$3}'
 +        done 
 +        echo "`date +%Y%m%d-%H%M`: Listener Resource ${database}_LSNR is offline on system ${system}" | tee -a ${LOGFILE} 
 +        system=`hares -state ${database}_ORA | grep ONLINE | nawk '{print$3}'
 +        if [[ -n "${system}" ]] 
 +        then 
 +                echo "`date +%Y%m%d-%H%M`: Stopping ${database}_ORA on ${system}" | tee -a ${LOGFILE} 
 +                hares -offline ${database}_ORA -sys ${system} 2>&1 | tee -a ${LOGFILE} 
 +        fi 
 +        sleep 5 
 +        count=1 
 +        temp=`hares -state ${database}_ORA | tail +2 | grep -v OFFLINE | grep -v FAULTED | nawk '{print$3}'
 +        while [[ -n "${temp}" ]] 
 +        do 
 +                seconds=count*5 
 +                echo "`date +%Y%m%d-%H%M`: Database resource ${database}_ORA not yet offline after ${seconds} seconds" | tee -a ${LOGFILE} 
 +                echo "`date +%Y%m%d-%H%M`: Status of resource ${database}_ORA" | tee -a ${LOGFILE} 
 +                hares -state ${database}_ORA 2>&1 | tee -a ${LOGFILE} 
 +                if [[ $seconds -gt 300 ]] 
 +                then 
 +                        echo "`date +%Y%m%d-%H%M`: Database resource ${database}_ORA still not offline after ${seconds} seconds. We are exiting the script. Please check the database alert log" | tee -a ${LOGFILE} 
 +                        exit 1 
 +                fi 
 +                sleep 5 
 +                count=count+1 
 +                temp=`hares -state ${database}_ORA | tail +2 | grep -v OFFLINE | grep -v FAULTED | nawk '{print$3}'
 +        done 
 +        echo "`date +%Y%m%d-%H%M`: Database Resource ${database}_ORA is offline on system ${system}" | tee -a ${LOGFILE} 
 + 
 +        ;; 
 +esac 
 +</code> 
 +  * [[Tablespaces]] 
 + 
 +==== Following a database crash... ==== 
 +Check the status of the datafiles and tablespaces. They might need recovering.
 Restarted and checked alert log. datafile 6 was in RECOVER status Restarted and checked alert log. datafile 6 was in RECOVER status
-<code>3@@</code>+<code> 
 + 
 +SQL> recover datafile 6; 
 + 
 + 
 +Checked dba_datafiles. File is now in OFFLINE status 
 + 
 +SQL> alter database datafile 6 online; 
 + 
 +... 
 +Errors in file e:\\oracle\\product\\admin\\arisppmp\\bdump\\arisppmp_lgwr_5104.trc: 
 +ORA-00494: enqueue [[CF]] held for too long (more than 900 seconds) by 'inst 1, osid 4956' 
 + 
 +Wed Apr 30 02:35:29 2014 
 +System State dumped to trace file e:\\oracle\\product\\admin\\arisppmp\\bdump\\arisppmp_lgwr_5104.trc 
 +Wed Apr 30 02:35:30 2014 
 +Errors in file e:\\oracle\\product\\admin\\arisppmp\\udump\\arisppmp_ora_13032.trc: 
 +ORA-00603: ORACLE server session terminated by fatal error 
 +ORA-00376: file 6 cannot be read at this time 
 +ORA-01110: data file 6: 'G:\\ORADATA\\ARISPPMP\\ARISPPMP01.DBF' 
 +ORA-00376: file 6 cannot be read at this time 
 +ORA-01110: data file 6: 'G:\\ORADATA\\ARISPPMP\\ARISPPMP01.DBF' 
 + 
 +Killing enqueue blocker (pid=4956) on resource CF-00000000-00000000 
 + by killing session 167.1 
 +Wed Apr 30 02:35:38 2014 
 +Errors in file e:\\oracle\\product\\admin\\arisppmp\\bdump\\arisppmp_dbw0_4956.trc: 
 + 
 +Wed Apr 30 02:40:30 2014 
 +Errors in file e:\\oracle\\product\\admin\\arisppmp\\bdump\\arisppmp_lgwr_5104.trc: 
 +ORA-00494: enqueue [[CF]] held for too long (more than 900 seconds) by 'inst 1, osid 4956' 
 + 
 +Wed Apr 30 02:40:30 2014 
 +System State dumped to trace file e:\\oracle\\product\\admin\\arisppmp\\bdump\\arisppmp_lgwr_5104.trc 
 +Killing enqueue blocker (pid=4956) on resource CF-00000000-00000000 
 + by terminating the process 
 +LGWR: terminating instance due to error 2103 
 +Wed Apr 30 02:40:32 2014 
 +Errors in file e:\\oracle\\product\\admin\\arisppmp\\bdump\\arisppmp_arc1_6920.trc: 
 +ORA-02103: PCC: inconsistent cursor cache (out-of-range cuc ref) 
 + 
 +Wed Apr 30 02:40:32 2014 
 +Errors in file e:\\oracle\\product\\admin\\arisppmp\\bdump\\arisppmp_arc0_6912.trc: 
 +ORA-02103: PCC: inconsistent cursor cache (out-of-range cuc ref) 
 + 
 +Wed Apr 30 02:40:33 2014 
 +Errors in file e:\\oracle\\product\\admin\\arisppmp\\bdump\\arisppmp_arc0_6912.trc: 
 +ORA-02103: PCC: inconsistent cursor cache (out-of-range cuc ref) 
 + 
 +Wed Apr 30 02:40:33 2014 
 +Master background archival failure: 2103 
 +Wed Apr 30 02:40:33 2014 
 +Errors in file e:\\oracle\\product\\admin\\arisppmp\\bdump\\arisppmp_psp0_4848.trc: 
 +ORA-02103: PCC: inconsistent cursor cache (out-of-range cuc ref) 
 + 
 +Wed Apr 30 02:40:33 2014 
 +Errors in file e:\\oracle\\product\\admin\\arisppmp\\bdump\\arisppmp_dbw2_5056.trc: 
 +ORA-02103: PCC: inconsistent cursor cache (out-of-range cuc ref) 
 + 
 +Wed Apr 30 02:40:35 2014 
 +Errors in file e:\\oracle\\product\\admin\\arisppmp\\bdump\\arisppmp_smon_5208.trc: 
 +ORA-02103: PCC: inconsistent cursor cache (out-of-range cuc ref) 
 + 
 +Wed Apr 30 02:40:36 2014 
 +Instance terminated by LGWR, pid = 5104 
 +... 
 +</code>
  
-=====How big is the database?=====+==== How big is the database? ====
 Calculate the total database size Calculate the total database size
-<code>4@@</code> +<code> 
-=====How big are the tablespaces?=====+set lines 132 
 +col dbname for a9  heading "Database" 
 +col dbsize for a15 heading "Size" 
 +col dbused for a15 heading "Used space" 
 +col dbfree for a15 heading "Free space" 
 +with used_space as 
 +
 +select  bytes 
 +from    v$datafile 
 +union   all 
 +select  bytes 
 +from    v$tempfile 
 +union   all 
 +select  bytes 
 +from    v$log 
 +
 +, free_space as 
 +
 +select sum(bytes) sum_bytes 
 +from dba_free_space 
 +
 +select vd.name                                                                                            dbname 
 +,      round(sum(used_space.bytes)/1024/1024/1024 ) || ' GB'                                              dbsize 
 +,      round(sum(used_space.bytes)/1024/1024/1024 ) - round(free_space.sum_bytes/1024/1024/1024) || ' GB' dbused 
 +,      round(free_space.sum_bytes/1024/1024/1024) || ' GB'                                                dbfree 
 +from   free_space 
 +,      used_space 
 +,      v$database vd 
 +group  by vd.name 
 +,      free_space.sum_bytes 
 +
 +</code> 
 +==== How big are the tablespaces? ====
 Report the database size in terms of tablespace Report the database size in terms of tablespace
-<code>5@@</code>+<code> 
 +set pages 100 lines 200 
 +select df.tablespace_name                                                    "Tablespace" 
 +,      totalusedspace                                                        "Used MB" 
 +,      (df.totalspace - tu.totalusedspace)                                   "Free MB" 
 +,      df.totalspace                                                         "Total MB" 
 +,      round( 100 * ( (df.totalspace - tu.totalusedspace) / df.totalspace) ) "Pct. Free" 
 +from   ( 
 +       select tablespace_name 
 +       ,      round(sum(bytes) / 1048576) totalspace 
 +       from   dba_data_files 
 +       group  by tablespace_name 
 +       ) df 
 +,      ( 
 +       select round(sum(bytes)/(1024*1024)) totalusedspace 
 +       ,      tablespace_name 
 +       from   dba_segments 
 +       group  by tablespace_name 
 +       ) tu 
 +where  df.tablespace_name  = tu.tablespace_name 
 +and    df.totalspace      != 0 
 +order  by 5 
 +
 +</code>
  
-=====Database Free space report=====+==== How big are the schemas? ==== 
 +<code> 
 +set lines 1000 pages 100 
 +break on report 
 +compute sum of schema_size_gig on report 
 +select owner 
 +,      sum(bytes)/1024/1024/1024 schema_size_gig 
 +from   dba_segments 
 +group  by owner 
 +order  by 2 
 +
 +</code> 
 + 
 +==== How to start a database after altering the spfile with a value that makes startup impossible ==== 
 +From [[https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:2200190221847]] 
 +<code> 
 +[email protected]> alter system set processes=5000 scope=spfile; 
 +System altered. 
 + 
 +[email protected]> shutdown 
 +Database closed. 
 +Database dismounted. 
 +ORACLE instance shut down. 
 + 
 +... 
 +Connected to an idle instance. 
 + 
 +idle> startup 
 +ORA-00064: object is too large to allocate on this O/S (1,4720000) 
 +idle> Disconnected 
 +</code> 
 + 
 +I'm hosed! cannot start. processes=5000 too big. So, using Kevins approach and the fact that the LAST parameter value will be used, I just: 
 + 
 +<code> 
 +[ora920@tkyte-pc-isdn dbs]$ cat temp.ora 
 +spfile= /usr/oracle/ora920/OraHome1/dbs/spfileora920.ora 
 +processes = 150 
 + 
 +Connected to an idle instance. 
 + 
 +idle> startup pfile=temp.ora 
 +ORACLE instance started. 
 + 
 +Total System Global Area 143725064 bytes 
 +Fixed Size 451080 bytes 
 +Variable Size 109051904 bytes 
 +Database Buffers 33554432 bytes 
 +Redo Buffers 667648 bytes 
 +Database mounted. 
 +Database opened. 
 +idle> show parameter processes 
 + 
 +NAME TYPE VALUE 
 +------------------------------------ ----------- ------------------------------ 
 +... 
 +processes integer 150 
 +idle> alter system set processes=150 scope=spfile; 
 +System altered. 
 +</code> 
 + 
 +==== Show the High Water Mark for a given table, or all tables if ALL is specified for Table_Name ==== 
 +From [[http://www.oracle-wiki.net/startsqlshowhwmtab]] 
 +<code> 
 +SET LINESIZE 300 
 +SET SERVEROUTPUT ON 
 +SET VERIFY OFF 
 +  
 +DECLARE 
 +  CURSOR cu_tables IS 
 +    SELECT a.owner, 
 +           a.table_name 
 +    FROM   all_tables a 
 +    WHERE  a.table_name = Decode(Upper('&&Table_Name'),'ALL',a.table_name,Upper('&&Table_Name')) 
 +    AND    a.owner      = Upper('&&Table_Owner')  
 +    AND    a.partitioned='NO' 
 +    AND    a.logging='YES' 
 +order by table_name; 
 +  
 +  op1  NUMBER; 
 +  op2  NUMBER; 
 +  op3  NUMBER; 
 +  op4  NUMBER; 
 +  op5  NUMBER; 
 +  op6  NUMBER; 
 +  op7  NUMBER; 
 +BEGIN 
 +  
 +  Dbms_Output.Disable; 
 +  Dbms_Output.Enable(1000000); 
 +  Dbms_Output.Put_Line('TABLE                             UNUSED BLOCKS     TOTAL BLOCKS  HIGH WATER MARK'); 
 +  Dbms_Output.Put_Line('------------------------------  ---------------  ---------------  ---------------'); 
 +  FOR cur_rec IN cu_tables LOOP 
 +    Dbms_Space.Unused_Space(cur_rec.owner,cur_rec.table_name,'TABLE',op1,op2,op3,op4,op5,op6,op7); 
 +    Dbms_Output.Put_Line(RPad(cur_rec.table_name,30,' ') || 
 +                         LPad(op3,15,' '               || 
 +                         LPad(op1,15,' '               || 
 +                         LPad(Trunc(op1-op3-1),15,' '));  
 +  END LOOP; 
 +  
 +END; 
 +
 +</code> 
 +==== Database Free space report ====
 From [[http://asktom.oracle.com/pls/asktom/ASKTOM.download_file?p_file=6551402703363001567|asktom]] From [[http://asktom.oracle.com/pls/asktom/ASKTOM.download_file?p_file=6551402703363001567|asktom]]
  
-*Tablespace Name: name of tablespace, leading '*' indicates a good locally managed tablespace, leading blank means it is a bad dictionary managed tablespace. Second character of A implies ASSM managed storage, second character of M implies manually managed (pctused, freelists, etc are used to control space utilization) +  * Tablespace Name: name of tablespace, leading '*' indicates a good locally managed tablespace, leading blank means it is a bad dictionary managed tablespace. Second character of A implies ASSM managed storage, second character of M implies manually managed (pctused, freelists, etc are used to control space utilization) 
-*Mbytes: allocated space of the tablespace, sum of mbytes consumed by all datafiles associated with tablespace. +  * Mbytes: allocated space of the tablespace, sum of mbytes consumed by all datafiles associated with tablespace. 
-*Used: space in the tablespace that is used by some segment. +  * Used: space in the tablespace that is used by some segment. 
-*Free: space in the tablespace not allocated to any segment. +  * Free: space in the tablespace not allocated to any segment. 
-*%Used: ratio of free to allocated space +  * %Used: ratio of free to allocated space 
-*largest: mostly useful with dictionary managed tablespaces, the size of the largest contiguous set of blocks available. If this number in a dictionary managed tablespace is smaller than the next extent for some object, that object could fail with "out of space" even if the FREE column says there is lots of free space. +  * largest: mostly useful with dictionary managed tablespaces, the size of the largest contiguous set of blocks available. If this number in a dictionary managed tablespace is smaller than the next extent for some object, that object could fail with "out of space" even if the FREE column says there is lots of free space. 
-*MaxPoss Kbytes: the autoextend max size (note CAN be smaller than the allocated size!!!! you can set the maxsize to be less than the current size of a file) +  * MaxPoss Kbytes: the autoextend max size (note CAN be smaller than the allocated size!!!! you can set the maxsize to be less than the current size of a file) 
-*%Max Used: how much of the maximum autoextend size has been used so far  +  * %Max Used: how much of the maximum autoextend size has been used so far 
-<code>6@@</code>+<code> 
 +set linesize 132 
 +------------------------------------------------------- 
 +-- This SQL Plus script lists freespace by tablespace 
 +-------------------------------------------------------- 
 + 
 +column dummy noprint 
 +column  pct_used      format 999.9             heading "%|Used" 
 +column  name          format a19               heading "Tablespace Name" 
 +column  Mbytes        format 999,999,999       heading "MBytes" 
 +column  used          format 999,999,999       heading "Used" 
 +column  free          format 999,999,999       heading "Free" 
 +column  largest       format 999,999,999       heading "Largest" 
 +column  max_size      format 9,999,999,999,999 heading "MaxPoss|Mbytes" 
 +column  pct_max_used  format 999.9             heading "%|Max|Used" 
 +break   on report 
 +compute sum of mbytes on report 
 +compute sum of free on report 
 +compute sum of used on report 
 + 
 +select (select decode(extent_management,'LOCAL','*',' ') || 
 +               decode(segment_space_management,'AUTO','a ','m ') 
 +              from dba_tablespaces where tablespace_name = b.tablespace_name) || 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, 
 +           nvl(largest,0) largest, 
 +           nvl(mbytes_max,mbytes_alloc) Max_Size, 
 +           decode( mbytes_max, 0, 0, (mbytes_alloc/mbytes_max)*100) pct_max_used 
 +from ( select sum(bytes)/1024/1024 mbytes_free, 
 +                          max(bytes)/1024/1024 largest, 
 +                          tablespace_name 
 +           from  sys.dba_free_space 
 +           group by tablespace_name ) a, 
 +     ( select sum(bytes)/1024/1024 mbytes_alloc, 
 +                          sum(maxbytes)/1024/1024 mbytes_max, 
 +                          tablespace_name 
 +           from sys.dba_data_files 
 +           group by tablespace_name 
 +           union all 
 +      select sum(bytes)/1024/1024 mbytes_alloc, 
 +                          sum(maxbytes)/1024/1024 mbytes_max, 
 +                          tablespace_name 
 +           from sys.dba_temp_files 
 +           group by tablespace_name )b 
 +where a.tablespace_name (+) = b.tablespace_name 
 +order by 8 
 +
 +</code>
  
-=====Which schemas are taking up all of the space?=====+==== Which schemas are taking up all of the space? ==== 
 +<code>
  set pages 999  set pages 999
  col "size MB" format 999,999,999  col "size MB" format 999,999,999
Line 51: Line 554:
  ,      2 desc  ,      2 desc
  ,      1;  ,      1;
-=====Show the ten largest objects in the database===== +</code> 
- colowner format a15 +==== Show the ten largest objects in the database ==== 
- colsegment_name format a30 +<code> 
- colsegment_type format a15 +colowner format a15 
- colmb format 999,999,999 +colsegment_name format a30 
- select owner +colsegment_type format a15 
- ,      segment_name +colmb format 999,999,999 
- ,      segment_type +select owner 
- ,      mb +,      segment_name 
- from   ( +,      segment_type 
-        select owner +,      mb 
-        ,      segment_name +from   ( 
-        ,      segment_type +       select owner 
-        ,      bytes / 1024 / 1024 "MB" +       ,      segment_name 
-        from   dba_segments +       ,      segment_type 
-        order  by bytes desc +       ,      bytes / 1024 / 1024 "MB" 
-        +       from   dba_segments 
- where  1=1 +       order  by bytes desc 
- and    rownum < 11; +       
-=====Is java installed in the database?=====+where  1=1 
 +and    rownum < 11; 
 +</code> 
 + 
 +==== Is java installed in the database? ====
 This will return 9000'ish if it is This will return 9000'ish if it is
 +<code>
  select count(*)  select count(*)
  from   all_objects  from   all_objects
Line 77: Line 585:
  and    object_type like '%JAVA%'  and    object_type like '%JAVA%'
  and    owner = 'SYS';  and    owner = 'SYS';
-=====Show character set information=====+</code> 
 +==== Show character set information ==== 
 +<code>
  select * from nls_database_parameters;  select * from nls_database_parameters;
-=====Show all used features=====+</code> 
 +==== Show all used features ==== 
 +<code>
  select name  select name
  ,      detected_usages  ,      detected_usages
Line 85: Line 597:
  where  1=1  where  1=1
  and    detected_usages > 0;  and    detected_usages > 0;
-=====Move a database from one host to another without RMAN===== +</code> 
-Once upon a time, this was the only way to move a database to a different server. Now it's not common as RMAN can do it so well.<br />+==== Move a database from one host to another without RMAN ==== 
 +Once upon a time, this was the only way to move a database to a different server. Now it's not common as RMAN can do it so well.\\
 **On source server** **On source server**
-====Get a text version of the controlfile==== +=== Get a text version of the controlfile === 
-<code>7@@</code> +<code> 
-====Grab a copy of the pfile==== +alter database backup controlfile to trace as '/tmp/&database_name._cf.sql'; 
-<code>8@@</code> +</code> 
-====Send these 2 files to the destination server==== +=== Grab a copy of the pfile === 
-<code>9@@</code> +<code> 
-====Shutdown the database==== +create pfile='/tmp/init_&database..ora' from spfile; 
-<code>10@@</code> +</code> 
-====Copy the database datafiles to the new host (see in the controlfile creation script where they are)==== +=== Send these 2 files to the destination server === 
-As we are going to reopen the database with resetlogs, no need to copy the redo logs.<br />+<code> 
 +scp /tmp/init*ora /tmp/*_cf.sql oracle@${dest_host}:/tmp/ 
 +</code> 
 +=== Shutdown the database === 
 +<code> 
 +shu immediate 
 +</code> 
 +=== Copy the database datafiles to the new host (see in the controlfile creation script where they are) === 
 +As we are going to reopen the database with resetlogs, no need to copy the redo logs.\\
 As a new did will be created, no need to copy the archivelogs. If we need the old database back, we can just restart it on this server. As a new did will be created, no need to copy the archivelogs. If we need the old database back, we can just restart it on this server.
-<code>11@@</code>+<code> 
 +scp /cln/exp/ora_data3/cocpit/*dbf oracle@hn512:/cln/exp/ora_data2/cocpit/ 
 +</code>
 **On destination server** **On destination server**
-====Edit the files==== +=== Edit the files === 
-  * Change path names for new filesystem(s) +  *  Change path names for new filesystem(s) 
-  * Create any directories that don't exist (archivelog, audit, ...) +  *  Create any directories that don't exist (archivelog, audit, ...) 
-  * Modify the controlfile recreation script +  *  Modify the controlfile recreation script 
-    * Remove Part #1 (use the resetlogs option) +    *  Remove Part #1 (use the resetlogs option) 
-    * Change REUSE to SET +    *  Change REUSE to SET 
-    * Remove the recover database and open statements +    *  Remove the recover database and open statements 
-    * Comment out the alter tablespace temp statements. Might need it after opening. +    *  Comment out the alter tablespace temp statements. Might need it after opening. 
-====Add database entry to /etc/oratab==== +=== Add database entry to /etc/oratab === 
-====Create or add entry to listener.ora==== +=== Create or add entry to listener.ora === 
-====Create or add entry to tnsnames.ora==== +=== Create or add entry to tnsnames.ora === 
-====Setup environment for database==== +=== Setup environment for database === 
-<code>12@@</code> +<code> 
-====Copy init file to where it can be used==== +. .oraenv 
-<code>13@@</code>+</code> 
 +=== Copy init file to where it can be used === 
 +<code> 
 +cp /tmp/init${ORACLE_SID}.ora ${ORACLE_HOME}/dbs/ 
 +</code> 
 + 
 +=== Create the new controlfile === 
 +<code> 
 +cd /tmp 
 +sqlplus / as sysdba 
 +@&database_name._cf 
 +</code> 
 +=== Mount the database === 
 +<code> 
 +alter database mount 
 +</code> 
 +=== Open the database === 
 +<code> 
 +alter database open resetlogs 
 +</code> 
 +=== Check the database === 
 +<code> 
 +set lines 2000 pages 100 
 +col file_name for a80 
 +select file_name, status, online_status from dba_data_files; 
 +select file_name, status, online_status from dba_temp_files; 
 +</code>
  
-====Create the new controlfile==== 
-<code>14@@</code> 
-====Mount the database==== 
-<code>15@@</code> 
-====Open the database==== 
-<code>16@@</code> 
-====Check the database==== 
-<code>17@@</code> 
database_status.1544130326.txt.gz · Last modified: 2018/12/06 21:05 by 91.177.234.129

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki