Enviroment
- OS: Oracle Linux 6.2 run on VMWare
- A simple Oracle 11.2.0.3 database named orcl on filesystem
|
Steps to move database from file system to a ASM diskgroup
|
|
|
Create directory grid parallel to directory of oracle and install Grid Infrastructure
[root@oel62 ~]# mkdir -p /u01/app/grid
[root@oel62 ~]# chown grid:oinstall /u01/app/grid
more see: Install Grid for Standalone Server
Additional create 2 ASM disks using UDEV then create a new diskgroup named FRA for Fast Recovery Area.
Howto: see here
before:
[root@oel62 ~]# id oracle
uid=54321(oracle) gid=54321(oinstall) groups=54321(oinstall),54322(dba)
run:
[root@oel62 ~]# usermod -G oinstall,dba,oper,asmdba oracle
after:
[root@oel62 ~]# id oracle
uid=54321(oracle) gid=54321(oinstall) groups=54321(oinstall),54322(dba),54323(oper),54325(asmdba)
for more see: here
[oracle@oel62 ~]$ su - grid
before:
[grid@oel62 ~]$ ls -l /u01/app/oracle/product/11.2.0/dbhome_1/bin/oracle
-rwsr-s--x 1 oracle oinstall 232399123 Jun 5 17:18 /u01/app/oracle/product/11.2.0/dbhome_1/bin/oracle
run:
[grid@oel62 ~]$ /u01/app/grid/product/11.2.0/grid/bin/setasmgidwrap
o=/u01/app/oracle/product/11.2.0/dbhome_1/bin/oracle
after:
[grid@oel62 ~]$ ls -l /u01/app/oracle/product/11.2.0/dbhome_1/bin/oracle
-rwsr-s--x 1 oracle asmadmin 232399123 Jun 5 17:18 /u01/app/oracle/product/11.2.0/dbhome_1/bin/oracle
for more see: here
RMAN> startup
RMAN> BACKUP AS COPY INCREMENTAL LEVEL 0 DATABASE FORMAT '+DATA' TAG 'ORA_ASM_MIGRATION';
RMAN> shutdown immediate
This is the crux of the story. We say via RMAN backup the database, but AS COPY(not backupset!), and with the format +DATA which mean all copies are stored in ASM diskgroup DATA
And next we say via command switch database to copy, which means: all data files of the datbase are now their copies!
RMAN> startup mount
RMAN> restore spfile to '+DATA/spfileorcl.ora';
RMAN> shutdown immediate
Delete file spfileorcl.ora and initorcl.ora in $ORACLE_HOME/dbs/dbs:
Create a new pfile initorcl.ora which points to the spfile in ASM with this line:
SPFILE='+DATA/spfileorcl.ora'
SQL> startup nomount;
SQL> alter system set DB_CREATE_FILE_DEST='+DATA' sid ='*';
SQL> alter system set DB_RECOVERY_FILE_DEST='+FRA' sid='*';
SQL> alter system set CONTROL_FILES='+DATA','+FRA' scope=spfile sid='*';
SQL> shutdown immediate
RMAN> startup nomount
..
RMAN> restore controlfile from '/u01/app/oracle/oradata/orcl/control01.ctl';
Starting restore at 26-JUN-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=24 device type=DISK
channel ORA_DISK_1: copied control file copy
output file name=+DATA/orcl/controlfile/current.276.786977643
output file name=+FRA/orcl/controlfile/current.256.786977643
Finished restore at 26-JUN-12
All copies of datafiles are ready in ASM disgroup (see
Backup).
Migration data files to ASM is simple: just a switch all data files to their image copies (in ASM diskgroup)!
RMAN> alter database mount;
RMAN> SWITCH DATABASE TO COPY;
RMAN> recover database;
RMAN> alter database open;
What mean: SWITCH DATABASE TO COPY?
SQL> ALTER DATABASE TEMPFILE '/u01/app/oracle/oradata/orcl/temp01.dbf' DROP;
SQL> ALTER TABLESPACE temp ADD TEMPFILE;
SQL> select a.group#, a.status, b.member from v$log a,v$logfile b where a.group#=b.group# order by group#;
Create new log group:
SQL> alter database add logfile group 4 size 50M;
SQL> alter database add logfuile group 5 size 50M;
SQL> alter database add logfile group 6 size 50M;
Switch to new log group until old log group 1,2,3 have status INACTIVE:
SQL> alter system switch logfile;
SQL> alter system switch logfile;
..
Drop old INACTIVE log groups 1,2,3:
SQL> alter database drop logfile group 1;
SQL> alter database drop logfile group 2;
SQL> alter database drop logfile group 3;
Optionally move archive log, backupset, copies from old FRA
RMAN> BACKUP AS COPY ARCHIVELOG ALL DELETE INPUT;
RMAN> BACKUP BACKUPSET ALL DELETE INPUT;
RMAN> BACKUP AS COPY DATAFILECOPY ALL DELETE INPUT;
Where are the files, now?
Control files, Data files, Online Log Files, Tempfile, Archiv Log files?
Control files:
SQL> show parameter control_files
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
control_files string +DATA/orcl/controlfile/current
.276.786977643, +FRA/orcl/cont
rolfile/current.256.786977643
SQL> select name from v$controlfile;
NAME
------------------------------------------------------------
+DATA/orcl/controlfile/current.276.786977643
+FRA/orcl/controlfile/current.256.786977643
Online log files:
SQL> select a.group#, a.status, b.member from v$log a,v$logfile b where a.group#=b.group# order by group#;
GROUP# STATUS MEMBER
---------- ---------------- --------------------------------------------------
4 INACTIVE +DATA/orcl/onlinelog/group_4.266.786980949
4 INACTIVE +FRA/orcl/onlinelog/group_4.259.786980949
5 CURRENT +DATA/orcl/onlinelog/group_5.262.786980955
5 CURRENT +FRA/orcl/onlinelog/group_5.258.786980957
6 INACTIVE +DATA/orcl/onlinelog/group_6.264.786980963
6 INACTIVE +FRA/orcl/onlinelog/group_6.257.786980963
6 rows selected.
Datafiles:
SQL> select name from v$datafile;
NAME
------------------------------------------------------------
+DATA/orcl/datafile/system.270.786932029
+DATA/orcl/datafile/sysaux.273.786932071
+DATA/orcl/datafile/undotbs1.279.786932105
+DATA/orcl/datafile/users.286.786932109
SQL> select name from v$datafile_header;
NAME
------------------------------------------------------------
+DATA/orcl/datafile/system.270.786932029
+DATA/orcl/datafile/sysaux.273.786932071
+DATA/orcl/datafile/undotbs1.279.786932105
+DATA/orcl/datafile/users.286.786932109
Tempfile:
SQL> select name from v$tempfile;
NAME
----------------------------------------------------------------------
+DATA/orcl/tempfile/temp.265.786980893
Diskgroup
[oracle@oel62 ~]$ su - grid
[grid@oel62 ~]$ rlwrap asmcmd -p
ASMCMD [+] > ls
DATA/
FRA/
Online log files:
ASMCMD [+] > find --type onlinelog . *
+DATA/ORCL/ONLINELOG/group_4.266.786980949
+DATA/ORCL/ONLINELOG/group_5.262.786980955
+DATA/ORCL/ONLINELOG/group_6.264.786980963
+FRA/ORCL/ONLINELOG/group_4.259.786980949
+FRA/ORCL/ONLINELOG/group_5.258.786980957
+FRA/ORCL/ONLINELOG/group_6.257.786980963
Control files:
ASMCMD [+] > find --type controlfile . *
+DATA/ORCL/CONTROLFILE/Backup.260.786932109
+DATA/ORCL/CONTROLFILE/current.276.786977643
+FRA/ORCL/CONTROLFILE/current.256.786977643
Datafiles:
ASMCMD [+] > find --type datafile . *
+DATA/ORCL/DATAFILE/SYSAUX.273.786932071
+DATA/ORCL/DATAFILE/SYSTEM.270.786932029
+DATA/ORCL/DATAFILE/UNDOTBS1.279.786932105
+DATA/ORCL/DATAFILE/USERS.286.786932109
+FRA/ORCL/DATAFILE/SYSAUX.263.786981205
+FRA/ORCL/DATAFILE/SYSTEM.264.786981149
+FRA/ORCL/DATAFILE/UNDOTBS1.262.786981251
+FRA/ORCL/DATAFILE/USERS.261.786981257
Archive log files:
ASMCMD [+] > find --type archivelog . *
+FRA/ORCL/ARCHIVELOG/2012_06_26/thread_1_seq_10.271.786981119
+FRA/ORCL/ARCHIVELOG/2012_06_26/thread_1_seq_11.270.786981119
+FRA/ORCL/ARCHIVELOG/2012_06_26/thread_1_seq_4.267.786981111
+FRA/ORCL/ARCHIVELOG/2012_06_26/thread_1_seq_5.266.786981113
+FRA/ORCL/ARCHIVELOG/2012_06_26/thread_1_seq_6.265.786981113
+FRA/ORCL/ARCHIVELOG/2012_06_26/thread_1_seq_7.274.786981115
+FRA/ORCL/ARCHIVELOG/2012_06_26/thread_1_seq_8.273.786981115
+FRA/ORCL/ARCHIVELOG/2012_06_26/thread_1_seq_9.272.786981117
Tempfiles:
ASMCMD [+] > find --type tempfile . *
+DATA/ORCL/TEMPFILE/TEMP.265.786980893
[oracle@oel62 ~]$ ls -r /u01/app/oracle/oradata/orcl/
temp01.dbf redo03.log redo02.log redo01.log control01.ctl
[oracle@oel62 ~]$ ls -r /u01/app/oracle/fast_recovery_area/orcl/
control02.ctl
Source: http://localhost/oradoc/server.112/e16102/asm_rman.htm#i1022780