Killing Oracle Session from database and OS level

Identify the Session to be Killed

Killing sessions can be very destructive if you kill the wrong session, so be very careful when identifying the session to be killed. If you kill a session belonging to a background process you will cause an instance crash.

Identify the offending session using the [G]V$SESSION and [G]V$PROCESS views as follows.

SET LINESIZE 100
COLUMN spid FORMAT A10
COLUMN username FORMAT A10
COLUMN program FORMAT A45

SQL> SELECT s.inst_id,
       s.sid,
       s.serial#,
       p.spid,
       s.username,
       s.program
FROM   gv$session s
       JOIN gv$process p ON p.addr = s.paddr AND p.inst_id = s.inst_id
WHERE  s.type != ‘BACKGROUND’;

   INST_ID        SID    SERIAL# SPID       USERNAME   PROGRAM
———- ———- ———- ———- ———- ———————————————
         1         30         15 3859       TEST       sqlplus@oel5-11gr2.localdomain (TNS V1-V3)
         1         23        287 3834       SYS        sqlplus@oel5-11gr2.localdomain (TNS V1-V3)
         1         40        387 4663                  oracle@oel5-11gr2.localdomain (J000)
         1         38        125 4665                  oracle@oel5-11gr2.localdomain (J001)

The SID and SERIAL# values of the relevant session can then be substituted into the commands in the following sections.

ALTER SYSTEM KILL SESSION

The basic syntax for killing a session is shown below.

SQL> ALTER SYSTEM KILL SESSION ‘sid,serial#’;

In a RAC environment, you optionally specify the INST_ID, shown when querying the GV$SESSION view. This allows you to kill a session on different RAC node.

SQL> ALTER SYSTEM KILL SESSION ‘sid,serial#,@inst_id’;

The KILL SESSION command doesn’t actually kill the session. It merely asks the session to kill itself. In some situations, like waiting for a reply from a remote database or rolling back transactions, the session will not kill itself immediately and will wait for the current operation to complete. In these cases the session will have a status of “marked for kill”. It will then be killed as soon as possible.

In addition to the syntax described above, you can add the IMMEDIATE clause.

SQL> ALTER SYSTEM KILL SESSION ‘sid,serial#’ IMMEDIATE;

This does not affect the work performed by the command, but it returns control back to the current session immediately, rather than waiting for confirmation of the kill.

If the marked session persists for some time you may consider killing the process at the operating system level. Before doing this it’s worth checking to see if it is performing a rollback. You can do this by running this script (session_undo.sql). If the USED_UREC value is decreasing for the session in question you should leave it to complete the rollback rather than killing the session at the operating system level.

ALTER SYSTEM DISCONNECT SESSION

The ALTER SYSTEM DISCONNECT SESSION syntax is an alternative method for killing Oracle sessions. Unlike the KILL SESSION command which asks the session to kill itself, the DISCONNECT SESSION command kills the dedicated server process (or virtual circuit when using Shared Sever), which is equivalent to killing the server process from the operating system. The basic syntax is similar to the KILL SESSION command with the addition of the POST_TRANSACTION clause. The SID and SERIAL# values of the relevant session can be substituted into one of the following statements.

SQL> ALTER SYSTEM DISCONNECT SESSION ‘sid,serial#’ POST_TRANSACTION;

SQL> ALTER SYSTEM DISCONNECT SESSION ‘sid,serial#’ IMMEDIATE;

The POST_TRANSACTION clause waits for ongoing transactions to complete before disconnecting the session, while the IMMEDIATE clause disconnects the session and ongoing transactions are rolled back immediately.

The POST_TRANSACTION and IMMEDIATE clauses can be used together, but the documentation states that in this case the IMMEDIATE clause is ignored. In addition, the syntax diagram suggests both clauses are optional, but in reality, one or both must be specified or you receive an error.

SQL> alter system disconnect session ‘30,7’;

alter system disconnect session ‘30,7’
                                     *
ERROR at line 1:
ORA-02000: missing POST_TRANSACTION or IMMEDIATE keyword

SQL>
This command means you should never need to switch to the operating system to kill sessions, which reduces the chances of killing the wrong process.

The Windows Approach

To kill the session on the Windows operating system, first identify the session, then substitute the relevant SID and SPID values into the following command issued from the command line.

C:\> orakill ORACLE_SID spid

The session thread should be killed immediately and all resources released.

The UNIX Approach

Warning: If you are using the Multithreaded Model in Oracle 12c, you should not attempt to kill operating system processes. To know why, read this.

To kill the session on UNIX or Linux operating systems, first identify the session, then substitute the relevant SPID into the following command.

% kill spid

If after a few minutes the process hasn’t stopped, terminate the session using the following.

% kill -9 spid

If in doubt check that the SPID matches the UNIX PROCESSID shown using.

% ps -ef | grep ora

The session thread should be killed immediately and all resources released.

Tracking Cursors usage

Total cursors open, by session:

select a.value, s.username, s.sid, s.serial#
from v$sesstat a, v$statname b, v$session s
where a.statistic# = b.statistic#  and s.sid=a.sid
and b.name = ‘opened cursors current’
and username = ‘FARHAT’;

Here’s how to find open cursors that have been parsed. You need to be logged in as a user with access to v$open_cursor and v$session.

COLUMN USER_NAME FORMAT A15

SELECT s.machine, oc.user_name, oc.sql_text, count(1)
FROM v$open_cursor oc, v$session s
WHERE oc.sid = s.sid
GROUP BY user_name, sql_text, machine
HAVING COUNT(1) > 2
ORDER BY count(1) DESC
;

This select shows you the actual SQL code that opened the cursors

select  sql_text, count(*) as “OPEN CURSORS”, user_name from v$open_cursor
group by sql_text, user_name order by count(*) desc;

You can filter your users

select  sql_text, count(*) as “OPEN CURSORS”, user_name from v$open_cursor
WHERE USER_NAME=’FARHAT’
group by sql_text, user_name order by count(*) desc;

You can find Sum of Number of Cursors opened by all users connected to database

select sum(a.value) total_cur, avg(a.value) avg_cur, max(a.value) max_cur,
 s.username, s.machine
 from v$sesstat a, v$statname b, v$session s
 where a.statistic# = b.statistic# and s.sid=a.sid
 and b.name = ‘opened cursors current’
 group by s.username, s.machine
 order by 1 desc;

Bulk vs Conventional data Loading in Oracle for Large tables

DECLARE
TYPE t_bas_user_log IS TABLE OF BAS_USER_LOG%ROWTYPE;
myuser_tab   t_bas_user_log := t_bas_user_log();
start_time  number;
end_time   number;
BEGIN
— Populate a collection – 100000 rows
SELECT * BULK COLLECT INTO myuser_tab FROM base_user_log1;
EXECUTE IMMEDIATE ‘TRUNCATE TABLE myuser_log’;
Start_time := DBMS_UTILITY.get_time;
FOR i in myuser_tab.first .. myuser_tab.last LOOP
 INSERT INTO myuser_log –(product_id, product_name, effective_date)
 VALUES  (myuser_tab(i).LOG_SERIAL_NUM      ,
myuser_tab(i).LOG_USER_ID        ,
  myuser_tab(i).LOG_ACTION_TYPE     ,
  myuser_tab(i).LOG_DATE           ,
  myuser_tab(i).TABLE_NAME         ,
  myuser_tab(i).FIELD_NAME_STRING  ,
  myuser_tab(i).OLD_VALUE_STRING   ,
  myuser_tab(i).NEW_VALUE_STRING   ,
  myuser_tab(i).CMP_NUM             ,
  myuser_tab(i).TRANS_SERIAL        ,
  myuser_tab(i).ACCOUNT_YEAR  )    ;
END LOOP;
end_time := DBMS_UTILITY.get_time;
DBMS_OUTPUT.PUT_LINE(‘Conventional Insert: ‘||to_char(end_time-start_time));
EXECUTE IMMEDIATE ‘TRUNCATE TABLE myuser_log’;
Start_time := DBMS_UTILITY.get_time;
FORALL i in myuser_tab.first .. myuser_tab.last
 INSERT INTO myuser_log VALUES myuser_tab(i);
end_time := DBMS_UTILITY.get_time;
DBMS_OUTPUT.PUT_LINE(‘Bulk Insert: ‘||to_char(end_time-start_time));
    COMMIT;
END;

Image below shows that there is a huge difference between Bulk and conventional data loading.

Patching RAC (Grid Plus Database) / Bundle Patch not full release


Environment: 11gRAC/DB (11.2.0.3) , Windows Server 2008 R2 x64 Edition
Patch:13965211 – 11.2.0.3 Patch 6 for Windows 64 bit, download patch from metalink.
This patch is RAC rolling upgradable for GRID, and RDBMS homes. 
You should administer one Oracle product, one Oracle home at a time, for its particular Bundle Patch Update.

DB 11.2.0.3 Patch 6 includes all bugs fixed in 11.2.0.3 Patch 1 to Patch 5. It must be applied on top of the 11.2.0.3 base release or on top of any earlier bundle patch from 11.2.0.3 Patch 1 to Patch 5.
The order of patching in RAC install is GRID_HOME, then RDBMS_HOME 
OPatch Info:
Oracle recommends that you use OPatch utility release 11.2.0.1.9 or later. You can download it fromMy Oracle Support with patch 6880880.

Patch Installation Instructions
Patching GRID Home

  1. Before Patching GRID_HOME, stop OCR related resources, Oracle HASD Services (OHASD) Services and all Oracle Services:
    > srvctl stop service -d  
             -s  -i 
    > srvctl stop instance -d DBNAME -i INSTANCE -o abort
    > crsctl stop crs

    make the backup of the Oracle Home being patached (eg; d:\app...)

  2. To verify all resources have been oved to the other nodes, run the following command from another node with GRID running:
    > crsctl status resource -t

     

  3. Then use the Computer Management Services GUI or the net stop command to stop ALL Oracle services running on that node:
        net stop OracleService
        net stop OracleTNSListenerLISTENER_
        net stop OracleTNSListenerLISTENER_SCANn
        net stop OracleDBConsole
        net stop OracleASMService
        net stop “Oracle VSS Writer Service”
        net stop OracleREMExecService
        net stop OracleOHService
        net stop “Oracle Object Service”
        net stop OracleClusterVolumeService
        net stop ocfs (required only for OCFS installation)
        net stop orafenceservice
        Note: An explicit ‘srvctl start listener -n ‘ should be issued after patching
  4. Set the ORACLE_HOME environment variable properly
    D:\Sources\11.2.0.3\Patches\p6880880_112000_MSWIN-x86-64_optach\OPatch>set ORACLE_HOME=D:\app\11.2.0.3\grid
  5. Go to the directory where you downloaded the patch:
    D:\Sources\11.2.0.3\Patches\p6880880_112000_MSWIN-x86-64_optach\OPatch>cd D:\Sources\11.2.0.3\Patches\p13965211_112030_MSWIN-x86-64
    First check the inventory for the existing patches
    D:\Sources\11.2.0.3\Patches\p13965211_112030_MSWIN-x86-64>D:\Sources\11.2.0.3\Patches\p6880880_112000_MSWIN-x86-64_optach\OPatch\opatch lsinventory
Oracle Interim Patch Installer version 11.2.0.3.0
Copyright (c) 2012, Oracle Corporation.  All rights reserved.


Oracle Home       : D:\app\11.2.0.3\grid
Central Inventory : C:\Program Files\Oracle\Inventory
   from           : n/a
OPatch version    : 11.2.0.3.0
OUI version       : 11.2.0.3.0
Log file location : D:\app\11.2.0.3\grid\cfgtoollogs\opatch\opatch2012-05-26_10-47-13AM_1.log

Lsinventory Output file location : D:\app\11.2.0.3\grid\cfgtoollogs\opatch\lsinv\lsinventory2012-05-26_10-47-13AM.txt

——————————————————————————–
Installed Top-level Products (1):

Oracle Grid Infrastructure                                           11.2.0.3.0
There are 1 products installed in this Oracle Home.


There are no Interim patches installed in this Oracle Home.


Rac system comprising of multiple nodes
  Local node = P-HQ-CL-OR-11
  Remote node = P-HQ-CL-OR-12

——————————————————————————–

OPatch succeeded.

  1. D:\Sources\11.2.0.3\Patches\p13965211_112030_MSWIN-x86-64>cd 13965211
  2. D:\Sources\11.2.0.3\Patches\p13965211_112030_MSWIN-x86-64\13965211>D:\Sources\11.2.0.3\Patches\p6880880_112000_MSWIN-x86-64_optach\OPatch\opatch apply -local
  1. opatch will attempt to apply the patch on all the nodes in the cluster sequentially. However will prompt for user input to start patching other nodes. At this time ensure that the Oracle services on target node are stopped before proceeding to patch. Once the opatch session completes patching this node, start the services and proceed applying patch to the next node.
  2.  Once the opatch session completes patching GRID_HOME on a node, run the following before proceeding to patch GRID_HOME on the next node. %ORACLE_HOME%\bin\acfsroot installD:\Sources\11.2.0.3\Patches\p13965211_112030_MSWIN-x86-64\13965211>%ORACLE_HOME%\bin\acfsroot install
    ACFS-9300: ADVM/ACFS distribution files found.
    ACFS-9307: Installing requested ADVM/ACFS software.
    ACFS-9308: Loading installed ADVM/ACFS drivers.
    ACFS-9327: Verifying ADVM/ACFS devices.
    ACFS-9157: Detecting driver ‘oracle oks’.
    ACFS-9157: Detecting driver ‘oracle advm’.
    ACFS-9157: Detecting driver ‘oracle acfs’.
    ACFS-9309: ADVM/ACFS installation correctness verified.

  3. After this you can start the CRS or go for the RDBMS home patch without starting it, I started.
    D:\app\11.2.0.3\grid\BIN>crsctl start crs
    CRS-4123: Oracle High Availability Services has been started.

    D:\app\11.2.0.3\grid\BIN>crsctl check crs
    CRS-4638: Oracle High Availability Services is online
    CRS-4537: Cluster Ready Services is online
    CRS-4529: Cluster Synchronization Services is online
    CRS-4533: Event Manager is online
     
  4. Verify the patch installation
  5. opatch lsinventory 

    Patching RDBMS Home

    1. Before Patching RDBMS_HOME, the GRID and ASM services can be running.
      Stop OCR related resources and Oracle Services on the current node as listed below:
      > srvctl stop service -d -s -i > srvctl stop instance -d -i -o abort
      D:\app\11.2.0.3\grid\BIN>srvctl stop instance -d rac -i rac1
    2. Set ORACLE_HOME
      D:\Sources\11.2.0.3\Patches\p13965211_112030_MSWIN-x86-64\13965211>set ORACLE_HOME=D:\app\farif\product\11.2.0.3\dbhome_1
    3.  Apply patch
      D:\Sources\11.2.0.3\Patches\p13965211_112030_MSWIN-x86-64\13965211>D:\Sources\11.2.0.3\Patches\p6880880_112000_MSWIN-x86-64_optach\OPatch\opatch apply 
    4. Start the DB instances
      D:\app\11.2.0.3\grid\BIN>srvctl start instance -d rac -i rac1

      D:\app\11.2.0.3\grid\BIN>
    5. Post installation steps

      After installing the patch, perform the following actions:
      For each database instance running out of the ORACLE_HOME being patched, connect to the database using SQL*Plus as SYSDBA and run catwinbundle.sql as follows:

      d %ORACLE_HOME%\Bundle\Patch6
      > sqlplus /nolog
      SQL> CONNECT / AS SYSDBA
      SQL> STARTUP
      SQL> @catwinbundle.sql
      SQL> QUIT

C:\Users\farif>cd D:\app\farif\product\11.2.0.3\dbhome_1\bundle\patch6


D:\app\farif\product\11.2.0.3\dbhome_1\bundle\patch6>sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Sun May 27 11:30:19 2012

Copyright (c) 1982, 2011, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 – 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, Oracle Label Security,
OLAP, Data Mining and Real Application Testing options

SQL>

SQL> @catwinbundle.sql

SQL> ALTER SESSION SET current_schema = SYS;

Session altered.

SQL> PROMPT Updating registry…
Updating registry…
SQL> INSERT INTO registry$history
  2    (action_time, action,
  3     namespace, version, id,
  4     bundle_series, comments)
  5  VALUES
  6    (SYSTIMESTAMP, ‘APPLY’,
  7     SYS_CONTEXT(‘REGISTRY$CTX’,’NAMESPACE’),
  8     ‘11.2.0.3’,
  9     6,
 10     ‘WINBUNDLE’,
 11     ‘11.2.0.3 BP 6’);

1 row created.

SQL> COMMIT;

Commit complete.

SQL> SPOOL off
SQL> SET echo off
Check the following log file for errors:
D:\app\farif\cfgtoollogs\catbundle\catbundle_WINBUNDLE_RAC_APPLY_2012May27_11_31_37.log
SQL>

Check all dependent objects are valid and if not then compile them by using 
utlrp.sql
SQL> select count(*) from dba_objects where status ='INVALID';

COUNT(*)
----------
20083
Note: 
You must execute the steps in “Post Installation Steps” for any new database that was created by any of the following methods:

  • Using DBCA (Database Configuration Assistant) to select a sample database (General, Data Warehouse, Transaction Processing)
  • Using a script that was created by DBCA that creates a database from a sample database
  • Cloning a database that was created by either of the two preceding methods, and if “Post Installation Steps”   was not executed after Bundle Patch6 was applied

Using Service in Oracle RAC environment

10g

To add a service

Command: srvctl add service -d db_name -s service_name -r pref_insts [-a avail_insts] [-P TAF_policy]
Command: srvctl add service -d db_name -s service_name -u {-r “new_pref_inst” | -a “new_avail_inst”}
Example: srvctl add service -d RAC -s PRD -r RAC01,RAC02 -a RAC03,RAC04
Example: srvctl add serv -d CRM -s CRM -r CRM1 -a CRM3 -P basic

To remove a service

Command: srvctl remove service -d db_name -s service_name [-i inst_name] [-f]
Example: srvctl remove serv -d rac -s sales
Example: srvctl remove service -d rac -s sales -i rac01,rac02
To start a service

Command: srvctl start service -d db_name [-s service_names [-i inst_name]] [-o start_options]
Command: srvctl start service -d db_name -s service_names [-o open]
Command: srvctl start service -d db_name -s service_names -o nomount
srvctl start service -d db_name -s service_names -o mount
srvctl start serv -d dwh -s dwh

To stop a service

Command: srvctl stop service -d db_name [-s service_names [-i inst_name]] [-f]
srvctl stop serv -d dwh -s dwh

To view the status of Service

Command: srvctl status service -d db_name [-s service_names] [-f] [-v] [-S level]
srvctl status service -d rac -s rac

TO enable the service at cluster startup

Command: srvctl enable service -d db_name -s service_names [-i inst_name]
srvctl enable service -d apps -s apps1

To disable the service at cluster startup

Command: srvctl disable service -d db_name -s service_names [-i inst_name]
Example: srvctl disable serv -d rac -s rac -i rac1

To view the config service

Command: srvctl config service -d db_name [-s service_name] [-a] [-S level]
Command: srvctl config service -d db_name -a — -a shows TAF configuration
Example: srvctl config service -d TEST -s test PREF:TST1 AVAIL:TST2

To modify the service

Command: srvctl modify service -d db_name -s service_name -i old_inst_name -t new_inst_name [-f]
Command: srvctl modify service -d db_name -s service_name -i avail_inst_name -r [-f]
Command: srvctl modify service -d db_name -s service_name -n -i preferred_list [-a available_list] [-f]
Command: srvctl modify service -d db_name -s service_name -i old_inst_name -a avail_inst -P TAF_policy
Example: srvctl modify serv -d PROD -s DWH -n -i I1,I2,I3,I4 -a I5,I6

To relocate service

Command: srvctl relocate service -d db_name -s service_name -i old_inst_name -t target_inst [-f]
To Get/set the environment for Service

Command: srvctl getenv service -d db_name -s service_name -t name_list
Command: srvctl setenv service -d db_name [-s service_name] {-t “name=val[,name=val,…]” | -T “name=val”}
Command: srvctl unsetenv service -d db_name -s service_name -t name_list

11gR2

Command: srvctl add service -d db_unique_name -s service_name
-g server_pool [-c {UNIFORM|SINGLETON}] [-k network_number]
[-l [PRIMARY|PHYSICAL_STANDBY|LOGICAL_STANDBY|SNAPSHOT_STANDBY]
[-y {AUTOMATIC|MANUAL}] [-q {TRUE|FALSE}] [-j {SHORT|LONG}]
[-B {NONE|SERVICE_TIME|THROUGHPUT}] [-e {NONE|SESSION|SELECT}]
[-m {NONE|BASIC}] [-P {BASIC|NONE|PRECONNECT}] [-x {TRUE|FALSE}]
[-z failover_retries] [-w failover_delay]

To add service with service goals

Example: srvctl add service -d rac -s rac1 -q TRUE -m BASIC -e SELECT -z 180 -w 5 -j LONG

To add service wih preconnect taf

Command: srvctl add service -d db_unique_name -s service_name -u {-r preferred_list | -a available_list}
Example: srvctl add serv -d rac -s report -r rac01,rac02 -a rac03 -P PRECONNECT

To start service

Command: srvctl start service -d db_unique_name [-s “service_name_list” [-n node_name | -i instance_name]] [-o start_options]
Example: srvctl start serv -d rac -s rac
Example: srvctl start service -d rac -s rac -i rac2

To stop service

srvctl stop service -d db_unique_name [-s “service_name_list”] [-n node_name | -i instance_name] [-f]
srvctl stop service -d rac -s rac
srvctl stop serv -d rac -s rac -i rac2

To view service

srvctl status service -d db_unique_name [-s “service_name_list”] [-f] [-v]
srvctl status service -d rac -s rac -v

To modify the service

Command: srvctl modify service -d db_unique_name -s service_name
[-c {UNIFORM|SINGLETON}] [-P {BASIC|PRECONNECT|NONE}]
[-l {[PRIMARY]|[PHYSICAL_STANDBY]|[LOGICAL_STANDBY]|[SNAPSHOT_STANDBY]} [-q {TRUE|FALSE}] [-x {TRUE|FALSE}] [-j {SHORT|LONG}] [-B {NONE|SERVICE_TIME|THROUGHPUT}] [-e {NONE|SESSION|SELECT}] [-m {NONE|BASIC}] [-z failover_retries] [-w failover_delay] [-y {AUTOMATIC|MANUAL}]

Command: srvctl modify service -d db_unique_name -s service_name -i old_instance_name -t new_instance_name [-f]
Command: srvctl modify service -d db_unique_name -s service_name -i avail_inst_name -r [-f]
Command: srvctl modify service -d db_unique_name -s service_name -n -i preferred_list [-a available_list] [-f]

Example: srvctl modify service -d rac -s rac -i rac1 -t rac2
Example: srvctl modify serv -d rac -s rac -i rac1 -r
Example: srvctl modify service -d rac -s rac -n -i rac1 -a rac2
To relocate the service

Command: srvctl relocate service -d db_unique_name -s service_name {-c source_node -n target_node|-i old_instance_name -t new_instance_name} [-f]
Example: srvctl relocate service -d rac -s rac -i rac1 -t rac3

Installing Oracle Spatial 11.2.0.4

Step 1: Connect to the database where you want to install Oracle Spatial using SYSDBA privileges (use the SYS or SYSTEM accounts). For my install I used SQL*Plus to connect to the database.

Step 2: Verify prerequisites. To install Oracle Spatial, we need to have JAVA virtual machine, Oracle intermedia and Oracle XML database products already installed. Verify if the products are installed by executing the following SQL:

SQL> SELECT comp_id, version, status FROM dba_registry
WHERE comp_id IN (‘JAVAVM’,’ORDIM’,’XDB’)

COMP_ID VERSION STATUS

ORDIM 11.2.0.4.0 VALID
XDB 11.2.0.4.0 VALID
JAVAVM 11.2.0.4.0 VALID

————————————————————————–
Step 3: The install scripts also require a MDSYS user account. Ensure MDSYS user exists or create one before installing Oracle Spatial:

select username from dba_users where username like ‘MD%’

USERNAME

MDSYS
MDDATA

————————————————————————-
Step 4: Execute scripts to install Oracle Spatial:

SQL> spool D:\temp\spatial_install.txt

SQL> @D:\app\Oracle\product\11.2.0.4.0\dbhome_1\md\admin\mdprivs.sql

SQL> @D:\app\Oracle\product\11.2.0.4.0\dbhome_1\md\admin\mdinst.sql

——————————————————————-
Step 5: Verify Oracle Spatial is installed correctly. There should not be any invalid objects in MDSYS account:

SELECT comp_id, control, schema, version, status, comp_name
FROM   dba_registry
WHERE  comp_id = ‘SDO’

COMP_ID CONTROL   SCHEMA                 VERSION     STATUS   COMP_NAME                                      
———————————————————————————————-
SDO                            SYS                           MDSYS                        11.2.0.4.0 VALID   Spatial                
                                                                     
                                                                               
1 row selected.
——————————————————————

SQL> SELECT object_name, object_type, status FROM dba_objects
 WHERE  owner = ‘MDSYS’
 AND    status ‘VALID’
ORDER BY 1

no rows selected

Storing PDF Files inside Database


Create Source (D:\temp) and output (D:\temp\tgt) directories.

CRATE OR REPLACE DIRECTORY MY_FILES AS ‘D:\temp’;

GRANT READ, WRITE ON DIRECTORY MY_FILES TO PUBLIC;

CREATE OR REPLACE DIRECTORY TGT_FILES AS ‘D:\temp\tgt’;

GRANT READ, WRITE ON DIRECTORY TGT_FILES TO PUBLIC;

————————————————————————————-
Create table with blob data type which will store file inside table column.

CREATE TABLE STORE_FILES (
FILE_ID NUMBER,
FILE_NAME VARCHAR2(20),
FILE_COPY BLOB);

——————————————————————–
Create procedure which will load files from source directory(D:\temp) to database table STORE_FILES

CREATE OR REPLACE PROCEDURE load_file_to_table (p_file_id IN STORE_FILES.FILE_ID%TYPE, p_file_name IN STORE_FILES.FILE_NAME%TYPE) AS
v_bfile BFILE;
v_blob BLOB;
BEGIN
INSERT INTO STORE_FILES (file_id, file_name, file_copy)
VALUES (p_file_id, p_file_name, empty_blob())
RETURN file_copy INTO v_blob;
v_bfile := BFILENAME(‘SRC_FILES’, p_file_name);
DBMS_LOB.FILEOPEN(v_bfile, Dbms_Lob.File_Readonly);
DBMS_LOB.LOADFROMFILE(v_blob, v_bfile, Dbms_Lob.Getlength(v_bfile));
DBMS_LOB.FILECLOSE(v_bfile);
COMMIT;
END;
/

——————————————————————–
Copy a pdf file in source directory D:\temp (I copied test.pdf) You must replace name of file with your own file name in below code

exec load_file_to_table(1,’test.pdf’) ;

———————————————————————
Procedure to Unload files from DB to Server File System

CREATE OR REPLACE PROCEDURE load_file_to_target (p_file_id IN STORE_FILES.FILE_ID%TYPE, p_file_name IN STORE_FILES.FILE_NAME%TYPE) AS
v_blob BLOB;
v_start NUMBER := 1;
v_bytelen NUMBER := 32000;
v_len NUMBER ;
v_len_copy NUMBER;
v_raw_var RAW(32000);
v_output utl_file.file_type;
BEGIN
–define output directory and open the file in write byte mode
v_output := utl_file.fopen(‘TGT_FILES’, p_file_name,’wb’, 32760);
v_start := 1;
v_bytelen := 32000;
— get length of blob
SELECT DBMS_LOB.GETLENGTH(file_copy)
INTO v_len
FROM STORE_FILES
where file_name = p_file_name and file_id = p_file_id  ;
— save blob length
v_len_copy := v_len;
— Get the blob
select file_copy
into v_blob
FROM STORE_FILES
where file_name = p_file_name and file_id = p_file_id  ;
— Maximum size of buffer parameter is 32767 before which you have to flush your buffer
IF v_len < 32760 THEN
utl_file.put_raw(v_output,v_blob);
utl_file.fflush(v_output);
ELSE
— write in separate buffers
v_start := 1;
WHILE v_start 0
LOOP
DBMS_LOB.READ(v_blob,v_bytelen,v_start,v_raw_var);
utl_file.put_raw(v_output,v_raw_var);
utl_file.fflush(v_output);
— set the start position for next flush
v_start := v_start + v_bytelen;
— set the end position if less than 32000 bytes
v_len_copy := v_len_copy – v_bytelen;
IF v_len_copy < 32000 THEN
v_bytelen := v_len_copy;
END IF;
end loop;
utl_file.fclose(v_output);
END IF;
END;
/

———————————————————————-
Execute procedure to unload files from DB to D:\temp\tgt folder.

exec load_file_to_target(1,’test.pdf’) ;

Installing Patch 11.2.0.3 (Upgrade from 11.2.0.2 to 11.2.0.3)

Document to follow
http://docs.oracle.com/cd/E11882_01/server.112/e23633/upgrade.htm#UPGRD52731

To run the Pre-Upgrade Information Tool 
  1. Log in to the system as the owner of the environment of the database being upgraded.
    Important:

    The Pre-Upgrade Information Tool must be copied to and must be run from the environment of the database being upgraded.

  2. Start SQL*Plus.
  3. Connect to the database instance as a user with SYSDBA privileges.
  4. Set the system to spool results to a log file for later analysis:
    SQL> SPOOL upgrade_info.log
  5. Run the Pre-Upgrade Information Tool:
    SQL> @$11g_ORACLE_HOME/rdbms/admin/utlu112i.sql
  6. Turn off the spooling of script results to the log file:
    SQL> SPOOL OFF
    Check the output of the Pre-Upgrade Information Tool in upgrade_info.log.
##################################################
OUTPUT OF upgrade_info.log file
#################################################

Oracle Database 11.2 Pre-Upgrade Information Tool 12-24-2013 13:47:49                               

Script Version: 11.2.0.3.0 Build: 001                                                               

.                                                                                                   

**********************************************************************                              
Database:                                                                                           
**********************************************************************                              
–> name:          TEST                                                                             
–> version:       11.2.0.2.0                                                                       
–> compatible:    11.2.0.0.0                                                                       
–> blocksize:     8192                                                                             
–> platform:      Microsoft Windows x86 64-bit                                                     
–> timezone file: V14                                                                              
.                                                                                                   
**********************************************************************                              
Tablespaces: [make adjustments in the current environment]                                          
**********************************************************************                              
–> SYSTEM tablespace is adequate for the upgrade.                                                  
…. minimum required size: 705 MB                                                                  
–> SYSAUX tablespace is adequate for the upgrade.                                                  
…. minimum required size: 483 MB                                                                  
–> UNDOTBS1 tablespace is adequate for the upgrade.                                                
…. minimum required size: 400 MB                                                                  
–> TEMP tablespace is adequate for the upgrade.                                                    
…. minimum required size: 60 MB                                                                   
.                                                                                                   
**********************************************************************                              
Flashback: OFF                                                                                      
**********************************************************************                              
**********************************************************************                              
Update Parameters: [Update Oracle Database 11.2 init.ora or spfile]                                 
Note: Pre-upgrade tool was run on a lower version 64-bit database.                                  
**********************************************************************                              
–> If Target Oracle is 32-Bit, refer here for Update Parameters:                                   
— No update parameter changes are required.                                                        
.                                                                                                   
                                                                                                    
–> If Target Oracle is 64-Bit, refer here for Update Parameters:                                   
— No update parameter changes are required.                                                        
.                                                                                                   
**********************************************************************                              
Renamed Parameters: [Update Oracle Database 11.2 init.ora or spfile]                                
**********************************************************************                              
— No renamed parameters found. No changes are required.                                            
.                                                                                                   
**********************************************************************                              
Obsolete/Deprecated Parameters: [Update Oracle Database 11.2 init.ora or spfile]                    
**********************************************************************                              
— No obsolete parameters found. No changes are required                                            
.                                                                                                   
                                                                                                    
**********************************************************************                              
Components: [The following database components will be upgraded or installed]                       
**********************************************************************                              
–> Oracle Catalog Views         [upgrade]  VALID                                                   
–> Oracle Packages and Types    [upgrade]  VALID                                                   
–> JServer JAVA Virtual Machine [upgrade]  VALID                                                   
–> Oracle XDK for Java          [upgrade]  VALID                                                   
–> Oracle Workspace Manager     [upgrade]  VALID                                                   
–> OLAP Analytic Workspace      [upgrade]  VALID                                                   
–> OLAP Catalog                 [upgrade]  VALID                                                   
–> EM Repository                [upgrade]  VALID                                                   
–> Oracle Text                  [upgrade]  VALID                                                   
–> Oracle XML Database          [upgrade]  VALID                                                   
–> Oracle Java Packages         [upgrade]  VALID                                                   
–> Oracle interMedia            [upgrade]  VALID                                                   
–> Spatial                      [upgrade]  VALID                                                   
–> Expression Filter            [upgrade]  VALID                                                   
–> Rule Manager                 [upgrade]  VALID                                                   
–> Oracle Application Express   [upgrade]  VALID                                                   
… APEX will only be upgraded if the version of APEX in                                            
… the target Oracle home is higher than the current one.                                          
–> Oracle OLAP API              [upgrade]  VALID                                                   
.                                                                                                   
**********************************************************************                              
Miscellaneous Warnings                                                                              
**********************************************************************                              
WARNING: –> Your recycle bin is turned on and currently contains no objects.                       
…. Because it is REQUIRED that the recycle bin be empty prior to upgrading                        
…. and your recycle bin is turned on, you may need to execute the command:                        
        PURGE DBA_RECYCLEBIN                                                                        
…. prior to executing your upgrade to confirm the recycle bin is empty.                           
WARNING: –> Database contains schemas with objects dependent on DBMS_LDAP package.                 
…. Refer to the 11g Upgrade Guide for instructions to configure Network ACLs.                     
…. USER APEX_030200 has dependent objects.                                                        
.                                                                                                   
**********************************************************************                              
Recommendations                                                                                     
**********************************************************************                              
Oracle recommends gathering dictionary statistics prior to                                          
upgrading the database.                                                                             
To gather dictionary statistics execute the following command                                       
while connected as SYSDBA:                                                                          
                                                                                                    
    EXECUTE dbms_stats.gather_dictionary_stats;                                                     
                                                                                                    
**********************************************************************                              
Oracle recommends reviewing any defined events prior to upgrading.                                  
                                                                                                    
To view existing non-default events execute the following commands                                  
while connected AS SYSDBA:                                                                          
  Events:                                                                                           
    SELECT (translate(value,chr(13)||chr(10),’ ‘)) FROM sys.v$parameter2                            
      WHERE  UPPER(name) =’EVENT’ AND  isdefault=’FALSE’                                            
                                                                                                    
  Trace Events:                                                                                     
    SELECT (translate(value,chr(13)||chr(10),’ ‘)) from sys.v$parameter2                            
      WHERE UPPER(name) = ‘_TRACE_EVENTS’ AND isdefault=’FALSE’                                     
                                                                                                    
Changes will need to be made in the init.ora or spfile.                                             
                                                                                                    
********************************************************************** 

To check the status of access and add ACLs for network utility packages 


Run the pre-upgrade information tool as described in “Using the Pre-Upgrade Information Tool”.

Check the output from the pre-upgrade information tool (upgrade_info.log) for messages such as the following:
WARNING: –> Database contains schemas with objects dependent on network packages.
…. Refer to the 11g Upgrade Guide for instructions to configure Network ACLs.
…. USER WKSYS has dependent objects.
…. USER SYSMAN has dependent objects.
…. USER FLOWS_010600 has dependent objects.
.
Query the DBA_DEPENDENCIES view to obtain more information about the dependencies. For example:
SELECT * FROM DBA_DEPENDENCIES
WHERE referenced_name IN (‘UTL_TCP’,’UTL_SMTP’,’UTL_MAIL’,’UTL_HTTP’,’UTL_INADDR’,’DBMS_LDAP’)
  AND owner NOT IN (‘SYS’,’PUBLIC’,’ORDPLUGINS’);
Prepare post-upgrade scripts now to make the scripts available for use in the test environment. This ensures the new access controls are part of your upgrade testing.
To configure network access control lists (ACLs) in the database so that these packages can work as they did in prior releases, see the example script provided in “Configuring Fine-Grained Access to External Network Services After Upgrading Oracle Database”. This script shows how to use the DBMS_NETWORK_ACL_ADMIN package to create, assign, and add privileges to the access control list.
After the upgrade, you must grant the specific required privileges. Access is based on the usage in the original database.

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


Decreasing Downtime for Gathering Optimizer Statistics (Optional)
When upgrading to the new Oracle Database 11g release, optimizer statistics are collected for dictionary tables that lack statistics. This statistics collection process can be time consuming for databases with a large number of dictionary tables, but statistics gathering only occurs for those tables that lack statistics or are significantly changed during the upgrade.
To decrease the amount of downtime incurred when collecting statistics 
  • Collect statistics before performing the actual database upgrade. Oracle recommends that you use the DBMS_STATS.GATHER_DICTIONARY_STATSprocedure to gather these statistics. For example, you can enter the following SQL statement:
    EXEC DBMS_STATS.GATHER_DICTIONARY_STATS;
################################################################################

Ensuring That No Files Are in Backup Mode

Files must not be in backup mode when performing the upgrade; therefore, you must wait until backups are completed. You can query the system to see a list of any files in backup mode and then take appropriate action by either waiting for the backup to complete, or by aborting any backups that are not needed.
To get a list of files in backup mode
  • Issue the following statement:
    SQL> SELECT * FROM v$backup WHERE status != 'NOT ACTIVE';

Resolving Outstanding Distributed Transactions

You must resolve outstanding distributed transactions before performing the upgrade. You can do this by first querying to see any pending transactions, and then committing the transactions. You must wait until all pending distributed transactions have been committed.
To resolve outstanding distributed transactions
  1. Issue the following statement:
    SQL> SELECT * FROM dba_2pc_pending;
  2. If the query in the previous step returns any rows, then issue the following statements:
    SQL> SELECT local_tran_id FROM dba_2pc_pending;
    SQL> EXECUTE dbms_transaction.purge_lost_db_entry('');
    SQL> COMMIT;

Synchronizing a Standby Database with the Primary Database

If a standby database exists, then you must synchronize it with the primary database.
To check if a standby database exists and to synchronize it 
  1. Issue the following query:
    SQL> SELECT SUBSTR(value,INSTR(value,'=',INSTR(UPPER(value),'SERVICE'))+1)
    FROM v$parameter
    WHERE name LIKE 'log_archive_dest%' AND UPPER(value) LIKE 'SERVICE%';
  2. If the query in the previous step returns a row, then synchronize the standby database with the primary database.
    • Make sure all the logs are transported to the standby server after a final log switch in the primary.
    • Start the recovery of the standby database with the NODELAY option.

Purging the Database Recycle Bin

The database recycle bin must be empty before you begin the upgrade process. You use the PURGE statement to remove items and their associated objects from the recycle bin and release their storage space.
To empty the database recycle bin
  • Issue the following command:
    SQL> PURGE dba_recyclebin
####################################################################

From newly installed home 11.2.0.3 invoke DBUA (Database Upgrade Assistant)

dbua
On Windows operating systems, select 
Start > 
Programs > 
Oracle – HOME_NAME > 
Configuration and Migration Tools > 

Database Upgrade Assistant.



Deleting obslete rman backup information from controlfile

We took database backup disk including controlfile from production server to refresh a staging server for application testing purpose. upon restore when we checked database backups.

RMAN> delete backup completed before ‘sysdate-7’;

backup piece handle=D:\RMANBACKUP\DB\HOMEDB_DB_C1NVIH3N_5505_1 RECID=5387 STAMP=804865144
deleted backup piece
backup piece handle=D:\RMANBACKUP\DB\HOMEDB_DB_C2NVIH8J_5506_1 RECID=5388 STAMP=804865300
deleted backup piece
backup piece handle=D:\RMANBACKUP\DB\HOMEDB_DB_C3NVIHH7_5507_1 RECID=5389 STAMP=804865576
deleted backup piece
backup piece handle=D:\RMANBACKUP\DB\HOMEDB_DB_C4NVIHL5_5508_1 RECID=5390 STAMP=804865701
deleted backup piece
backup piece handle=D:\RMANBACKUP\AR\AL_C7NVIHR7_1_1 RECID=5393 STAMP=804865895
deleted backup piece
backup piece handle=D:\RMANBACKUP\AR\AL_C8NVIHRC_1_1 RECID=5394 STAMP=804865900
deleted backup piece
backup piece handle=D:\RMANBACKUP\AR\AL_C9NVIHRR_1_1 RECID=5395 STAMP=804865916
deleted backup piece
backup piece handle=D:\RMANBACKUP\DB\HOMEDB_DB_CCNVIJQP_5516_1 RECID=5397 STAMP=804867929
deleted backup piece
backup piece handle=D:\RMANBACKUP\DB\HOMEDB_DB_CDNVIK0I_5517_1 RECID=5398 STAMP=804868115
deleted backup piece
backup piece handle=D:\RMANBACKUP\DB\HOMEDB_DB_CENVIK5E_5518_1 RECID=5399 STAMP=804868272
deleted backup piece
backup piece handle=D:\RMANBACKUP\DB\HOMEDB_DB_CFNVIKE2_5519_1 RECID=5400 STAMP=804868547
deleted backup piece
backup piece handle=D:\RMANBACKUP\DB\HOMEDB_DB_CGNVIKI0_5520_1 RECID=5401 STAMP=804868673
deleted backup piece
backup piece handle=D:\RMANBACKUP\DB\HOMEDB_DB_CHNVIKN6_5521_1 RECID=5402 STAMP=804868841
deleted backup piece
backup piece handle=D:\RMANBACKUP\CONTROLFILE\CONTORLFILE_C-1547250382-20130116-03 RECID=5403 STAMP=804868847
deleted backup piece
backup piece handle=D:\RMANBACKUP\DB\AL_CJNVIKO6_1_1 RECID=5404 STAMP=804868870
deleted backup piece
backup piece handle=D:\RMANBACKUP\CONTROLFILE\CONTORLFILE_C-1547250382-20130116-04 RECID=5405 STAMP=804868878
Deleted 17 objects

RMAN> list backup summary;

This is output

————————————————————————————————————
List of Backups
===============
Key     TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag
——- — — – ———– ————— ——- ——- ———- —
5186    B  F  A SBT_TAPE    26-DEC-12       1       1       NO         TAG20121226T070014
5187    B  F  A SBT_TAPE    26-DEC-12       1       1       NO         TAG20121226T070014
5188    B  F  A SBT_TAPE    26-DEC-12       1       1       NO         TAG20121226T070014
5189    B  F  A SBT_TAPE    26-DEC-12       1       1       NO         TAG20121226T070014
5190    B  F  A SBT_TAPE    26-DEC-12       1       1       NO         TAG20121226T070014
5191    B  F  A SBT_TAPE    26-DEC-12       1       1       NO         TAG20121226T072051
5192    B  A  A SBT_TAPE    26-DEC-12       1       1       NO         TAG20121226T072144
5193    B  A  A SBT_TAPE    26-DEC-12       1       1       NO         TAG20121226T072144
5194    B  F  A SBT_TAPE    26-DEC-12       1       1       NO         TAG20121226T072456
5195    B  F  A SBT_TAPE    27-DEC-12       1       1       NO         TAG20121227T070010
5196    B  F  A SBT_TAPE    27-DEC-12       1       1       NO         TAG20121227T070010
5197    B  F  A SBT_TAPE    27-DEC-12       1       1       NO         TAG20121227T070010
5198    B  F  A SBT_TAPE    27-DEC-12       1       1       NO         TAG20121227T070010
5199    B  F  A SBT_TAPE    27-DEC-12       1       1       NO         TAG20121227T070010
5200    B  F  A SBT_TAPE    27-DEC-12       1       1       NO         TAG20121227T071808
5201    B  A  A SBT_TAPE    27-DEC-12       1       1       NO         TAG20121227T071907
5202    B  F  A SBT_TAPE    27-DEC-12       1       1       NO         TAG20121227T072027
5203    B  F  A SBT_TAPE    28-DEC-12       1       1       NO         TAG20121228T070010
5204    B  F  A SBT_TAPE    28-DEC-12       1       1       NO         TAG20121228T070010
5205    B  F  A SBT_TAPE    28-DEC-12       1       1       NO         TAG20121228T070010
5206    B  F  A SBT_TAPE    28-DEC-12       1       1       NO         TAG20121228T070010
5207    B  F  A SBT_TAPE    28-DEC-12       1       1       NO         TAG20121228T070010
5208    B  F  A SBT_TAPE    28-DEC-12       1       1       NO         TAG20121228T071708
5209    B  A  A SBT_TAPE    28-DEC-12       1       1       NO         TAG20121228T071809
5210    B  F  A SBT_TAPE    28-DEC-12       1       1       NO         TAG20121228T071927
5211    B  F  A SBT_TAPE    29-DEC-12       1       1       NO         TAG20121229T070010
5212    B  F  A SBT_TAPE    29-DEC-12       1       1       NO         TAG20121229T070010
5213    B  F  A SBT_TAPE    29-DEC-12       1       1       NO         TAG20121229T070010
5214    B  F  A SBT_TAPE    29-DEC-12       1       1       NO         TAG20121229T070010
5215    B  F  A SBT_TAPE    29-DEC-12       1       1       NO         TAG20121229T070010
5216    B  F  A SBT_TAPE    29-DEC-12       1       1       NO         TAG20121229T071947
5217    B  A  A SBT_TAPE    29-DEC-12       1       1       NO         TAG20121229T072047
5218    B  F  A SBT_TAPE    29-DEC-12       1       1       NO         TAG20121229T072216
5219    B  F  A SBT_TAPE    30-DEC-12       1       1       NO         TAG20121230T070011
5220    B  F  A SBT_TAPE    30-DEC-12       1       1       NO         TAG20121230T070011
5221    B  F  A SBT_TAPE    30-DEC-12       1       1       NO         TAG20121230T070011
5222    B  F  A SBT_TAPE    30-DEC-12       1       1       NO         TAG20121230T070011
5223    B  F  A SBT_TAPE    30-DEC-12       1       1       NO         TAG20121230T070011
5224    B  F  A SBT_TAPE    30-DEC-12       1       1       NO         TAG20121230T075122
5225    B  A  A SBT_TAPE    30-DEC-12       1       1       NO         TAG20121230T075223
5226    B  F  A SBT_TAPE    30-DEC-12       1       1       NO         TAG20121230T075310
5227    B  F  A SBT_TAPE    31-DEC-12       1       1       NO         TAG20121231T070447
5228    B  F  A SBT_TAPE    31-DEC-12       1       1       NO         TAG20121231T070447
5229    B  F  A SBT_TAPE    31-DEC-12       1       1       NO         TAG20121231T070447
5230    B  F  A SBT_TAPE    31-DEC-12       1       1       NO         TAG20121231T070447
5231    B  F  A SBT_TAPE    31-DEC-12       1       1       NO         TAG20121231T070447
5232    B  F  A SBT_TAPE    31-DEC-12       1       1       NO         TAG20121231T081640
5233    B  A  A SBT_TAPE    31-DEC-12       1       1       NO         TAG20121231T081735
5234    B  F  A SBT_TAPE    31-DEC-12       1       1       NO         TAG20121231T081833
5235    B  F  A SBT_TAPE    01-JAN-13       1       1       NO         TAG20130101T070007
5236    B  F  A SBT_TAPE    01-JAN-13       1       1       NO         TAG20130101T070007
5237    B  F  A SBT_TAPE    01-JAN-13       1       1       NO         TAG20130101T070007
5238    B  F  A SBT_TAPE    01-JAN-13       1       1       NO         TAG20130101T070007
5239    B  F  A SBT_TAPE    01-JAN-13       1       1       NO         TAG20130101T070007
5240    B  F  A SBT_TAPE    01-JAN-13       1       1       NO         TAG20130101T072128
5241    B  A  A SBT_TAPE    01-JAN-13       1       1       NO         TAG20130101T072228
5242    B  F  A SBT_TAPE    01-JAN-13       1       1       NO         TAG20130101T072336
5243    B  F  A SBT_TAPE    02-JAN-13       1       1       NO         TAG20130102T070007
5244    B  F  A SBT_TAPE    02-JAN-13       1       1       NO         TAG20130102T070007
5245    B  F  A SBT_TAPE    02-JAN-13       1       1       NO         TAG20130102T070007
5246    B  F  A SBT_TAPE    02-JAN-13       1       1       NO         TAG20130102T070007
5247    B  F  A SBT_TAPE    02-JAN-13       1       1       NO         TAG20130102T070007
5248    B  F  A SBT_TAPE    02-JAN-13       1       1       NO         TAG20130102T071843
5249    B  A  A SBT_TAPE    02-JAN-13       1       1       NO         TAG20130102T071938
5250    B  F  A SBT_TAPE    02-JAN-13       1       1       NO         TAG20130102T072035
5251    B  F  A SBT_TAPE    03-JAN-13       1       1       NO         TAG20130103T070011
5252    B  F  A SBT_TAPE    03-JAN-13       1       1       NO         TAG20130103T070011
5253    B  F  A SBT_TAPE    03-JAN-13       1       1       NO         TAG20130103T070011
5254    B  F  A SBT_TAPE    03-JAN-13       1       1       NO         TAG20130103T070011
5255    B  F  A SBT_TAPE    03-JAN-13       1       1       NO         TAG20130103T070011
5256    B  F  A SBT_TAPE    03-JAN-13       1       1       NO         TAG20130103T071810
5257    B  A  A SBT_TAPE    03-JAN-13       1       1       NO         TAG20130103T071909
5258    B  F  A SBT_TAPE    03-JAN-13       1       1       NO         TAG20130103T072028
5259    B  F  A SBT_TAPE    04-JAN-13       1       1       NO         TAG20130104T070008
5260    B  F  A SBT_TAPE    04-JAN-13       1       1       NO         TAG20130104T070008
5261    B  F  A SBT_TAPE    04-JAN-13       1       1       NO         TAG20130104T070008
5262    B  F  A SBT_TAPE    04-JAN-13       1       1       NO         TAG20130104T070008
5263    B  F  A SBT_TAPE    04-JAN-13       1       1       NO         TAG20130104T070008
5264    B  F  A SBT_TAPE    04-JAN-13       1       1       NO         TAG20130104T072116
5265    B  A  A SBT_TAPE    04-JAN-13       1       1       NO         TAG20130104T072218
5266    B  F  A SBT_TAPE    04-JAN-13       1       1       NO         TAG20130104T072328
5267    B  F  A SBT_TAPE    05-JAN-13       1       1       NO         TAG20130105T070010
5268    B  F  A SBT_TAPE    05-JAN-13       1       1       NO         TAG20130105T070010
5269    B  F  A SBT_TAPE    05-JAN-13       1       1       NO         TAG20130105T070010
5270    B  F  A SBT_TAPE    05-JAN-13       1       1       NO         TAG20130105T070010
5271    B  F  A SBT_TAPE    05-JAN-13       1       1       NO         TAG20130105T070010
5272    B  F  A SBT_TAPE    05-JAN-13       1       1       NO         TAG20130105T072519
5273    B  A  A SBT_TAPE    05-JAN-13       1       1       NO         TAG20130105T072618
5274    B  F  A SBT_TAPE    05-JAN-13       1       1       NO         TAG20130105T072725
5275    B  F  A SBT_TAPE    06-JAN-13       1       1       NO         TAG20130106T070007
5276    B  F  A SBT_TAPE    06-JAN-13       1       1       NO         TAG20130106T070007
5277    B  F  A SBT_TAPE    06-JAN-13       1       1       NO         TAG20130106T070007
5278    B  F  A SBT_TAPE    06-JAN-13       1       1       NO         TAG20130106T070007
5279    B  F  A SBT_TAPE    06-JAN-13       1       1       NO         TAG20130106T070007
5280    B  F  A SBT_TAPE    06-JAN-13       1       1       NO         TAG20130106T071954
5281    B  A  A SBT_TAPE    06-JAN-13       1       1       NO         TAG20130106T072057
5282    B  F  A SBT_TAPE    06-JAN-13       1       1       NO         TAG20130106T072145
5283    B  F  A SBT_TAPE    07-JAN-13       1       1       NO         TAG20130107T070010
5284    B  F  A SBT_TAPE    07-JAN-13       1       1       NO         TAG20130107T070010
5285    B  F  A SBT_TAPE    07-JAN-13       1       1       NO         TAG20130107T070010
5286    B  F  A SBT_TAPE    07-JAN-13       1       1       NO         TAG20130107T070010
5287    B  F  A SBT_TAPE    07-JAN-13       1       1       NO         TAG20130107T070010
5288    B  F  A SBT_TAPE    07-JAN-13       1       1       NO         TAG20130107T072130
5289    B  A  A SBT_TAPE    07-JAN-13       1       1       NO         TAG20130107T072229
5290    B  F  A SBT_TAPE    07-JAN-13       1       1       NO         TAG20130107T072326
5291    B  F  A SBT_TAPE    08-JAN-13       1       1       NO         TAG20130108T080443
5292    B  F  A SBT_TAPE    08-JAN-13       1       1       NO         TAG20130108T080443
5293    B  F  A SBT_TAPE    08-JAN-13       1       1       NO         TAG20130108T080443
5294    B  F  A SBT_TAPE    08-JAN-13       1       1       NO         TAG20130108T080443
5295    B  F  A SBT_TAPE    08-JAN-13       1       1       NO         TAG20130108T080443
5296    B  F  A SBT_TAPE    08-JAN-13       1       1       NO         TAG20130108T082525
5297    B  A  A SBT_TAPE    08-JAN-13       1       1       NO         TAG20130108T082639
5298    B  F  A SBT_TAPE    08-JAN-13       1       1       NO         TAG20130108T082756
5299    B  F  A SBT_TAPE    09-JAN-13       1       1       NO         TAG20130109T070013
5300    B  F  A SBT_TAPE    09-JAN-13       1       1       NO         TAG20130109T070013
5301    B  F  A SBT_TAPE    09-JAN-13       1       1       NO         TAG20130109T070013
5302    B  F  A SBT_TAPE    09-JAN-13       1       1       NO         TAG20130109T070013
5303    B  F  A SBT_TAPE    09-JAN-13       1       1       NO         TAG20130109T070013
5304    B  F  A SBT_TAPE    09-JAN-13       1       1       NO         TAG20130109T071821
5305    B  A  A SBT_TAPE    09-JAN-13       1       1       NO         TAG20130109T071922
5306    B  F  A SBT_TAPE    09-JAN-13       1       1       NO         TAG20130109T072037
5314    B  F  A SBT_TAPE    10-JAN-13       1       1       NO         TAG20130110T070007
5315    B  F  A SBT_TAPE    10-JAN-13       1       1       NO         TAG20130110T070007
5316    B  F  A SBT_TAPE    10-JAN-13       1       1       NO         TAG20130110T070007
5317    B  F  A SBT_TAPE    10-JAN-13       1       1       NO         TAG20130110T070007
5318    B  F  A SBT_TAPE    10-JAN-13       1       1       NO         TAG20130110T070007
5319    B  F  A SBT_TAPE    10-JAN-13       1       1       NO         TAG20130110T071756
5320    B  A  A SBT_TAPE    10-JAN-13       1       1       NO         TAG20130110T071900
5321    B  F  A SBT_TAPE    10-JAN-13       1       1       NO         TAG20130110T072009
5322    B  F  A SBT_TAPE    11-JAN-13       1       1       NO         TAG20130111T070007
5323    B  F  A SBT_TAPE    11-JAN-13       1       1       NO         TAG20130111T070007
5324    B  F  A SBT_TAPE    11-JAN-13       1       1       NO         TAG20130111T070007
5325    B  F  A SBT_TAPE    11-JAN-13       1       1       NO         TAG20130111T070007
5326    B  F  A SBT_TAPE    11-JAN-13       1       1       NO         TAG20130111T070007
5327    B  F  A SBT_TAPE    11-JAN-13       1       1       NO         TAG20130111T071725
5328    B  A  A SBT_TAPE    11-JAN-13       1       1       NO         TAG20130111T071825
5329    B  F  A SBT_TAPE    11-JAN-13       1       1       NO         TAG20130111T071922
5330    B  F  A SBT_TAPE    12-JAN-13       1       1       NO         TAG20130112T070007
5331    B  F  A SBT_TAPE    12-JAN-13       1       1       NO         TAG20130112T070007
5332    B  F  A SBT_TAPE    12-JAN-13       1       1       NO         TAG20130112T070007
5333    B  F  A SBT_TAPE    12-JAN-13       1       1       NO         TAG20130112T070007
5334    B  F  A SBT_TAPE    12-JAN-13       1       1       NO         TAG20130112T070007
5335    B  F  A SBT_TAPE    12-JAN-13       1       1       NO         TAG20130112T072235
5336    B  A  A SBT_TAPE    12-JAN-13       1       1       NO         TAG20130112T072335
5337    B  F  A SBT_TAPE    12-JAN-13       1       1       NO         TAG20130112T072432
5338    B  F  A SBT_TAPE    13-JAN-13       1       1       NO         TAG20130113T070008
5339    B  F  A SBT_TAPE    13-JAN-13       1       1       NO         TAG20130113T070008
5340    B  F  A SBT_TAPE    13-JAN-13       1       1       NO         TAG20130113T070008
5341    B  F  A SBT_TAPE    13-JAN-13       1       1       NO         TAG20130113T070008
5342    B  F  A SBT_TAPE    13-JAN-13       1       1       NO         TAG20130113T070008
5343    B  F  A SBT_TAPE    13-JAN-13       1       1       NO         TAG20130113T072006
5344    B  A  A SBT_TAPE    13-JAN-13       1       1       NO         TAG20130113T072055
5345    B  F  A SBT_TAPE    13-JAN-13       1       1       NO         TAG20130113T072205
5346    B  F  A SBT_TAPE    14-JAN-13       1       1       NO         TAG20130114T070103
5347    B  F  A SBT_TAPE    14-JAN-13       1       1       NO         TAG20130114T070103
5348    B  F  A SBT_TAPE    14-JAN-13       1       1       NO         TAG20130114T070103
5349    B  F  A SBT_TAPE    14-JAN-13       1       1       NO         TAG20130114T070103
5350    B  F  A SBT_TAPE    14-JAN-13       1       1       NO         TAG20130114T070103
5351    B  F  A SBT_TAPE    14-JAN-13       1       1       NO         TAG20130114T072201
5352    B  A  A SBT_TAPE    14-JAN-13       1       1       NO         TAG20130114T072300
5353    B  F  A SBT_TAPE    14-JAN-13       1       1       NO         TAG20130114T072520

RMAN> exit

Recovery Manager complete.

————————————————————————————————————
Still there are old backups in inventory because we don’t have sbt_tape configured on this server so we cannot delete these backups from inventory. To delete info from controlfile we need to recreate controlfile.

————————————————————————————————————

C:\Users\FARHAT.HOME>sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Mon Jan 21 07:48:59 2013

Copyright (c) 1982, 2011, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 – 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> alter database backup controlfile to trace as ‘d:\control22.txt’;

Database altered.

SQL> show parameter control

NAME                                 TYPE        VALUE
———————————— ———– ——————————
control_file_record_keep_time        integer     7
control_files                        string      D:\APP\FARHAT\ORADATA\HOMEDB\CO
                                                 NTROL01.CTL
control_management_pack_access       string      DIAGNOSTIC+TUNING

shutdown the database

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

Start DB in nomount state

SQL> startup nomount;
ORACLE instance started.

Total System Global Area 1553379328 bytes
Fixed Size                  2255464 bytes
Variable Size            1224738200 bytes
Database Buffers          318767104 bytes
Redo Buffers                7618560 bytes

SQL> show parameter control

NAME                                 TYPE        VALUE
———————————— ———– ——————————
control_file_record_keep_time        integer     7
control_files                        string      D:\APP\FARHAT\ORADATA\HOMEDB\CO
                                                 NTROL01.CTL
control_management_pack_access       string      DIAGNOSTIC+TUNING
SQL> show parameter spfile

NAME                                 TYPE        VALUE
———————————— ———– ——————————
spfile                               string

copy these lines from output file created with alter database backup controlfile to trace command and paste in sqlplus prompt

SQL> CREATE CONTROLFILE REUSE DATABASE “HOMEDB” NORESETLOGS  ARCHIVELOG
  2      MAXLOGFILES 192
  3      MAXLOGMEMBERS 3
  4      MAXDATAFILES 1024
  5      MAXINSTANCES 32
  6      MAXLOGHISTORY 5840
  7  LOGFILE
  8    GROUP 1 ‘D:\APP\FARHAT\FAST_RECOVERY_AREA\HOMEDB\ONLINELOG\O1_MF_1_8HB4BG1H_.LOG’  SIZE 500M BLOCKSIZE 512,
  9    GROUP 2 ‘D:\APP\FARHAT\FAST_RECOVERY_AREA\HOMEDB\ONLINELOG\O1_MF_2_8HB4767Z_.LOG’  SIZE 500M BLOCKSIZE 512,
 10    GROUP 3 ‘D:\APP\FARHAT\FAST_RECOVERY_AREA\HOMEDB\ONLINELOG\O1_MF_3_8HB4BLLD_.LOG’  SIZE 500M BLOCKSIZE 512,
 11    GROUP 4 ‘D:\APP\FARHAT\FAST_RECOVERY_AREA\HOMEDB\ONLINELOG\O1_MF_4_8HB4B33G_.LOG’  SIZE 500M BLOCKSIZE 512
 12  — STANDBY LOGFILE
 13  DATAFILE
 14    ‘D:\APP\FARHAT\ORADATA\HOMEDB\SYSTEM.256.770482167’,
 15    ‘D:\APP\FARHAT\ORADATA\HOMEDB\SYSAUX.257.770482167’,
 16    ‘D:\APP\FARHAT\ORADATA\HOMEDB\UNDOTBS1.258.770482167’,
 17    ‘D:\APP\FARHAT\ORADATA\HOMEDB\USERS.259.770482167’,
 18    ‘D:\APP\FARHAT\ORADATA\HOMEDB\EXAMPLE.264.770482273’,
 19    ‘D:\APP\FARHAT\ORADATA\HOMEDB\UNDOTBS2.265.770482381’,
 20    ‘D:\APP\FARHAT\ORADATA\HOMEDB\HOMELOG01.DBF’,
 21    ‘D:\APP\FARHAT\ORADATA\HOMEDB\TEST_NETBKUP.DBF’,
 22    ‘D:\APP\FARHAT\ORADATA\HOMEDB\RECOP1.DBF’,
 23    ‘D:\APP\FARHAT\ORADATA\HOMEDB\HOMELOG02.DBF’,
 24    ‘D:\APP\FARHAT\ORADATA\HOMEDB\HOME_TS01.DBF’,
 25    ‘D:\APP\FARHAT\ORADATA\HOMEDB\HOME_TS02.DBF’,
 26    ‘D:\APP\FARHAT\ORADATA\HOMEDB\HOME_TS03.DBF’,
 27    ‘D:\APP\FARHAT\ORADATA\HOMEDB\HOME_TS04.DBF’,
 28    ‘D:\APP\FARHAT\ORADATA\HOMEDB\HOME_TS05.DBF’,
 29    ‘D:\APP\FARHAT\ORADATA\HOMEDB\UNDOTBS1.278.770746419’,
 30    ‘D:\APP\FARHAT\ORADATA\HOMEDB\UNDOTBS2.279.770746495’
 31  CHARACTER SET AR8ISO8859P6
 32  ;

Control file created.

SQL> alter database open;

Database altered.

SQL>