Dec 2, 2009

Hiding Passwords When Connecting to Databases

To connect to RMAN from the operating system command line and hide authentication information, you must first start RMAN and then perform either of the following actions:
  • Run the CONNECT commands at the RMAN prompt
  • Run a command file at the RMAN prompt that contains the connection information. You can create execute-only privileges on the command file.
For example, if you are running RMAN in an UNIX environment, then you can use the following procedure:
1.Start RMAN without connecting to any databases:
% rman
  1. Place the connection information in a text file. For example, place the following lines in a file called connect.rmn:
CONNECT TARGET SYS/oracle@trgt 
CONNECT CATALOG rman/cat@catdb
  1. Change the permissions on the connect script so that everyone can execute the script but only the desired users have read access. For example, enter:
% chmod 711 connect.rmn
  1. Run the script from the RMAN prompt to connect to the target and catalog databases. For example:
RMAN> @connect.rmn

Automatic TSPITR in 10G RMAN

RMAN automatic Tablespace Point-In-Time Recovery ( TSPITR) enables you to quickly recover one or more tablespaces in an Oracle database to an earlier time, without affecting the state of the rest of the tablespaces and other objects in the database.

 When performing fully automated TSPITR, letting RMAN manage the entire process. There are only two requirements which we need to specify manually.
1.  Auxiliary destination for RMAN to use for the auxiliary set datafiles and other files for the auxiliary instance.  
2. Configure any channels required for the TSPITR on the target instance.
Note: The auxiliary instance will use the same channel configuration as the target instance when performing the TSPITR.

Setting up the environment:
 1. Created a tablespace test  and a table in that tablespace
   
   
SQL> Create tablespace test datafile 'D:\BACKUP\TEST.DBF' size 2 M;
Tablespace created

SQL> create table test001 (id number) tablespace test;
Table created.

SQL> insert into test001 values(100);
1 row created.

SQL> commit;
Commit complete.

SQL> select * from test001;
ID
----------
100

2. Checked the CURRENT LOG Sequence
SQL> select SEQUENCE# from v$log where status='CURRENT';

SEQUENCE#
----------
135

## 135 is my current log sequence
3. Taken the backup of the database and current controlfile using RMAN.

4. Done few log switch and droped that table.
 
SQL> drop table test001;        Table dropped.

SQL> select SEQUENCE# from v$log where status='CURRENT';

 SEQUENCE#
----------
       139
   ## Table dropped in log sequence 139.
   So TSPITR until log sequence 138 will give that table back.

Note: UNTIL TIME TSPITR syntax is :
RMAN> recover tablespace "TEST" until time "23-SEP-2005 10:00:00','DD-MON-YYYY HH24:MI:SS"
      auxiliary destination 'D:\BAckup\temp';

 
True test starts:
-----------------

1. Connect to RMAN
   C:> rman target / catalog rman/rman

2. Need to Do A TSPITR until log sequence 138.
  Auxiliary destination  is D:\Backup\temp
 RMAN> recover tablespace "TEST"  until logseq 138 thread 1
       auxiliary destination 'D:\Backup\temp';
Starting recover at 20-SEP-05
    starting full resync of recovery catalog
    full resync complete
    allocated channel: ORA_DISK_1
    channel ORA_DISK_1: sid=26 devtype=DISK
   
    Creating automatic instance, with SID='ljsA'
   
    initialization parameters used for automatic instance:
    db_name=AMAR
    compatible=10.2.0.1.0
    db_block_size=8192
    db_files=200
    db_unique_name=tspitr_AMAR_ljsA
    large_pool_size=1M
    shared_pool_size=110M
    #No auxiliary parameter file used
    db_create_file_dest=D:\BAckup\temp
    control_files=D:\BAckup\temp/cntrl_tspitr_AMAR_ljsA.f
   
   
    starting up automatic instance AMAR
   
    Oracle instance started
   
    Total System Global Area     201326592 bytes
   
    Fixed Size                     1247044 bytes
    Variable Size                146802876 bytes
    Database Buffers              50331648 bytes
    Redo Buffers                   2945024 bytes
    Automatic instance created
   
    contents of Memory Script:
    {
    # set the until clause
    set until  logseq 138 thread 1;
    # restore the controlfile
    restore clone controlfile;
    # mount the controlfile
    sql clone 'alter database mount clone database';
    # archive current online log for tspitr to a resent until time
    sql 'alter system archive log current';
    # avoid unnecessary autobackups for structural changes during TSPITR
    sql 'begin dbms_backup_restore.AutoBackupFlag(FALSE); end;';
    # resync catalog after controlfile restore
    resync catalog;
    }
    executing Memory Script
   
    executing command: SET until clause
   
    Starting restore at 20-SEP-05
    allocated channel: ORA_AUX_DISK_1
    channel ORA_AUX_DISK_1: sid=36 devtype=DISK
   
    channel ORA_AUX_DISK_1: starting datafile backupset restore
    channel ORA_AUX_DISK_1: restoring control file
    channel ORA_AUX_DISK_1: reading from backup piece
    +DATA/amar/backupset/2005_09_20/ncnnf0_tag20050920t105610_0.291.569501773
    channel ORA_AUX_DISK_1: restored backup piece 1
    piece handle=+DATA/amar/backupset/2005_09_20/ncnnf0_tag20050920t105610_0.291.569501773
    tag=TAG20050920T105610
    channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:15
    output filename=D:\BACKUP\TEMP\CNTRL_TSPITR_AMAR_LJSA.F
    Finished restore at 20-SEP-05
   
    sql statement: alter database mount clone database
    
    sql statement: alter system archive log current
   
    sql statement: begin dbms_backup_restore.AutoBackupFlag(FALSE); end;
   
    starting full resync of recovery catalog
    full resync complete
    released channel: ORA_DISK_1
    released channel: ORA_AUX_DISK_1
   
    contents of Memory Script:
    {
    # generated tablespace point-in-time recovery script
    # set the until clause
    set until  logseq 138 thread 1;
    plsql <<-- tspitr_2
    declare
      sqlstatement       varchar2(512);
      offline_not_needed exception;
      pragma exception_init(offline_not_needed, -01539);
    begin
      sqlstatement := 'alter tablespace '||  'TEST' ||' offline for recover';
      krmicd.writeMsg(6162, sqlstatement);
      krmicd.execSql(sqlstatement);
    exception
      when offline_not_needed then
        null;
    end; >>;
    # set an omf destination filename for restore
    set newname for clone datafile  1 to new;
    # set an omf destination filename for restore
    set newname for clone datafile  2 to new;
    # set an omf destination tempfile
    set newname for clone tempfile  1 to new;
    # set a destination filename for restore
    set newname for datafile  6 to
     "D:\BACKUP\TEST.DBF";
    # rename all tempfiles
    switch clone tempfile all;
    # restore the tablespaces in the recovery set plus the auxilliary tablespaces
    restore clone datafile  1, 2, 6;
    switch clone datafile all;
    #online the datafiles restored or flipped
    sql clone "alter database datafile  1 online";
    #online the datafiles restored or flipped
    sql clone "alter database datafile  2 online";
    #online the datafiles restored or flipped
    sql clone "alter database datafile  6 online";
    # make the controlfile point at the restored datafiles, then recover them
    recover clone database tablespace  "TEST", "SYSTEM", "UNDOTBS1" delete archivelog;
    alter clone database open resetlogs;
    # PLUG HERE the creation of a temporary tablespace if export fails due to lack
 
   # of temporary space.
    # For example in Unix these two lines would do that:
    #sql clone "create tablespace aux_tspitr_tmp
    #           datafile ''/tmp/aux_tspitr_tmp.dbf'' size 500K";
    }
    executing Memory Script
   
    executing command: SET until clause
   
    sql statement: alter tablespace TEST offline for recover
   
    executing command:
SET NEWNAME
   
    executing command: SET NEWNAME
   
    executing command: SET NEWNAME
   
    executing
command: SET NEWNAME
   
    renamed temporary file 1 to D:\BACKUP\TEMP\TSPITR_A\DATAFILE\O1_MF_TEMP_%U_.TMP in control file
 
  
    Starting restore at 20-SEP-05
    allocated channel: ORA_AUX_DISK_1
    channel ORA_AUX_DISK_1: sid=39 devtype=DISK
 
  
    channel ORA_AUX_DISK_1: starting datafile backupset restore
    channel ORA_AUX_DISK_1: specifying datafile(s) to
restore from backup set
    restoring datafile 00001 to D:\BACKUP\TEMP\TSPITR_A\DATAFILE\O1_MF_SYSTEM_%U_.DBF
    restoring
datafile 00002 to D:\BACKUP\TEMP\TSPITR_A\DATAFILE\O1_MF_UNDOTBS1_%U_.DBF
    restoring datafile 00006 to D:\BACKUP\TEST.DBF
 
   channel ORA_AUX_DISK_1: reading from backup piece
    +DATA/amar/backupset/2005_09_20/nnndf0_tag20050920t105434_0.295.569501677
 
   channel ORA_AUX_DISK_1: restored backup piece 1
    piece handle=+DATA/amar/backupset/2005_09_20/nnndf0_tag20050920t105434_0.295.569501677
 
   tag=TAG20050920T105434
    channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:06
    Finished restore at 20-SEP-05
 
  
    datafile 1 switched to datafile copy
    input datafile copy recid=4 stamp=569503256
    filename=D:\BACKUP\TEMP\TSPITR_A\DATAFILE\O1_MF_SYSTEM_1LZ8QZF1_.DBF
 
   datafile 2 switched to datafile copy
    input datafile copy recid=5 stamp=569503256
    filename=D:\BACKUP\TEMP\TSPITR_A\DATAFILE\O1_MF_UNDOTBS1_1LZ8QZN7_.DBF
 
  
    sql statement: alter database datafile  1 online
   
    sql statement: alter database datafile  2 online
 
  
    sql statement: alter database datafile  6 online
   
    Starting recover at 20-SEP-05
    using channel ORA_AUX_DISK_1
 
  
    starting media recovery
   
    archive log thread 1 sequence 134 is already on disk as file
    +DATA/amar/archivelog/2005_09_20/thread_1_seq_134.292.569501807
 
   archive log thread 1 sequence 135 is already on disk as file
    +DATA/amar/archivelog/2005_09_20/thread_1_seq_135.280.569501919
 
   archive log thread 1 sequence 136 is already on disk as file
    +DATA/amar/archivelog/2005_09_20/thread_1_seq_136.283.569501925
 
   archive log thread 1 sequence 137 is already on disk as file
    +DATA/amar/archivelog/2005_09_20/thread_1_seq_137.297.569501931
 
   archive log filename=+DATA/amar/archivelog/2005_09_20/thread_1_seq_134.292.569501807 thread=1
    sequence=134
    archive
log filename=+DATA/amar/archivelog/2005_09_20/thread_1_seq_135.280.569501919 thread=1
    sequence=135
    archive log filename=+DATA/amar/archivelog/2005_09_20/thread_1_seq_136.283.569501925
thread=1
    sequence=136
    archive log filename=+DATA/amar/archivelog/2005_09_20/thread_1_seq_137.297.569501931 thread=1
 
   sequence=137
    media recovery complete, elapsed time: 00:00:06
    Finished recover at 20-SEP-05
   
    database
opened
   
    contents of Memory Script:
    {
    # export the tablespaces in the recovery set
    host 'exp userid
 
   =\"/@(DESCRIPTION=(ADDRESS=(PROTOCOL=beq)(PROGRAM=oracle)(ARGV0=oracleljsA)(ARGS=^'(DESCRIPTION=(LO
    AL=YES)(ADDRESS=(PROTOCOL=beq)))^')(ENVS=^'ORACLE_SID=ljsA^'))(CONNECT_DATA=(SID=ljsA))) as
    sysdba\" point_in_time_recover=y tablespaces=
     TEST file=
    tspitr_a.dmp';
    # shutdown clone before import
    shutdown clone immediate
    # import the tablespaces in the recovery set
    host 'imp userid =\"/@ as sysdba\" point_in_time_recover=y file=
    tspitr_a.dmp';
    # online/offline the tablespace imported
    sql "alter tablespace  TEST online";
    sql "alter tablespace  TEST offline";
    # enable autobackups in case user does open resetlogs from RMAN after TSPITR
    sql 'begin dbms_backup_restore.AutoBackupFlag(TRUE); end;';
    # resync catalog
after tspitr finished
    resync catalog;
    }
    executing Memory Script
   
    Export: Release 10.2.0.1.0 -
Production on Tue Sep 20 11:21:40 2005
   
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
   
   
 
   Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Produc
    tion
    With the Partitioning, OLAP
and Data Mining options
    Export done in WE8MSWIN1252 character set and AL16UTF16 NCHAR character set
    server uses AL32UTF8
character set (possible charset conversion)
    Note: table data (rows) will not be exported
   
    About to export Tablespace
Point-in-time Recovery objects...
    For tablespace TEST ...
    . exporting cluster definitions
    . exporting table
definitions
    . . exporting table                        TEST001
    . exporting referential integrity constraints
 
  . exporting triggers
    . end point-in-time recovery
    Export terminated successfully without warnings.
   
 
  host command complete
   
    database closed
    database dismounted
    Oracle instance shut down
   
 
  Import: Release 10.2.0.1.0 - Production on Tue Sep 20 11:22:17 2005
   
    Copyright (c) 1982, 2005, Oracle.  All rights
reserved.
   
   
    Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Produc
    tion
 
   With the Partitioning, OLAP and Data Mining options
   
    Export file created by EXPORT:V10.02.01 via conventional path
 
   About to import Tablespace Point-in-time Recovery objects...
    import done in WE8MSWIN1252 character set and AL16UTF16 NCHAR
character set
    import server uses AL32UTF8 character set (possible charset conversion)
    . importing SYS's objects into
SYS
    . . importing table                      "TEST001"
    Import terminated successfully without warnings.
   
    host command complete
   
    sql statement: alter tablespace  TEST online
   
    sql statement: alter
tablespace  TEST offline
   
    sql statement: begin dbms_backup_restore.AutoBackupFlag(TRUE); end;
   
    starting
full resync of recovery catalog
    full resync complete
   
    Removing automatic instance
    Automatic instance
removed
    auxiliary instance file D:\BACKUP\TEMP\CNTRL_TSPITR_AMAR_LJSA.F deleted
    auxiliary instance file D:\BACKUP\TEMP\TSPITR_A\DATAFILE\O1_MF_SYSTEM_1LZ8QZF1_.DBF
deleted
    auxiliary instance file D:\BACKUP\TEMP\TSPITR_A\DATAFILE\O1_MF_UNDOTBS1_1LZ8QZN7_.DBF deleted
    auxiliary instance
file D:\BACKUP\TEMP\TSPITR_A\DATAFILE\O1_MF_TEMP_1LZ8TSLB_.TMP deleted
    auxiliary instance file D:\BACKUP\TEMP\TSPITR_A\ONLINELOG\O1_MF_1_1LZ8TM4X_.LOG
deleted
    auxiliary instance file D:\BACKUP\TEMP\TSPITR_A\ONLINELOG\O1_MF_2_1LZ8TMSL_.LOG deleted
    auxiliary instance file D:\BACKUP\TEMP\TSPITR_A\ONLINELOG\O1_MF_3_1LZ8TNCV_.LOG deleted
    Finished recover at 20-SEP-05

TSPITR recovery completed sucessfully.

3. Connect to target database using SQLPLUS and take the tablespace test Online.
 
  SQL>  select * from test001;
         ID
    ----------
         100
Recoverd the lost table using TSPITR. 

Dec 1, 2009

Migrating Oracle10g Database to Automatic Storage management (ASM)

Disable Block change tracking:

SQL> select * from v$block_change_tracking;


STATUS

----------
FILENAME
--------------------------------------------------------------------------------
     BYTES
----------
        DISABLED


If not disabled then, disble using this command.


SQL> ALTER DATABASE DISABLE BLOCK CHANGE TRACKING;

Database altered.

SQL>


Shutdown Database Cleanly:

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
     With the Partitioning, OLAP and Data Mining options



Create pfile and add/modify the below parameters:

[oracle@node1-pub oracle]$ sqlplus "/ as sysdba"


SQL*Plus: Release 10.2.0.1.0 - Production on Fri Jul 21 12:17:50 2006

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

Connected to an idle instance.

SQL> create pfile from spfile;

     File created.

Modify pfile with these parameters:


I have already created 2 ASM diskgroups DATA and FLASH.

*.control_files=(+DATA, +FLASH)
*.db_recovery_file_dest=+FLASH
*.db_recovery_file_dest_size=2147483648
*.db_create_file_dest=+DATA
*.db_create_online_log_dest_1=+FLASH
*.db_create_online_log_dest_2=+DATA -- optional if you want another online redo logs dest.

Create spfile back from modified pfile:


PS: take a copy of original spfile before you overwrite spfile using below command.

SQL> create spfile from pfile;


File created.


SQL> exit


Disconnected

Copy Database to ASM diskgroups using rman:

   (1) start the instance on NOMOUNT state
   (2) copy the controlfile from old location to ASM usin "resrore" rman command
   (3) mount the database
   (4) copy the datafiles to ASM disk group using rman "BACKUP AS COPY DATABASE" command
   (5) Switch database to COPY and open the database.

[oracle@node1-pub oracle]$ $ORACLE_HOME/bin/rman


Recovery Manager: Release 10.2.0.1.0 - Production on Fri Jul 21 10:03:10 2006

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

RMAN> connect target

connected to target database (not started)

RMAN> startup nomount

Oracle instance started

Total System Global Area     167772160 bytes

Fixed Size                     1218316 bytes
Variable Size                 83888372 bytes
Database Buffers              79691776 bytes
Redo Buffers                   2973696 bytes

RMAN> restore controlfile from '/home/oracle/oradata/db10g/control01.ctl';

Starting restore at 21-JUL-06
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=157 devtype=DISK

channel ORA_DISK_1: copied control file copy
output filename=+DATA/db10g/controlfile/backup.256.596369129
output filename=+FLASH/db10g/controlfile/backup.256.596369131
Finished restore at 21-JUL-06

RMAN> startup mount

database is already started
database mounted
released channel: ORA_DISK_1

RMAN> configure device type disk parallelism 4;

new RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK PARALLELISM 4 BACKUP TYPE TO BACKUPSET;
new RMAN configuration parameters are successfully stored

RMAN> BACKUP AS COPY DATABASE FORMAT '+DATA';

Starting backup at 21-JUL-06
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=152 devtype=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: sid=151 devtype=DISK
allocated channel: ORA_DISK_3
channel ORA_DISK_3: sid=150 devtype=DISK
allocated channel: ORA_DISK_4
channel ORA_DISK_4: sid=149 devtype=DISK
channel ORA_DISK_1: starting datafile copy
input datafile fno=00001 name=/home/oracle/oradata/db10g/system01.dbf
channel ORA_DISK_2: starting datafile copy
input datafile fno=00003 name=/home/oracle/oradata/db10g/sysaux01.dbf
channel ORA_DISK_3: starting datafile copy
input datafile fno=00002 name=/home/oracle/oradata/db10g/undotbs01.dbf
channel ORA_DISK_4: starting datafile copy
input datafile fno=00004 name=/home/oracle/oradata/db10g/users01.dbf
output filename=+DATA/db10g/datafile/undotbs1.259.596369341 tag=TAG20060721T100858 recid=2 stamp=596369352
channel ORA_DISK_3: datafile copy complete, elapsed time: 00:00:16
channel ORA_DISK_3: starting datafile copy
copying current control file
output filename=+DATA/db10g/datafile/users.260.596369341 tag=TAG20060721T100858 recid=1 stamp=596369350
channel ORA_DISK_4: datafile copy complete, elapsed time: 00:00:20
channel ORA_DISK_4: starting full datafile backupset
channel ORA_DISK_4: specifying datafile(s) in backupset
output filename=+DATA/db10g/controlfile/backup.261.596369361 tag=TAG20060721T100858 recid=3 stamp=596369364
channel ORA_DISK_3: datafile copy complete, elapsed time: 00:00:06
including current SPFILE in backupset
channel ORA_DISK_4: starting piece 1 at 21-JUL-06
channel ORA_DISK_4: finished piece 1 at 21-JUL-06
piece handle=+DATA/db10g/backupset/2006_07_21/nnsnf0_tag20060721t100858_0.262.596369369 tag=TAG20060721T100858 comment=NONE
channel ORA_DISK_4: backup set complete, elapsed time: 00:00:10
output filename=+DATA/db10g/datafile/sysaux.258.596369341 tag=TAG20060721T100858 recid=4 stamp=596369390
channel ORA_DISK_2: datafile copy complete, elapsed time: 00:01:05
output filename=+DATA/db10g/datafile/system.257.596369339 tag=TAG20060721T100858 recid=5 stamp=596369414
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:01:21
Finished backup at 21-JUL-06

RMAN> SWITCH DATABASE TO COPY;

datafile 1 switched to datafile copy "+DATA/db10g/datafile/system.257.596369339"
datafile 2 switched to datafile copy "+DATA/db10g/datafile/undotbs1.259.596369341"
datafile 3 switched to datafile copy "+DATA/db10g/datafile/sysaux.258.596369341"
datafile 4 switched to datafile copy "+DATA/db10g/datafile/users.260.596369341"

RMAN> alter database open;

database opened

     RMAN> exit

     Recovery Manager complete.


Migrate tempfile to ASM:

RMAN does not migrate the tempfile as part of the BACKUP AS COPY and SWITCH command becuase the tempfile is not listed in controlfile.
The tempfile has to be manually migrated to ASM.

[oracle@node1-pub oracle]$ sqlplus "/ as sysdba"


SQL*Plus: Release 10.2.0.1.0 - Production on Fri Jul 21 10:12:42 2006

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


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL> select name, bytes from v$tempfile;

NAME
--------------------------------------------------------------------------------
     BYTES
----------
/home/oracle/oradata/db10g/temp01.dbf
  20971520

SQL> create temporary tablespace temp1 tempfile SIZE 100M extent management local uniform size 1M;

Tablespace created.

SQL> alter database default temporary tablespace temp1;

Database altered.

SQL> drop tablespace temp including contents;

Tablespace dropped.

SQL> create temporary tablespace temp tempfile SIZE 100M extent management local uniform size 1M;

Tablespace created.

SQL> alter database default temporary tablespace temp;

Database altered.

SQL> drop tablespace temp1 including contents;

Tablespace dropped.

SQL> select name from v$tempfile;

NAME
--------------------------------------------------------------------------------
       +DATA/db10g/tempfile/temp.264.596370217


Migrate and drop the old Online Redo Logs to ASM:

Run the below procedure to migrate the redo logs to ASM. This program is taken from OTN/metalink.


SQL> declare

   cursor orlc is
      select lf.member, l.bytes
      from v$log l, v$logfile lf
      where l.group# = lf.group# and
         lf.type = 'ONLINE'
      order by l.thread#, l.sequence#;

   type numTab_t is table of number index by binary_integer;
   type charTab_t is table of varchar2(1024) index by binary_integer;
   byteslist numTab_t; namelist charTab_t;

   procedure migrateorlfile(name IN varchar2, bytes IN number) is
         retry number;
         stmt varchar2(1024);
         als varchar2(1024) := 'alter system switch logfile';
      begin
         select count(*) into retry from v$logfile;
         stmt := 'alter database add logfile size ' || bytes;
         execute immediate stmt;
         stmt := 'alter database drop logfile ''' || name || '''';
         for i in 1..retry loop
            begin execute immediate stmt;
            exit;
            exception
               when others then
                if i > retry then raise;
                end if;
             execute immediate als;
           end;
         end loop;
      end;
      begin
      open orlc;
      fetch orlc bulk collect into namelist, byteslist;
      close orlc;
      for i in 1..namelist.count loop migrateorlfile(namelist(i), byteslist(i));
      end loop;
end;
/
  2    3    4    5    6    7    8    9   10   11   12   13   14   15   16   17   18   19   20   21   22   23   24   25   26  27   28   29   30   31   32   33   34   35   36   37   38   39   40

PL/SQL procedure successfully completed.

SQL> SQL>
SQL>



SQL> select member from v$logfile;

MEMBER
--------------------------------------------------------------------------------
+FLASH/db10g/onlinelog/group_3.259.596373299
+FLASH/db10g/onlinelog/group_2.258.596373295
/home/oracle/oradata/db10g/redo01.log
+FLASH/db10g/onlinelog/group_4.257.596373293

SQL> alter system switch logfile;

System altered.

SQL> /

System altered.

SQL> /

System altered.

SQL> /

System altered.


Re-Execute the same script again in order to migrate the remaining ones.

SQL> declare

   cursor orlc is
      select lf.member, l.bytes
      from v$log l, v$logfile lf
      where l.group# = lf.group# and
         lf.type = 'ONLINE'
      order by l.thread#, l.sequence#;

   type numTab_t is table of number index by binary_integer;
   type charTab_t is table of varchar2(1024) index by binary_integer;
   byteslist numTab_t; namelist charTab_t;

   procedure migrateorlfile(name IN varchar2, bytes IN number) is
         retry number;
         stmt varchar2(1024);
         als varchar2(1024) := 'alter system switch logfile';
      begin
         select count(*) into retry from v$logfile;
         stmt := 'alter database add logfile size ' || bytes;
         execute immediate stmt;
         stmt := 'alter database drop logfile ''' || name || '''';
         for i in 1..retry loop
            begin execute immediate stmt;
            exit;
            exception
               when others then
                if i > retry then raise;
                end if;
             execute immediate als;
           end;
         end loop;
      end;
      begin
      open orlc;
      fetch orlc bulk collect into namelist, byteslist;
      close orlc;
      for i in 1..namelist.count loop migrateorlfile(namelist(i), byteslist(i));
      end loop;
end;
/  2    3    4    5    6    7    8    9   10   11   12   13   14   15   16   17   18   19   20   21   22   23   24   25   26   27   28   29   30   31   32   33   34   35   36   37   38   39   40

PL/SQL procedure successfully completed.

SQL> select member from v$logfile;

MEMBER
--------------------------------------------------------------------------------
+FLASH/db10g/onlinelog/group_3.259.596373619
+FLASH/db10g/onlinelog/group_2.258.596373615
+FLASH/db10g/onlinelog/group_1.261.596373613
+FLASH/db10g/onlinelog/group_4.257.596373293
+FLASH/db10g/onlinelog/group_5.260.596373609

SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
     With the Partitioning, OLAP and Data Mining options


DELETE THE OLD DATAFILES USING RMAN.

This way, it will also clear out the datafiles entry from controlfile.


[oracle@node1-pub oracle]$ $ORACLE_HOME/bin/rman


Recovery Manager: Release 10.2.0.1.0 - Production on Fri Jul 21 11:22:33 2006

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

RMAN> connect target

connected to target database: DB10G (DBID=4283639931)


RMAN> run {

2> DELETE COPY OF DATABASE;
3> }

using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=134 devtype=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: sid=151 devtype=DISK
allocated channel: ORA_DISK_3
channel ORA_DISK_3: sid=153 devtype=DISK
allocated channel: ORA_DISK_4
channel ORA_DISK_4: sid=138 devtype=DISK

List of Datafile Copies
Key     File S Completion Time Ckp SCN    Ckp Time        Name
------- ---- - --------------- ---------- --------------- ----
6       1    A 21-JUL-06       461254     21-JUL-06       /home/oracle/oradata/db10g/system01.dbf
7       2    A 21-JUL-06       461254     21-JUL-06       /home/oracle/oradata/db10g/undotbs01.dbf
8       3    A 21-JUL-06       461254     21-JUL-06       /home/oracle/oradata/db10g/sysaux01.dbf
9       4    A 21-JUL-06       461254     21-JUL-06       /home/oracle/oradata/db10g/users01.dbf

Do you really want to delete the above objects (enter YES or NO)? YES
deleted datafile copy
datafile copy filename=/home/oracle/oradata/db10g/system01.dbf recid=6 stamp=596369439
deleted datafile copy
datafile copy filename=/home/oracle/oradata/db10g/undotbs01.dbf recid=7 stamp=596369439
deleted datafile copy
datafile copy filename=/home/oracle/oradata/db10g/sysaux01.dbf recid=8 stamp=596369440
deleted datafile copy
datafile copy filename=/home/oracle/oradata/db10g/users01.dbf recid=9 stamp=596369440
Deleted 4 objects



RMAN> exit



Recovery Manager complete.

REMOVE THE OLD ONLINE REDO LOGS FILES PHYSICALLY:



[oracle@node1-pub oracle]$ rm /home/oracle/oradata/db10g/redo*.log
[oracle@node1-pub oracle]$ sqlplus "/ as sysdba"

SQL*Plus: Release 10.2.0.1.0 - Production on Fri Jul 21 11:29:56 2006

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


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
     With the Partitioning, OLAP and Data Mining options



Enable the block change tracking:

SQL> ALTER DATABASE ENABLE BLOCK CHANGE TRACKING;


Database altered.



SQL>

Search This Blog