Tuesday, August 7, 2012

How Migrate All Files on ASM to Non-ASM (Unix/Linux)


In this post I’ll show a way to migrate the database stored in ASM to Filesystem.
I’ll use PL/SQL scripts and RMAN commands to accomplish this.


Env Info:
1DATABASE NAME : DROP
2ORACLE DATAFILES/CONTROLFILE/TEMPFILE = /u01/app/oracle/oradata/drop
3ORACLE FLASH RECOVERY AREA= /u01/app/oracle/flash_recovery_area/
Migration  steps:
  1. Controlfile
  2. Datafile and Tempfile
  3. Online Logs (redo)
  4. Archived Online logs (archivelogs) and BackupSet in FRA
  5. Server Parameter File (SPFILE)

1.  Controlfiles

1SQL> select name from v$controlfile;
2 
3NAME
4--------------------------------------------------------------------------------
5+DG_DATA/drop/controlfile/current.275.761683397
6+DG_FRA/drop/controlfile/current.281.761683397

01SQL> shutdown immediate;
02Database closed.
03Database dismounted.
04ORACLE instance shut down.
05 
06SQL> startup nomount
07ORACLE instance started.
08 
09Total System Global Area 1119043584 bytes
10Fixed Size                  2218888 bytes
11Variable Size             855639160 bytes
12Database Buffers          251658240 bytes
13Redo Buffers                9527296 bytes
14 
15SQL> alter system set
16control_files='/u01/app/oracle/oradata/drop/control01.ctl',
17'/u01/app/oracle/flash_recovery_area/drop/control02.ctl'
18SCOPE=SPFILE SID='*';
19 
20System altered.
21 
22SQL> shutdown immediate;
23ORA-01507: database not mounted
24 
25ORACLE instance shut down.
26 
27$ rman target /
28 
29Recovery Manager: Release 11.2.0.2.0 - Production on Mon Sep 12 18:36:53 2011
30 
31Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
32 
33connected to target database (not started)
34 
35RMAN> startup nomount
36 
37Oracle instance started
38 
39Total System Global Area    1119043584 bytes
40 
41Fixed Size                     2218888 bytes
42Variable Size                855639160 bytes
43Database Buffers             251658240 bytes
44Redo Buffers                   9527296 bytes
45 
46RMAN> restore controlfile from '+DG_DATA/drop/controlfile/current.275.761683397';
47 
48Starting restore at 12-SEP-11
49using target database control file instead of recovery catalog
50allocated channel: ORA_DISK_1
51channel ORA_DISK_1: SID=134 device type=DISK
52 
53channel ORA_DISK_1: copied control file copy
54output file name=/u01/app/oracle/oradata/drop/control01.ctl
55output file name=/u01/app/oracle/flash_recovery_area/drop/control02.ctl
56Finished restore at 12-SEP-11
57 
58RMAN> startup mount
59 
60database is already started
61database mounted
62released channel: ORA_DISK_1
63 
64RMAN> exit
65 
66Recovery Manager complete.

01sqlplus / as sysdba
02 
03SQL*Plus: Release 11.2.0.2.0 Production on Mon Sep 12 18:53:19 2011
04 
05Copyright (c) 1982, 2010, Oracle.  All rights reserved.
06 
07SQL> select name from v$controlfile;
08 
09NAME
10--------------------------------------------------------------------------------
11/u01/app/oracle/oradata/drop/control01.ctl
12/u01/app/oracle/flash_recovery_area/drop/control02.ctl

2.  Datafiles and Tempfiles

01SQL> select file#, name from v$datafile;
02 
03     FILE# NAME
04---------- --------------------------------------------------
05         1 +DG_DATA/drop/datafile/system.292.761712355
06         2 +DG_DATA/drop/datafile/sysaux.291.761712395
07         3 +DG_DATA/drop/datafile/undotbs1.290.761712439
08         4 +DG_DATA/drop/datafile/users.289.761712455
09         5 +DG_DATA/drop/datafile/users.288.761712457
10         6 +DG_DATA/drop/datafile/users.287.761712457
11         7 +DG_DATA/drop/datafile/users.277.761712459
12         8 +DG_DATA/drop/datafile/users.278.761712461
13         9 +DG_DATA/drop/datafile/users.279.761712461
14        10 +DG_DATA/drop/datafile/users.276.761712463
15 
1610 rows selected.
17 
18SQL> select file#, name from v$tempfile;
19 
20     FILE# NAME
21---------- --------------------------------------------------
22         2 +DG_DATA/drop/tempfile/temp.286.761687721
23         1 +DG_DATA/drop/tempfile/temp.293.761712609
Using this PL/SQL is enough to generate RMAN command to migrate all datafiles and tempfiles at same time.
01SET serveroutput ON;
02DECLARE
03  vcount  NUMBER:=0;
04  vfname VARCHAR2(1024);
05  CURSOR df
06  IS
07    SELECT file#,
08      rtrim(REPLACE(name,'+DG_DATA/drop/datafile/','/u01/app/oracle/oradata/drop/'),'.0123456789') AS name
09    FROM v$datafile;
10  CURSOR tp
11  IS
12    SELECT file#,
13      rtrim(REPLACE(name,'+DG_DATA/drop/tempfile/','/u01/app/oracle/oradata/drop/'),'.0123456789') AS name
14    FROM v$tempfile;
15BEGIN
16  dbms_output.put_line('CONFIGURE CONTROLFILE AUTOBACKUP ON;');
17  FOR dfrec IN df
18  LOOP
19    IF dfrec.name  != vfname THEN
20      vcount      :=1;
21      vfname     := dfrec.name;
22    ELSE
23      vcount := vcount+1;
24      vfname:= dfrec.name;
25    END IF;
26    dbms_output.put_line('backup as copy datafile ' || dfrec.file# ||' format  "'||dfrec.name ||vcount||'.dbf";');
27  END LOOP;
28  dbms_output.put_line('run');
29  dbms_output.put_line('{');
30  FOR dfrec IN df
31  LOOP
32    IF dfrec.name  != vfname THEN
33      vcount      :=1;
34      vfname     := dfrec.name;
35    ELSE
36      vcount := vcount+1;
37      vfname:= dfrec.name;
38    END IF;
39    dbms_output.put_line('set newname for datafile ' || dfrec.file# ||'  to  '''||dfrec.name ||vcount||'.dbf'' ;');
40  END LOOP;
41  FOR tprec IN tp
42  LOOP
43    IF tprec.name  !=  vfname THEN
44      vcount      :=1;
45      vfname     := tprec.name;
46    ELSE
47      vcount := vcount+1;
48      vfname:= tprec.name;
49    END IF;
50    dbms_output.put_line('set newname for tempfile ' || tprec.file# ||'  to  '''||tprec.name ||vcount||'.dbf'' ;');
51    END LOOP;
52    dbms_output.put_line('switch tempfile all;');
53    dbms_output.put_line('switch datafile all;');
54    dbms_output.put_line('restore database;');
55    dbms_output.put_line('recover database;');
56    dbms_output.put_line('}');
57    dbms_output.put_line('alter database open;');
58    dbms_output.put_line('exit');
59END;
60/
Database must be Mounted
01SQL> SET serveroutput ON;
02SQL> DECLARE
03.
04.
05.
06 57      dbms_output.put_line('exit');
07 58  END;
08 59  /
09 
10CONFIGURE CONTROLFILE AUTOBACKUP ON;
11backup as copy datafile 1 format  "/u01/app/oracle/oradata/drop/system1.dbf";
12backup as copy datafile 2 format  "/u01/app/oracle/oradata/drop/sysaux1.dbf";
13backup as copy datafile 3 format  "/u01/app/oracle/oradata/drop/undotbs1.dbf";
14backup as copy datafile 4 format  "/u01/app/oracle/oradata/drop/users1.dbf";
15backup as copy datafile 5 format  "/u01/app/oracle/oradata/drop/users2.dbf";
16backup as copy datafile 6 format  "/u01/app/oracle/oradata/drop/users3.dbf";
17backup as copy datafile 7 format  "/u01/app/oracle/oradata/drop/users4.dbf";
18backup as copy datafile 8 format  "/u01/app/oracle/oradata/drop/users5.dbf";
19backup as copy datafile 9 format  "/u01/app/oracle/oradata/drop/users6.dbf";
20backup as copy datafile 10 format  "/u01/app/oracle/oradata/drop/users7.dbf";
21run
22{
23set newname for datafile 1  to  '/u01/app/oracle/oradata/drop/system1.dbf' ;
24set newname for datafile 2  to  '/u01/app/oracle/oradata/drop/sysaux1.dbf' ;
25set newname for datafile 3  to  '/u01/app/oracle/oradata/drop/undotbs1.dbf' ;
26set newname for datafile 4  to  '/u01/app/oracle/oradata/drop/users1.dbf' ;
27set newname for datafile 5  to  '/u01/app/oracle/oradata/drop/users2.dbf' ;
28set newname for datafile 6  to  '/u01/app/oracle/oradata/drop/users3.dbf' ;
29set newname for datafile 7  to  '/u01/app/oracle/oradata/drop/users4.dbf' ;
30set newname for datafile 8  to  '/u01/app/oracle/oradata/drop/users5.dbf' ;
31set newname for datafile 9  to  '/u01/app/oracle/oradata/drop/users6.dbf' ;
32set newname for datafile 10  to  '/u01/app/oracle/oradata/drop/users7.dbf' ;
33set newname for tempfile 1  to  '/u01/app/oracle/oradata/drop/temp1.dbf' ;
34set newname for tempfile 2  to  '/u01/app/oracle/oradata/drop/temp2.dbf' ;
35switch tempfile all;
36switch datafile all;
37restore database;
38recover database;
39}
40alter database open;
41exit
Important: Setting AUTOBACKUP ON is mandatory (Backup Fails ORA-27038 Creating Automatic Controlfile Backup [ID 382989.1])
Create a RMAN script file “migrate_db.rcv” and paste command generate by PL/SQL.
001nohup rman target / cmdfile migrate_db.rcv log migrate_db.log &
002 
003cat migrate_db.log
004 
005using target database control file instead of recovery catalog
006old RMAN configuration parameters:
007CONFIGURE CONTROLFILE AUTOBACKUP ON;
008new RMAN configuration parameters:
009CONFIGURE CONTROLFILE AUTOBACKUP ON;
010new RMAN configuration parameters are successfully stored
011 
012Starting backup at 13-SEP-11
013allocated channel: ORA_DISK_1
014channel ORA_DISK_1: SID=137 device type=DISK
015channel ORA_DISK_1: starting datafile copy
016input datafile file number=00001 name=+DG_DATA/drop/datafile/system.292.761712355
017output file name=/u01/app/oracle/oradata/drop/system1.dbf tag=TAG20110913T025233 RECID=68 STAMP=761712766
018channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
019Finished backup at 13-SEP-11
020 
021Starting Control File and SPFILE Autobackup at 13-SEP-11
022piece handle=/u01/app/oracle/flash_recovery_area/DROP/autobackup/2011_09_13/o1_mf_s_761712652_76xvxlw3_.bkp comment=NONE
023Finished Control File and SPFILE Autobackup at 13-SEP-11
024 
025Starting backup at 13-SEP-11
026using channel ORA_DISK_1
027channel ORA_DISK_1: starting datafile copy
028input datafile file number=00002 name=+DG_DATA/drop/datafile/sysaux.291.761712395
029output file name=/u01/app/oracle/oradata/drop/sysaux1.dbf tag=TAG20110913T025253 RECID=69 STAMP=761712784
030channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
031Finished backup at 13-SEP-11
032 
033Starting Control File and SPFILE Autobackup at 13-SEP-11
034piece handle=/u01/app/oracle/flash_recovery_area/DROP/autobackup/2011_09_13/o1_mf_s_761712652_76xvy5h5_.bkp comment=NONE
035Finished Control File and SPFILE Autobackup at 13-SEP-11
036 
037Starting backup at 13-SEP-11
038using channel ORA_DISK_1
039channel ORA_DISK_1: starting datafile copy
040input datafile file number=00003 name=+DG_DATA/drop/datafile/undotbs1.290.761712439
041output file name=/u01/app/oracle/oradata/drop/undotbs1.dbf tag=TAG20110913T025312 RECID=70 STAMP=761712796
042channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
043Finished backup at 13-SEP-11
044 
045Starting Control File and SPFILE Autobackup at 13-SEP-11
046piece handle=/u01/app/oracle/flash_recovery_area/DROP/autobackup/2011_09_13/o1_mf_s_761712652_76xvyjkb_.bkp comment=NONE
047Finished Control File and SPFILE Autobackup at 13-SEP-11
048 
049Starting backup at 13-SEP-11
050using channel ORA_DISK_1
051channel ORA_DISK_1: starting datafile copy
052input datafile file number=00004 name=+DG_DATA/drop/datafile/users.289.761712455
053output file name=/u01/app/oracle/oradata/drop/users1.dbf tag=TAG20110913T025321 RECID=71 STAMP=761712802
054channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
055Finished backup at 13-SEP-11
056 
057Starting Control File and SPFILE Autobackup at 13-SEP-11
058piece handle=/u01/app/oracle/flash_recovery_area/DROP/autobackup/2011_09_13/o1_mf_s_761712652_76xvymrv_.bkp comment=NONE
059Finished Control File and SPFILE Autobackup at 13-SEP-11
060 
061Starting backup at 13-SEP-11
062using channel ORA_DISK_1
063channel ORA_DISK_1: starting datafile copy
064input datafile file number=00005 name=+DG_DATA/drop/datafile/users.288.761712457
065output file name=/u01/app/oracle/oradata/drop/users2.dbf tag=TAG20110913T025326 RECID=72 STAMP=761712807
066channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
067Finished backup at 13-SEP-11
068 
069Starting Control File and SPFILE Autobackup at 13-SEP-11
070piece handle=/u01/app/oracle/flash_recovery_area/DROP/autobackup/2011_09_13/o1_mf_s_761712652_76xvys74_.bkp comment=NONE
071Finished Control File and SPFILE Autobackup at 13-SEP-11
072 
073Starting backup at 13-SEP-11
074using channel ORA_DISK_1
075channel ORA_DISK_1: starting datafile copy
076input datafile file number=00006 name=+DG_DATA/drop/datafile/users.287.761712457
077output file name=/u01/app/oracle/oradata/drop/users3.dbf tag=TAG20110913T025332 RECID=73 STAMP=761712812
078channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
079Finished backup at 13-SEP-11
080 
081Starting Control File and SPFILE Autobackup at 13-SEP-11
082piece handle=/u01/app/oracle/flash_recovery_area/DROP/autobackup/2011_09_13/o1_mf_s_761712652_76xvyydl_.bkp comment=NONE
083Finished Control File and SPFILE Autobackup at 13-SEP-11
084 
085Starting backup at 13-SEP-11
086using channel ORA_DISK_1
087channel ORA_DISK_1: starting datafile copy
088input datafile file number=00007 name=+DG_DATA/drop/datafile/users.277.761712459
089output file name=/u01/app/oracle/oradata/drop/users4.dbf tag=TAG20110913T025335 RECID=74 STAMP=761712816
090channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
091Finished backup at 13-SEP-11
092 
093Starting Control File and SPFILE Autobackup at 13-SEP-11
094piece handle=/u01/app/oracle/flash_recovery_area/DROP/autobackup/2011_09_13/o1_mf_s_761712652_76xvz1qq_.bkp comment=NONE
095Finished Control File and SPFILE Autobackup at 13-SEP-11
096 
097Starting backup at 13-SEP-11
098using channel ORA_DISK_1
099channel ORA_DISK_1: starting datafile copy
100input datafile file number=00008 name=+DG_DATA/drop/datafile/users.278.761712461
101output file name=/u01/app/oracle/oradata/drop/users5.dbf tag=TAG20110913T025338 RECID=75 STAMP=761712819
102channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
103Finished backup at 13-SEP-11
104 
105Starting Control File and SPFILE Autobackup at 13-SEP-11
106piece handle=/u01/app/oracle/flash_recovery_area/DROP/autobackup/2011_09_13/o1_mf_s_761712652_76xvz4xm_.bkp comment=NONE
107Finished Control File and SPFILE Autobackup at 13-SEP-11
108 
109Starting backup at 13-SEP-11
110using channel ORA_DISK_1
111channel ORA_DISK_1: starting datafile copy
112input datafile file number=00009 name=+DG_DATA/drop/datafile/users.279.761712461
113output file name=/u01/app/oracle/oradata/drop/users6.dbf tag=TAG20110913T025342 RECID=76 STAMP=761712822
114channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
115Finished backup at 13-SEP-11
116 
117Starting Control File and SPFILE Autobackup at 13-SEP-11
118piece handle=/u01/app/oracle/flash_recovery_area/DROP/autobackup/2011_09_13/o1_mf_s_761712652_76xvz878_.bkp comment=NONE
119Finished Control File and SPFILE Autobackup at 13-SEP-11
120 
121Starting backup at 13-SEP-11
122using channel ORA_DISK_1
123channel ORA_DISK_1: starting datafile copy
124input datafile file number=00010 name=+DG_DATA/drop/datafile/users.276.761712463
125output file name=/u01/app/oracle/oradata/drop/users7.dbf tag=TAG20110913T025345 RECID=77 STAMP=761712825
126channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
127Finished backup at 13-SEP-11
128 
129Starting Control File and SPFILE Autobackup at 13-SEP-11
130piece handle=/u01/app/oracle/flash_recovery_area/DROP/autobackup/2011_09_13/o1_mf_s_761712652_76xvzcjb_.bkp comment=NONE
131Finished Control File and SPFILE Autobackup at 13-SEP-11
132 
133executing command: SET NEWNAME
134 
135executing command: SET NEWNAME
136 
137executing command: SET NEWNAME
138 
139executing command: SET NEWNAME
140 
141executing command: SET NEWNAME
142 
143executing command: SET NEWNAME
144 
145executing command: SET NEWNAME
146 
147executing command: SET NEWNAME
148 
149executing command: SET NEWNAME
150 
151executing command: SET NEWNAME
152 
153executing command: SET NEWNAME
154 
155executing command: SET NEWNAME
156 
157renamed tempfile 1 to /u01/app/oracle/oradata/drop/temp1.dbf in control file
158renamed tempfile 2 to /u01/app/oracle/oradata/drop/temp2.dbf in control file
159 
160datafile 1 switched to datafile copy
161input datafile copy RECID=68 STAMP=761712766 file name=/u01/app/oracle/oradata/drop/system1.dbf
162datafile 2 switched to datafile copy
163input datafile copy RECID=69 STAMP=761712784 file name=/u01/app/oracle/oradata/drop/sysaux1.dbf
164datafile 3 switched to datafile copy
165input datafile copy RECID=70 STAMP=761712796 file name=/u01/app/oracle/oradata/drop/undotbs1.dbf
166datafile 4 switched to datafile copy
167input datafile copy RECID=71 STAMP=761712802 file name=/u01/app/oracle/oradata/drop/users1.dbf
168datafile 5 switched to datafile copy
169input datafile copy RECID=72 STAMP=761712807 file name=/u01/app/oracle/oradata/drop/users2.dbf
170datafile 6 switched to datafile copy
171input datafile copy RECID=73 STAMP=761712812 file name=/u01/app/oracle/oradata/drop/users3.dbf
172datafile 7 switched to datafile copy
173input datafile copy RECID=74 STAMP=761712816 file name=/u01/app/oracle/oradata/drop/users4.dbf
174datafile 8 switched to datafile copy
175input datafile copy RECID=75 STAMP=761712819 file name=/u01/app/oracle/oradata/drop/users5.dbf
176datafile 9 switched to datafile copy
177input datafile copy RECID=76 STAMP=761712822 file name=/u01/app/oracle/oradata/drop/users6.dbf
178datafile 10 switched to datafile copy
179input datafile copy RECID=77 STAMP=761712825 file name=/u01/app/oracle/oradata/drop/users7.dbf
180 
181Starting restore at 13-SEP-11
182using channel ORA_DISK_1
183 
184skipping datafile 1; already restored to file /u01/app/oracle/oradata/drop/system1.dbf
185skipping datafile 2; already restored to file /u01/app/oracle/oradata/drop/sysaux1.dbf
186skipping datafile 3; already restored to file /u01/app/oracle/oradata/drop/undotbs1.dbf
187skipping datafile 4; already restored to file /u01/app/oracle/oradata/drop/users1.dbf
188skipping datafile 5; already restored to file /u01/app/oracle/oradata/drop/users2.dbf
189skipping datafile 6; already restored to file /u01/app/oracle/oradata/drop/users3.dbf
190skipping datafile 7; already restored to file /u01/app/oracle/oradata/drop/users4.dbf
191skipping datafile 8; already restored to file /u01/app/oracle/oradata/drop/users5.dbf
192skipping datafile 9; already restored to file /u01/app/oracle/oradata/drop/users6.dbf
193skipping datafile 10; already restored to file /u01/app/oracle/oradata/drop/users7.dbf
194restore not done; all files read only, offline, or already restored
195Finished restore at 13-SEP-11
196 
197Starting recover at 13-SEP-11
198using channel ORA_DISK_1
199 
200starting media recovery
201media recovery complete, elapsed time: 00:00:02
202 
203Finished recover at 13-SEP-11
204 
205database opened
206 
207Recovery Manager complete.

01SQL> select file#, name from v$datafile;
02 
03     FILE# NAME
04---------- --------------------------------------------------
05         1 /u01/app/oracle/oradata/drop/system1.dbf
06         2 /u01/app/oracle/oradata/drop/sysaux1.dbf
07         3 /u01/app/oracle/oradata/drop/undotbs1.dbf
08         4 /u01/app/oracle/oradata/drop/users1.dbf
09         5 /u01/app/oracle/oradata/drop/users2.dbf
10         6 /u01/app/oracle/oradata/drop/users3.dbf
11         7 /u01/app/oracle/oradata/drop/users4.dbf
12         8 /u01/app/oracle/oradata/drop/users5.dbf
13         9 /u01/app/oracle/oradata/drop/users6.dbf
14        10 /u01/app/oracle/oradata/drop/users7.dbf
15 
1610 rows selected.
17 
18SQL> select file#, name from v$tempfile;
19 
20     FILE# NAME
21---------- --------------------------------------------------
22         2 /u01/app/oracle/oradata/drop/temp2.dbf
23         1 /u01/app/oracle/oradata/drop/temp1.dbf
24 
25SQL>

3.  Online Logs (Redo)

Database must be Open
01SQL> select group#,member from v$logfile order by 1;
02 
03    GROUP# MEMBER
04---------- ------------------------------------------------------------------------------------------
05         1 +DG_DATA/drop/onlinelog/group_1.285.761755579
06         2 +DG_DATA/drop/onlinelog/group_2.284.761755615
07         3 +DG_DATA/drop/onlinelog/group_3.278.761755651
08         4 +DG_DATA/drop/onlinelog/group_4.283.761754951
09         5 +DG_DATA/drop/onlinelog/group_5.276.761754957
10         6 +DG_DATA/drop/onlinelog/group_6.282.761754963
11         7 +DG_DATA/drop/onlinelog/group_7.279.761754967
12 
13SQL> SELECT group# grp,
14      thread# thr,
15      bytes/1024 bytes_k,
16      'NO' srl,
17      status
18    FROM v$log
19  UNION
20  SELECT group# grp,
21    thread# thr,
22    bytes/1024 bytes_k,
23    'YES' srl,
24    status
25  FROM v$standby_log
26  ORDER BY 1;
27 
28       GRP        THR    BYTES_K SRL STATUS
29---------- ---------- ---------- --- ----------------
30         1          1     102400 NO  INACTIVE
31         2          1     102400 NO  CURRENT
32         3          1     102400 NO  UNUSED
33         4          1     102400 YES UNASSIGNED
34         5          1     102400 YES UNASSIGNED
35         6          1     102400 YES UNASSIGNED
36         7          1     102400 YES UNASSIGNED
Another PL/SQL, will work only if database have more than 2 Logfile Group
01DECLARE
02  vgroup NUMBER;
03  CURSOR rlc
04  IS
05    SELECT group# grp,
06      thread# thr,
07      bytes/1024 bytes_k,
08      'NO' srl,
09      status
10    FROM v$log
11  UNION
12  SELECT group# grp,
13    thread# thr,
14    bytes/1024 bytes_k,
15    'YES' srl,
16    status
17  FROM v$standby_log
18  ORDER BY status DESC;
19  stmt    VARCHAR2(2048);
20  swtstmt VARCHAR2(1024) := 'alter system switch logfile';
21  ckpstmt VARCHAR2(1024) := 'alter system checkpoint global';
22BEGIN
23  FOR rlcRec IN rlc
24  LOOP
25    IF (rlcRec.srl = 'YES') THEN
26      BEGIN
27        SELECT group#
28        INTO vgroup
29        FROM v$standby_log
30        WHERE group# = rlcRec.grp
31        AND thread#  = rlcRec.thr
32        AND (status  ='CURRENT'
33        OR status    = 'ACTIVE');
34        stmt        := 'alter database drop standby logfile group ' || rlcRec.grp;
35        EXECUTE IMMEDIATE swtstmt;
36        EXECUTE IMMEDIATE ckpstmt;
37        EXECUTE immediate stmt;
38        stmt := 'alter database add standby logfile thread ' || rlcRec.thr ||' group '||rlcRec.grp||' ''/u01/app/oracle/oradata/drop/redo_stby'||rlcRec.grp||'_'||rlcRec.thr||'_a.log'' size ' || rlcRec.bytes_k || 'K';
39        EXECUTE immediate stmt;
40      EXCEPTION
41      WHEN NO_DATA_FOUND THEN
42        BEGIN
43          EXECUTE immediate ckpstmt;
44          stmt := 'alter database drop standby logfile group ' || rlcRec.grp;
45          EXECUTE immediate stmt;
46          stmt := 'alter database add standby logfile thread ' || rlcRec.thr ||' group '||rlcRec.grp||' ''/u01/app/oracle/oradata/drop/redo_stby'||rlcRec.grp||'_'||rlcRec.thr||'_a.log'' size ' || rlcRec.bytes_k || 'K';
47          EXECUTE immediate stmt;
48        END;
49      END;
50    ELSE
51      BEGIN
52        SELECT group#
53        INTO vgroup
54        FROM v$log
55        WHERE group# = rlcRec.grp
56        AND thread#  = rlcRec.thr
57        AND (status  ='CURRENT'
58        OR status    = 'ACTIVE');
59        stmt        := 'alter database drop logfile group ' || rlcRec.grp;
60        EXECUTE IMMEDIATE swtstmt;
61        EXECUTE IMMEDIATE ckpstmt;
62        EXECUTE immediate stmt;
63        stmt := 'alter database add logfile thread ' || rlcRec.thr || ' group '||rlcRec.grp||'  ''/u01/app/oracle/oradata/drop/redo_'||rlcRec.grp||'_'||rlcRec.thr||'_a.log'' size ' || rlcRec.bytes_k || 'K';
64        EXECUTE immediate stmt;
65      EXCEPTION
66      WHEN NO_DATA_FOUND THEN
67        BEGIN
68          EXECUTE immediate ckpstmt;
69          stmt := 'alter database drop logfile group ' || rlcRec.grp;
70          EXECUTE immediate stmt;
71          stmt := 'alter database add logfile thread ' || rlcRec.thr || ' group '||rlcRec.grp||'  ''/u01/app/oracle/oradata/drop/redo_'||rlcRec.grp||'_'||rlcRec.thr||'_a.log'' size ' || rlcRec.bytes_k || 'K';
72          EXECUTE immediate stmt;
73        END;
74      END;
75    END IF;
76  END LOOP;
77END;
78/

01SQL> select group#,member from v$logfile order by 1;
02 
03    GROUP# MEMBER
04---------- ------------------------------------------------------------------------------------------
05         1 /u01/app/oracle/oradata/drop/redo_1_1_a.log
06         2 /u01/app/oracle/oradata/drop/redo_2_1_a.log
07         3 /u01/app/oracle/oradata/drop/redo_3_1_a.log
08         4 /u01/app/oracle/oradata/drop/redo_stby4_1_a.log
09         5 /u01/app/oracle/oradata/drop/redo_stby5_1_a.log
10         6 /u01/app/oracle/oradata/drop/redo_stby6_1_a.log
11         7 /u01/app/oracle/oradata/drop/redo_stby7_1_a.log
12 
137 rows selected.
14 
15SQL> SELECT group# grp,
16      thread# thr,
17      bytes/1024 bytes_k,
18      'NO' srl,
19      status
20    FROM v$log
21  UNION
22  SELECT group# grp,
23    thread# thr,
24    bytes/1024 bytes_k,
25    'YES' srl,
26    status
27  FROM v$standby_log
28  ORDER BY 1;  2    3    4    5    6    7    8    9   10   11   12   13   14
29 
30       GRP        THR    BYTES_K SRL STATUS
31---------- ---------- ---------- --- ----------------
32         1          1     102400 NO  CURRENT
33         2          1     102400 NO  UNUSED
34         3          1     102400 NO  UNUSED
35         4          1     102400 YES UNASSIGNED
36         5          1     102400 YES UNASSIGNED
37         6          1     102400 YES UNASSIGNED
38         7          1     102400 YES UNASSIGNED

4.  Archived Online logs (archivelogs) and BackupSet stored in FRA

Migrating BackupSet and Archivelogs from FRA (Flash Recovery Area) on ASM to FRA on NON-ASM
The first step is set new FRA.
01SQL> show parameter db_recovery_file
02NAME                                 TYPE        VALUE
03------------------------------------ ----------- ------------------------------
04db_recovery_file_dest                string      +DG_FRA
05db_recovery_file_dest_size           big integer 100G
06 
07SQL> alter system set db_recovery_file_dest='/u01/app/oracle/flash_recovery_area' scope=both;
08 
09SQL> show parameter db_recovery_file
10NAME                                 TYPE        VALUE
11------------------------------------ ----------- ------------------------------
12db_recovery_file_dest                string      /u01/app/oracle/flash_recovery_area
13db_recovery_file_dest_size           big integer 100G
Migrating Archivelog
01RMAN> list archivelog all;
02 
03using target database control file instead of recovery catalog
04List of Archived Log Copies for database with db_unique_name DROP
05=====================================================================
06 
07Key     Thrd Seq     S Low Time
08------- ---- ------- - ---------
0980      1    57      A 16-SEP-11
10        Name: +DG_FRA/drop/archivelog/2011_09_16/thread_1_seq_57.343.762030975
11 
1281      1    58      A 16-SEP-11
13        Name: +DG_FRA/drop/archivelog/2011_09_16/thread_1_seq_58.333.762030975
14.
15.
16.
1789      1    66      A 16-SEP-11
18        Name: +DG_FRA/drop/archivelog/2011_09_16/thread_1_seq_66.340.762030987
19 
2090      1    67      A 16-SEP-11
21        Name: +DG_FRA/drop/archivelog/2011_09_16/thread_1_seq_67.341.762030989
22 
23$ rman target /
24 
25Recovery Manager: Release 11.2.0.2.0 - Production on Fri Sep 16 19:20:01 2011
26 
27Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
28 
29connected to target database: DROP (DBID=3027542406)
30 
31RMAN>  BACKUP AS COPY ARCHIVELOG ALL DELETE INPUT;
32 
33Starting backup at 16-SEP-11
34current log archived
35using target database control file instead of recovery catalog
36allocated channel: ORA_DISK_1
37channel ORA_DISK_1: SID=25 device type=DISK
38channel ORA_DISK_1: starting archived log copy
39input archived log thread=1 sequence=57 RECID=92 STAMP=762031143
40output file name=/u01/app/oracle/flash_recovery_area/DROP/archivelog/2011_09_16/o1_mf_1_57_777lwyyp_.arc RECID=105 STAMP=762031215
41.
42.
43.
44channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:01
45channel ORA_DISK_1: deleting archived log(s)
46archived log file name=/u01/app/oracle/flash_recovery_area/DROP/archivelog/2011_09_16/o1_mf_1_69_777lww4t_.arc RECID=104 STAMP=762031212
47Finished backup at 16-SEP-11
48 
49Starting Control File and SPFILE Autobackup at 16-SEP-11
50piece handle=/u01/app/oracle/flash_recovery_area/DROP/autobackup/2011_09_16/o1_mf_s_762031234_777lxlx5_.bkp comment=NONE
51Finished Control File and SPFILE Autobackup at 16-SEP-11
52 
53RMAN> list archivelog all;
54 
55List of Archived Log Copies for database with db_unique_name DROP
56=====================================================================
57 
58Key     Thrd Seq     S Low Time
59------- ---- ------- - ---------
60105     1    57      A 16-SEP-11
61        Name: /u01/app/oracle/flash_recovery_area/DROP/archivelog/2011_09_16/o1_mf_1_57_777lwyyp_.arc
62 
63106     1    58      A 16-SEP-11
64        Name: /u01/app/oracle/flash_recovery_area/DROP/archivelog/2011_09_16/o1_mf_1_58_777lx0dh_.arc
65 
66.
67.
68.
69116     1    68      A 16-SEP-11
70        Name: /u01/app/oracle/flash_recovery_area/DROP/archivelog/2011_09_16/o1_mf_1_68_777lxhfl_.arc
71 
72117     1    69      A 16-SEP-11
73        Name: /u01/app/oracle/flash_recovery_area/DROP/archivelog/2011_09_16/o1_mf_1_69_777lxjwv_.arc
Migrating Backupset
01list backupset summary;
02 
03List of Backups
04===============
05Key     TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag
06------- -- -- - ----------- --------------- ------- ------- ---------- ---
0749      B  A  A DISK        16-SEP-11       1       1       NO         TAG20110916T190201
0850      B  F  A DISK        16-SEP-11       1       1       NO         TAG20110916T190208
0951      B  A  A DISK        16-SEP-11       1       1       NO         TAG20110916T190235
1052      B  F  A DISK        16-SEP-11       1       1       NO         TAG20110916T190237
1153      B  A  A DISK        16-SEP-11       1       1       NO         TAG20110916T190919
1254      B  F  A DISK        16-SEP-11       1       1       NO         TAG20110916T190921
1355      B  A  A DISK        16-SEP-11       1       1       NO         TAG20110916T190937
1456      B  F  A DISK        16-SEP-11       1       1       NO         TAG20110916T190939
15 
16RMAN> LIST BACKUPPIECE TAG TAG20110916T190201;
17 
18List of Backup Pieces
19BP Key  BS Key  Pc# Cp# Status      Device Type Piece Name
20------- ------- --- --- ----------- ----------- ----------
2149      49      1   1   AVAILABLE   DISK        +DG_FRA/drop/backupset/2011_09_16/annnf0_tag20110916t190201_0.332.762030121
22 
23RMAN> BACKUP DEVICE TYPE DISK BACKUPSET ALL DELETE INPUT;
24 
25Starting backup at 16-SEP-11
26using channel ORA_DISK_1
27channel ORA_DISK_1: input backup set: count=107, stamp=762030121, piece=1
28channel ORA_DISK_1: starting piece 1 at 16-SEP-11
29channel ORA_DISK_1: backup piece +DG_FRA/drop/backupset/2011_09_16/annnf0_tag20110916t190201_0.332.762030121
30piece handle=/u01/app/oracle/flash_recovery_area/DROP/backupset/2011_09_16/o1_mf_annnn_TAG20110916T190201_777ly4p4_.bkp comment=NONE
31.
32.
33.
34channel ORA_DISK_1: backup piece complete, elapsed time: 00:00:00
35channel ORA_DISK_1: input backup set: count=153, stamp=762031234, piece=1
36channel ORA_DISK_1: starting piece 1 at 16-SEP-11
37skipping backup piece handle /u01/app/oracle/flash_recovery_area/DROP/autobackup/2011_09_16/o1_mf_s_762031234_777lxlx5_.bkp; already exists
38channel ORA_DISK_1: finished piece 1 at 16-SEP-11
39channel ORA_DISK_1: backup piece complete, elapsed time: 00:00:00
40Finished backup at 16-SEP-11
41 
42Starting Control File and SPFILE Autobackup at 16-SEP-11
43piece handle=/u01/app/oracle/flash_recovery_area/DROP/autobackup/2011_09_16/o1_mf_s_762031278_777lyz23_.bkp comment=NONE
44Finished Control File and SPFILE Autobackup at 16-SEP-11
45 
46RMAN> LIST BACKUPSET SUMMARY;
47 
48List of Backups
49===============
50Key     TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag
51------- -- -- - ----------- --------------- ------- ------- ---------- ---
5249      B  A  A DISK        16-SEP-11       1       1       NO         TAG20110916T190201
5350      B  F  A DISK        16-SEP-11       1       1       NO         TAG20110916T190208
5451      B  A  A DISK        16-SEP-11       1       1       NO         TAG20110916T190235
5552      B  F  A DISK        16-SEP-11       1       1       NO         TAG20110916T190237
5653      B  A  A DISK        16-SEP-11       1       1       NO         TAG20110916T190919
5754      B  F  A DISK        16-SEP-11       1       1       NO         TAG20110916T190921
5855      B  A  A DISK        16-SEP-11       1       1       NO         TAG20110916T190937
5956      B  F  A DISK        16-SEP-11       1       1       NO         TAG20110916T190939
6057      B  F  A DISK        16-SEP-11       1       1       NO         TAG20110916T191630
6158      B  F  A DISK        16-SEP-11       1       1       NO         TAG20110916T191920
6259      B  F  A DISK        16-SEP-11       1       1       NO         TAG20110916T192034
6360      B  F  A DISK        16-SEP-11       1       1       NO         TAG20110916T192118
64 
65RMAN> LIST BACKUPPIECE TAG TAG20110916T190201;
66 
67List of Backup Pieces
68BP Key  BS Key  Pc# Cp# Status      Device Type Piece Name
69------- ------- --- --- ----------- ----------- ----------
7060      49      1   2   AVAILABLE   DISK        /u01/app/oracle/flash_recovery_area/DROP/backupset/2011_09_16/o1_mf_annnn_TAG20110916T190201_777ly4p4_.bkp

5.  Server Parameter File (SPFILE)

01SQL> show parameter spfile
02NAME                                 TYPE        VALUE
03------------------------------------ ----------- ------------------------------
04spfile                               string      +DG_DATA/drop/spfiledrop.ora
05 
06srvctl config database -d drop |grep Spfile
07Spfile: +DG_DATA/drop/spfiledrop.ora
08 
09rman target /
10 
11Recovery Manager: Release 11.2.0.2.0 - Production on Fri Sep 16 19:56:33 2011
12 
13Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
14 
15connected to target database: DROP (DBID=3027542406)
16 
17RMAN> restore spfile to '$ORACLE_HOME/dbs/spfiledrop.ora';
18 
19Starting restore at 16-SEP-11
20using target database control file instead of recovery catalog
21allocated channel: ORA_DISK_1
22channel ORA_DISK_1: SID=136 device type=DISK
23 
24channel ORA_DISK_1: starting datafile backup set restore
25channel ORA_DISK_1: restoring SPFILE
26output file name=$ORACLE_HOME/dbs/spfiledrop.ora
27channel ORA_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/DROP/autobackup/2011_09_16/o1_mf_s_762031278_777lyz23_.bkp
28channel ORA_DISK_1: piece handle=/u01/app/oracle/flash_recovery_area/DROP/autobackup/2011_09_16/o1_mf_s_762031278_777lyz23_.bkp tag=TAG20110916T192118
29channel ORA_DISK_1: restored backup piece 1
30channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
31Finished restore at 16-SEP-11
32 
33# edit initdrop.ora on $ORACLE_HOME/dbs
34vi initdrop
35spfile='/u01/app/oracle/product/11.2.0/dbhome_1/dbs/spfiledrop.ora'
36 
37# If you are using Oracle Restart you must change configuration with srvct.
38$ srvctl modify database -d drop -p $ORACLE_HOME/dbs/spfiledrop.ora
39$ srvctl config database -d drop |grep Spfile
40Spfile: /u01/app/oracle/product/11.2.0/dbhome_1/dbs/spfiledrop.ora
41 
42SQL> shutdown immediate;
43Database closed.
44Database dismounted.
45ORACLE instance shut down.
46SQL> startup
47ORACLE instance started.
48 
49Total System Global Area 1119043584 bytes
50Fixed Size                  2218888 bytes
51Variable Size             855639160 bytes
52Database Buffers          251658240 bytes
53Redo Buffers                9527296 bytes
54Database mounted.
55Database opened.
56SQL> show parameter spfile
57 
58NAME                                 TYPE        VALUE
59------------------------------------ ----------- ------------------------------
60spfile                               string      /u01/app/oracle/product/11.2.0/dbhome_1/dbs/spfiledrop.ora

No comments: