27
Database Migration to Oracle Automatic Storage Management (ASM) Alejandro Vargas Oracle Support Israel Principal Support Consultant Introduction ......................................................................................................................................................................................... 3 Migration Procedure Description ......................................................................................................................................................... 3 Database Migration to ASM, List of Steps ........................................................................................................................................... 4 Database Migration to ASM, Execution Step by Step ......................................................................................................................... 5 1) Check amount of space required by the database inside ASM .................................................................................................. 5 2) Check amount of space available on ASM ................................................................................................................................. 6 3) If the database is not in archive log, enable archiving ................................................................................................................ 7 4) If block change tracking is not enabled enable it. ....................................................................................................................... 8 5) Make a Backup as copy of the database on the chosen ASM diskgroup ................................................................................... 9 6) Archive log current ................................................................................................................................................................... 11 7) Take an incremental backup and recover the level 0 backup previously done ......................................................................... 11 8) Create a copy of the SPFILE in the ASM disk group. ............................................................................................................... 14 9) Perform a consistent shutdown of the database ....................................................................................................................... 16 10) Create an pfile specifying the location of the new SPFILE. ..................................................................................................... 16 11) Start the database in NOMOUNT mode .................................................................................................................................. 17 12) Migrate the control file to ASM ................................................................................................................................................ 17 13) Set flash recovery area size and destination. .......................................................................................................................... 18 14) Shutdown and startup nomount to make active last changes to spfile .................................................................................... 18

Database Migration to - UserLand Softwarestatic7.userland.com/oracle/gems/alejandroVargas/DatabaseMigration... · Database Migration to Oracle Automatic Storage Management ... List

  • Upload
    vophuc

  • View
    224

  • Download
    2

Embed Size (px)

Citation preview

Page 1: Database Migration to - UserLand Softwarestatic7.userland.com/oracle/gems/alejandroVargas/DatabaseMigration... · Database Migration to Oracle Automatic Storage Management ... List

Database Migration to Oracle Automatic Storage Management (ASM)

Alejandro Vargas

Oracle Support Israel Principal Support Consultant

Introduction ......................................................................................................................................................................................... 3 Migration Procedure Description ......................................................................................................................................................... 3 Database Migration to ASM, List of Steps........................................................................................................................................... 4 Database Migration to ASM, Execution Step by Step ......................................................................................................................... 5

1) Check amount of space required by the database inside ASM .................................................................................................. 5 2) Check amount of space available on ASM ................................................................................................................................. 6 3) If the database is not in archive log, enable archiving ................................................................................................................ 7 4) If block change tracking is not enabled enable it. ....................................................................................................................... 8 5) Make a Backup as copy of the database on the chosen ASM diskgroup ................................................................................... 9 6) Archive log current ................................................................................................................................................................... 11 7) Take an incremental backup and recover the level 0 backup previously done......................................................................... 11 8) Create a copy of the SPFILE in the ASM disk group. ............................................................................................................... 14 9) Perform a consistent shutdown of the database....................................................................................................................... 16 10) Create an pfile specifying the location of the new SPFILE. ..................................................................................................... 16 11) Start the database in NOMOUNT mode .................................................................................................................................. 17 12) Migrate the control file to ASM ................................................................................................................................................ 17 13) Set flash recovery area size and destination. .......................................................................................................................... 18 14) Shutdown and startup nomount to make active last changes to spfile .................................................................................... 18

Page 2: Database Migration to - UserLand Softwarestatic7.userland.com/oracle/gems/alejandroVargas/DatabaseMigration... · Database Migration to Oracle Automatic Storage Management ... List

15) Restore the Control Files into ASM with RMAN ...................................................................................................................... 19 15) Mount the database................................................................................................................................................................. 20 16) Execute Rman Switch Database to Copy................................................................................................................................ 20 17) Execute Recover Database..................................................................................................................................................... 21 18) Migrate Tempfiles to ASM. ...................................................................................................................................................... 21 19) Move Flashback Logs Into ASM Flash Recovery Area ........................................................................................................... 22 20) Move RMAN Change Tracking File Into ASM ......................................................................................................................... 22 21) Open The Database. ............................................................................................................................................................... 23 22) Migrate The online logs Into ASM ........................................................................................................................................... 23 23) Check Oracle Files .................................................................................................................................................................. 25 24) Remove the File System Old Files .......................................................................................................................................... 26 25) Rename the temporary pfile .................................................................................................................................................... 26 End of the procedure. .................................................................................................................................................................... 27

Page 3: Database Migration to - UserLand Softwarestatic7.userland.com/oracle/gems/alejandroVargas/DatabaseMigration... · Database Migration to Oracle Automatic Storage Management ... List

Introduction

ASM has become main stream with critical production implementations around the world, and many other planning to move from earlier releases to 10g and ASM. ASM has proved to be a strong technology delivering management simplicity and best performance for Oracle databases. This document describes the procedure to migrate a database from any kind of storage to ASM storage. This procedure is one option from several options available to migrate to ASM. I did choose to test and describe this procedure because it is probably the most efficient and simple available. It will permit the migration databases of all sizes with a minimal downtime window.

Migration Procedure Description

The migration procedure is implemented using Rman backup as copy incremental level 0, inside ASM. The level 0 backup is followed by one ore more incremental level 1 backups. The incremental backups are used to keep the level 0 backup in sync with the database until downtime is approved. When downtime is available we will take the last incremental backup level 1, we will recover the Level 0 backup with it and we will switch the database with the ASM based copy. This procedure does require preparing an empty ASM diskgroup as big as the size of the actual database we will migrate. This procedure consists of 25 steps that can be run from scripts prepared in advance to minimize execution time.

Page 4: Database Migration to - UserLand Softwarestatic7.userland.com/oracle/gems/alejandroVargas/DatabaseMigration... · Database Migration to Oracle Automatic Storage Management ... List

Database Migration to ASM, List of Steps

1) Check Amount Of Space Required By The Database Inside ASM 2) Check Amount Of Space Available On ASM 3) If The Database Is Not In Archive Log, Enable Archiving 4) If Rman Block Change Tracking Is Not Enabled Enable It. 5) Make A Backup As Copy Of The Database On The Chosen ASM Diskgroup 6) Archive Log Current 7) Take An Incremental Backup And Recover The Level 0 Backup Previously Done 8) Create A Copy Of The SPFILE In The ASM Disk Group. 9) Perform A Consistent Shutdown Of The Database 10) Create An Pfile Specifying The Location Of The New SPFILE. 11) Start The Database In NOMOUNT Mode 12) Migrate The Control File To ASM 13) Set Flash Recovery Area Size And Destination. 14) Shutdown And Startup Nomount To Make Active Last Changes To Spfile 15) Restore The Control Files Into ASM With RMAN 16) Execute Rman Switch Database To Copy 17) Execute Recover Database 18) Migrate Temporary Files To ASM. 19) Move Flashback Logs Into ASM Flash Recovery Area 20) Move RMAN Change Tracking File Into ASM 21) Open The Database. 22) Migrate The Online Logs Into ASM 23) Check Oracle Files 24) Remove The File System Old Files 25) Rename The Temporary Pfile

Page 5: Database Migration to - UserLand Softwarestatic7.userland.com/oracle/gems/alejandroVargas/DatabaseMigration... · Database Migration to Oracle Automatic Storage Management ... List

Database Migration to ASM, Execution Step by Step

1) Check amount of space required by the database inside ASM

The environment used to implement this test is based on an 11g ASM instance and a 10g Database based on filesystem:

ORA Environnement Variables: ASM_HOME=/oradisk/app01/oracle/product/11db ORACLE_BASE=/oradisk/app01/oracle ORACLE_HOME=/oradisk/app01/oracle/product/10db ORACLE_SID=redx ORACLE_TERM=xsun5 ----------- ORACLE Databases Running: oracle 4591 1 0 05:19 ? 00:00:00 asm_smon_+ASM oracle 4717 1 1 05:26 ? 00:00:03 ora_smon_redx ----------- ORACLE Databases registered in Oratab: +ASM:/oradisk/app01/oracle/product/11db:N redx:/oradisk/app01/oracle/product/10db:N

In this first step we check the amount of space required by the database inside ASM

SQL> select sum(bytes)/1024/1024/1024 from v$datafile;

Page 6: Database Migration to - UserLand Softwarestatic7.userland.com/oracle/gems/alejandroVargas/DatabaseMigration... · Database Migration to Oracle Automatic Storage Management ... List

SUM(BYTES)/1024/1024/1024 ------------------------- .737304688 SQL> select sum(bytes)/1024/1024/1024 from v$log; SUM(BYTES)/1024/1024/1024 ------------------------- .146484375 SQL> select sum(bytes)/1024/1024/1024 from v$tempfile; SUM(BYTES)/1024/1024/1024 ------------------------- .01953125

In this test the total amount of space required is about 0.9 GB

2) Check amount of space available on ASM We have 2 diskgroups with enough free space for the database. {oracle} /oradisk/app01/oracle/scripts/av [pollux.com] > asmcmd lsdg State Type Rebal Sector Block AU Total_MB Free_MB Req_mir_free_MB Usable_file_MB Offline_disks Name MOUNTED EXTERN N 512 4096 1048576 4820 2876 0 2876 0 DB1DATADG/ MOUNTED EXTERN N 512 4096 1048576 2892 2661 0 2661 0 DB1FRADG/ MOUNTED EXTERN N 512 4096 1048576 1928 888 0 888 0 DB2TST1DG/ MOUNTED EXTERN N 512 4096 1048576 1928 1036 0 1036 0 DB3CLNDG/ We will use Diskgroup DB1DATADG that has 2.8 GB available for the database, and DB1FRADG for the Flash Recovery Area.

Page 7: Database Migration to - UserLand Softwarestatic7.userland.com/oracle/gems/alejandroVargas/DatabaseMigration... · Database Migration to Oracle Automatic Storage Management ... List

3) If the database is not in archive log, enable archiving

In order to use this procedure the database must be on archive log mode.

{oracle} /oradisk/app01/oracle/scripts/av/fs-to-asm [pollux.com] > sql SQL*Plus: Release 10.2.0.3.0 - Production on Mon Dec 24 05:55:30 2007 Copyright (c) 1982, 2006, Oracle. All Rights Reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production With the Partitioning, OLAP and Data Mining options SQL> shutdown immediate; Database closed. Database dismounted. ORACLE instance shut down. SQL> startup mount; ORACLE instance started. Fixed Size 1260696 bytes Variable Size 83886952 bytes Database Buffers 79691776 bytes Redo Buffers 2932736 bytes

Page 8: Database Migration to - UserLand Softwarestatic7.userland.com/oracle/gems/alejandroVargas/DatabaseMigration... · Database Migration to Oracle Automatic Storage Management ... List

Database mounted. SQL> alter database archivelog; Database altered. SQL> alter database open; Database altered. SQL> archive log list Database log mode Archive Mode Automatic archival Enabled Archive destination USE_DB_RECOVERY_FILE_DEST Oldest online log sequence 19 Next log sequence to archive 21 Current log sequence 21 SQL> show parameters db_recovery_file NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ db_recovery_file_dest string /oradisk/app01/oracle/flash_re covery_area db_recovery_file_dest_size big integer 2G

4) If block change tracking is not enabled enable it.

Block change tracking will help us to fasten the performance of the incremental backup that is part of point 7 of this procedure, if it is not already enabled we will enable it.

Page 9: Database Migration to - UserLand Softwarestatic7.userland.com/oracle/gems/alejandroVargas/DatabaseMigration... · Database Migration to Oracle Automatic Storage Management ... List

SQL> alter database enable block change tracking; Database altered.

5) Make a Backup as copy of the database on the chosen ASM diskgroup

Backup as copy make exact copies of the datafiles, a database can be started from this datafile copies. In addition we "tag" this backup in order to easily refer to it on the next steps.

{oracle} /oradisk/app01/oracle/scripts/av/fs-to-asm [pollux.com] > rman target / Recovery Manager: Release 10.2.0.3.0 - Production on Mon Dec 24 05:59:15 2007 Copyright (c) 1982, 2005, Oracle. All rights reserved. connected to target database: REDX (DBID=2305343033) RMAN> BACKUP AS COPY INCREMENTAL LEVEL 0 DATABASE 2> FORMAT '+DB1DATADG' TAG 'ORA_ASM_MIGRATION'; Starting backup at 24/12/2007 06:00:59 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: sid=142 devtype=DISK channel ORA_DISK_1: starting datafile copy

Page 10: Database Migration to - UserLand Softwarestatic7.userland.com/oracle/gems/alejandroVargas/DatabaseMigration... · Database Migration to Oracle Automatic Storage Management ... List

input datafile fno=00001 name=/oradisk/app01/oracle/oradata/REDX/datafile/o1_mf_system_3pgvow06_.dbf output filename=+DB1DATADG/redx/datafile/system.275.642146477 tag=ORA_ASM_MIGRATION recid=2 stamp=642146555 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:01:37 channel ORA_DISK_1: starting datafile copy input datafile fno=00002 name=/oradisk/app01/oracle/oradata/REDX/datafile/o1_mf_undotbs1_3pgw0h1y_.dbf output filename=+DB1DATADG/redx/datafile/undotbs1.278.642146567 tag=ORA_ASM_MIGRATION recid=3 stamp=642146609 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:56 channel ORA_DISK_1: starting datafile copy input datafile fno=00003 name=/oradisk/app01/oracle/oradata/REDX/datafile/o1_mf_sysaux_3pgw2xms_.dbf output filename=+DB1DATADG/redx/datafile/sysaux.276.642146619 tag=ORA_ASM_MIGRATION recid=4 stamp=642146653 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:36 channel ORA_DISK_1: starting datafile copy input datafile fno=00004 name=/oradisk/app01/oracle/oradata/REDX/datafile/o1_mf_users_3pgw7jcd_.dbf output filename=+DB1DATADG/redx/datafile/users.279.642146655 tag=ORA_ASM_MIGRATION recid=5 stamp=642146657 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:04 channel ORA_DISK_1: starting datafile copy copying current control file output filename=+DB1DATADG/redx/controlfile/backup.280.642146663 tag=ORA_ASM_MIGRATION recid=6 stamp=642146665 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07 channel ORA_DISK_1: starting incremental level 0 datafile backupset channel ORA_DISK_1: specifying datafile(s) in backupset

Page 11: Database Migration to - UserLand Softwarestatic7.userland.com/oracle/gems/alejandroVargas/DatabaseMigration... · Database Migration to Oracle Automatic Storage Management ... List

including current SPFILE in backupset channel ORA_DISK_1: starting piece 1 at 24/12/2007 06:04:29 channel ORA_DISK_1: finished piece 1 at 24/12/2007 06:04:34 piece handle=+DB1DATADG/redx/backupset/2007_12_24/nnsnn0_ora_asm_migration_0.284.642146673 tag=ORA_ASM_MIGRATION comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07 Finished backup at 24/12/2007 06:04:34

6) Archive log current

From within rman execute the archive log current command to assure all online logs are written to disk.

RMAN> sql 'alter system archive log current'; sql statement: alter system archive log current

7) Take an incremental backup and recover the level 0 backup previously done

If this is a big and active database the backup may take a long time, in order to capture all changes since the backup time we will execute an incremental level 1 backup for update of the backup already done. We may need to execute this steps several times until we get an authorized downtime window.

When downtime is authorized we can shutdown and mount the database, then proceed to take a last incremental level 1 backup for restore of the level 0 backup as copy, and proceed with steps 8 to 24.

On this test, to simulate activity I will create a user and a table:

Page 12: Database Migration to - UserLand Softwarestatic7.userland.com/oracle/gems/alejandroVargas/DatabaseMigration... · Database Migration to Oracle Automatic Storage Management ... List

SQL> conn / as sysdba; Connected. SQL> create user avargas identified by oracle default tablespace users temporary tablespace temp; User created. SQL> grant dba to avargas; Grant succeeded. SQL> conn avargas/oracle Connected. SQL> create table usersdb as select * from dba_users; Table created.

Now we can create the new backup and recover the level 0 backup with all changes that happened since it was taken. This step is to be repeated every couple of hours until downtime is authorized, at this moment the database should be shut down and started up mount to take the last incremental level 1 backup.

RMAN> backup incremental level 1 2> for recover of copy with tag 'ORA_ASM_MIGRATION' 3> database; Starting backup at 24/12/2007 06:13:35 using channel ORA_DISK_1

Page 13: Database Migration to - UserLand Softwarestatic7.userland.com/oracle/gems/alejandroVargas/DatabaseMigration... · Database Migration to Oracle Automatic Storage Management ... List

channel ORA_DISK_1: starting incremental level 1 datafile backupset channel ORA_DISK_1: specifying datafile(s) in backupset input datafile fno=00001 name=/oradisk/app01/oracle/oradata/REDX/datafile/o1_mf_system_3pgvow06_.dbf input datafile fno=00002 name=/oradisk/app01/oracle/oradata/REDX/datafile/o1_mf_undotbs1_3pgw0h1y_.dbf input datafile fno=00003 name=/oradisk/app01/oracle/oradata/REDX/datafile/o1_mf_sysaux_3pgw2xms_.dbf input datafile fno=00004 name=/oradisk/app01/oracle/oradata/REDX/datafile/o1_mf_users_3pgw7jcd_.dbf channel ORA_DISK_1: starting piece 1 at 24/12/2007 06:13:37 channel ORA_DISK_1: finished piece 1 at 24/12/2007 06:14:53 piece handle=/oradisk/app01/oracle/flash_recovery_area/REDX/backupset/2007_12_24/o1_mf_nnnd1_TAG20071224T061335_3pydhl8o_.bkp tag=TAG20071224T061335 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:01:17 channel ORA_DISK_1: starting incremental level 1 datafile backupset channel ORA_DISK_1: specifying datafile(s) in backupset including current control file in backupset including current SPFILE in backupset channel ORA_DISK_1: starting piece 1 at 24/12/2007 06:14:55 channel ORA_DISK_1: finished piece 1 at 24/12/2007 06:14:57 piece handle=/oradisk/app01/oracle/flash_recovery_area/REDX/backupset/2007_12_24/o1_mf_ncsn1_TAG20071224T061335_3pydl07c_.bkp tag=TAG20071224T061335 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:04 Finished backup at 24/12/2007 06:14:57

Once the incremental level 1 backup is ready we can use it to update the full backup level 0 we did take before

Page 14: Database Migration to - UserLand Softwarestatic7.userland.com/oracle/gems/alejandroVargas/DatabaseMigration... · Database Migration to Oracle Automatic Storage Management ... List

RMAN> recover copy of database with tag 'ORA_ASM_MIGRATION'; Starting recover at 24/12/2007 19:22:33 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: sid=149 devtype=DISK channel ORA_DISK_1: starting incremental datafile backupset restore channel ORA_DISK_1: specifying datafile copies to recover recovering datafile copy fno=00001 name=+DB1DATADG/redx/datafile/system.275.642146477 recovering datafile copy fno=00002 name=+DB1DATADG/redx/datafile/undotbs1.278.642146567 recovering datafile copy fno=00003 name=+DB1DATADG/redx/datafile/sysaux.276.642146619 recovering datafile copy fno=00004 name=+DB1DATADG/redx/datafile/users.279.642146655 channel ORA_DISK_1: reading from backup piece /oradisk/app01/oracle/flash_recovery_area/REDX/backupset/2007_12_24/o1_mf_nnnd1_TAG20071224T061335_3pydhl8o_.bkp channel ORA_DISK_1: restored backup piece 1 piece handle=/oradisk/app01/oracle/flash_recovery_area/REDX/backupset/2007_12_24/o1_mf_nnnd1_TAG20071224T061335_3pydhl8o_.bkp tag=TAG20071224T061335 channel ORA_DISK_1: restore complete, elapsed time: 00:00:15 Finished recover at 24/12/2007 19:22:53

8) Create a copy of the SPFILE in the ASM disk group.

In order to create an spfile copy inside the ASM diskgroup we will make a backup of the actual spfile and then we will restore it into the ASM diskgroup.

Page 15: Database Migration to - UserLand Softwarestatic7.userland.com/oracle/gems/alejandroVargas/DatabaseMigration... · Database Migration to Oracle Automatic Storage Management ... List

RMAN> run { BACKUP AS BACKUPSET SPFILE; 2> RESTORE SPFILE TO "+DB1DATADG/redx/spfileredx.ora";} Starting backup at 24/12/2007 19:38:06 using channel ORA_DISK_1 channel ORA_DISK_1: starting full datafile backupset channel ORA_DISK_1: specifying datafile(s) in backupset including current SPFILE in backupset channel ORA_DISK_1: starting piece 1 at 24/12/2007 19:38:08 channel ORA_DISK_1: finished piece 1 at 24/12/2007 19:38:10 piece handle=/oradisk/app01/oracle/flash_recovery_area/REDX/backupset/2007_12_24/o1_mf_nnsnf_TAG20071224T193807_3pzvn1hv_.bkp tag=TAG20071224T193807 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03 Finished backup at 24/12/2007 19:38:10 Starting restore at 24/12/2007 19:38:11 using channel ORA_DISK_1 channel ORA_DISK_1: starting datafile backupset restore channel ORA_DISK_1: restoring SPFILE output filename=+DB1DATADG/redx/spfileredx.ora channel ORA_DISK_1: reading from backup piece /oradisk/app01/oracle/flash_recovery_area/REDX/backupset/2007_12_24/o1_mf_nnsnf_TAG20071224T193807_3pzvn1hv_.bkp channel ORA_DISK_1: restored backup piece 1 piece handle=/oradisk/app01/oracle/flash_recovery_area/REDX/backupset/2007_12_24/o1_mf_nnsnf_TAG20071224T193807_3pzvn1hv_.bkp tag=TAG20071224T193807 channel ORA_DISK_1: restore complete, elapsed time: 00:00:15

Page 16: Database Migration to - UserLand Softwarestatic7.userland.com/oracle/gems/alejandroVargas/DatabaseMigration... · Database Migration to Oracle Automatic Storage Management ... List

Finished restore at 24/12/2007 19:38:29

Confirm that the spfile was created:

{oracle} /home/oracle [pollux.com] > asmcmd ls +DB1DATADG/redx/spfileredx.ora spfileredx.ora

9) Perform a consistent shutdown of the database

RMAN> shutdown immediate; database closed database dismounted Oracle instance shut down

10) Create an pfile specifying the location of the new SPFILE.

A temporary pfile needs to be created to implement the following steps On the $ORACLE_HOME/dbs directory create the pfile including only the SPFILE parameter pointing to the spfile inside ASM

{oracle} > cd $ORACLE_HOME/dbs {oracle} > echo "SPFILE=+DB1DATADG/redx/spfileredx.ora" >initredx.ora.new

Page 17: Database Migration to - UserLand Softwarestatic7.userland.com/oracle/gems/alejandroVargas/DatabaseMigration... · Database Migration to Oracle Automatic Storage Management ... List

11) Start the database in NOMOUNT mode

At this moment we have two copies of the database datafiles, the old one on File System and the new one on ASM. Both copies are in sync. On the next steps we will migrate all other oracle files into ASM: controlfiles, online redologs, flashback logs, block change tracking file. To start this we need to start the database in nomount mode:

{oracle} /oradisk/app01/oracle/scripts/av/fs-to-asm [pollux.com] > sqlplus / as sysdba SQL*Plus: Release 10.2.0.3.0 - Production on Mon Dec 24 19:58:56 2007 Copyright (c) 1982, 2006, Oracle. All Rights Reserved. Connected to an idle instance. SQL> startup nomount pfile='/oradisk/app01/oracle/product/10db/dbs/initredx.ora.new' ORACLE instance started. Total System Global Area 167772160 bytes Fixed Size 1260696 bytes Variable Size 92275560 bytes Database Buffers 71303168 bytes Redo Buffers 2932736 bytes

12) Migrate the control file to ASM

On this step we will prepare the spfile to later move the controlfiles inside ASM.

Page 18: Database Migration to - UserLand Softwarestatic7.userland.com/oracle/gems/alejandroVargas/DatabaseMigration... · Database Migration to Oracle Automatic Storage Management ... List

We pass only the location of the controlfiles, disk groups DB1DATADG and DB1FRADG, but not the controlfile names. The name will be automatically generated because we are using Oracle Managed Files.

SQL> alter system set control_files='+DB1DATADG','+DB1FRADG' scope=spfile sid='*'; System altered. System altered.

13) Set flash recovery area size and destination.

On this step we will set the Flash Recovery Area into ASM diskgroup DB1FRADG

SQL> alter system set DB_RECOVERY_FILE_DEST_SIZE=2g scope=spfile sid='*'; System altered. SQL> alter system set DB_RECOVERY_FILE_DEST='+DB1FRADG' scope=spfile sid='*'; System altered.

14) Shutdown and startup nomount to make active last changes to spfile

SQL> shutdown immediate; ORA-01507: database not mounted

Page 19: Database Migration to - UserLand Softwarestatic7.userland.com/oracle/gems/alejandroVargas/DatabaseMigration... · Database Migration to Oracle Automatic Storage Management ... List

ORACLE instance shut down. SQL> startup nomount pfile='/oradisk/app01/oracle/product/10db/dbs/initredx.ora.new' ORACLE instance started. Total System Global Area 167772160 bytes Fixed Size 1260696 bytes Variable Size 96469864 bytes Database Buffers 67108864 bytes Redo Buffers 2932736 bytes

15) Restore the Control Files into ASM with RMAN

From an Rman session we will restore the controlfiles inside ASM using the controlfile that is located on file system.

{oracle} /oradisk/app01/oracle [pollux.com] > rman target / Recovery Manager: Release 10.2.0.3.0 - Production on Mon Dec 24 20:54:27 2007 Copyright (c) 1982, 2005, Oracle. All rights reserved. connected to target database: redx (not mounted) RMAN> restore controlfile from '/oradisk/app01/oracle/oradata/REDX/controlfile/o1_mf_3pgvds25_.ctl'; Starting restore at 24/12/2007 20:55:14 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1

Page 20: Database Migration to - UserLand Softwarestatic7.userland.com/oracle/gems/alejandroVargas/DatabaseMigration... · Database Migration to Oracle Automatic Storage Management ... List

channel ORA_DISK_1: sid=156 devtype=DISK channel ORA_DISK_1: copied control file copy output filename=+DB1DATADG/redx/controlfile/current.283.642200127 output filename=+DB1FRADG/redx/controlfile/current.354.642200137 Finished restore at 24/12/2007 20:55:44

15) Mount the database

Once having had migrated the controlfiles inside ASM we can mount the database from the same Rman session

RMAN> alter database mount; database mounted released channel: ORA_DISK_1

16) Execute Rman Switch Database to Copy

At this moment all datafiles, controlfiles, and Flash Recovery Area are located inside ASM. We have the original database on File System synchronized with it's copy on ASM, we are ready to switch the database from the File System files to the ASM files. This is achieved using the Rman command "Switch database to copy"

RMAN> switch database to copy; datafile 1 switched to datafile copy "+DB1DATADG/redx/datafile/system.275.642146477"

Page 21: Database Migration to - UserLand Softwarestatic7.userland.com/oracle/gems/alejandroVargas/DatabaseMigration... · Database Migration to Oracle Automatic Storage Management ... List

datafile 2 switched to datafile copy "+DB1DATADG/redx/datafile/undotbs1.278.642146567" datafile 3 switched to datafile copy "+DB1DATADG/redx/datafile/sysaux.276.642146619" datafile 4 switched to datafile copy "+DB1DATADG/redx/datafile/users.279.642146655"

17) Execute Recover Database

RMAN> recover database; Starting recover at 24/12/2007 21:08:08 allocated channel: ORA_DISK_1 channel ORA_DISK_1: sid=151 devtype=DISK starting media recovery media recovery complete, elapsed time: 00:00:11 Finished recover at 24/12/2007 21:08:26

18) Migrate Tempfiles to ASM.

On this step we will migrate from Rman the Oracle temporary files inside ASM.

RMAN> run { set newname for tempfile 1 to '+DB1DATADG' ; 2> switch tempfile all;} executing command: SET NEWNAME using target database control file instead of recovery catalog

Page 22: Database Migration to - UserLand Softwarestatic7.userland.com/oracle/gems/alejandroVargas/DatabaseMigration... · Database Migration to Oracle Automatic Storage Management ... List

renamed temporary file 1 to +DB1DATADG in control file

19) Move Flashback Logs Into ASM Flash Recovery Area

Flashback logs cannot be migrated into ASM, in order to move the flashback log destination into ASM we need to set flashback off and on, this will enable creating the Flashback logs into the Flash recovery Area defined into an ASM diskgroup.

SQL> ALTER DATABASE FLASHBACK OFF; Database altered. SQL> ALTER DATABASE FLASHBACK ON; Database altered.

20) Move RMAN Change Tracking File Into ASM

Rman Change Tracking File logs cannot be migrated into ASM, in order to move the Change Tracking File location into ASM we need to disable and enable Block Change Tracking into an ASM diskgroup.

SQL> alter database disable block change tracking; Database altered. SQL> alter database enable block change tracking using file '+DB1DATADG';

Page 23: Database Migration to - UserLand Softwarestatic7.userland.com/oracle/gems/alejandroVargas/DatabaseMigration... · Database Migration to Oracle Automatic Storage Management ... List

Database altered.

21) Open The Database.

At this point the database can be opened

SQL> alter database open; Database altered.

22) Migrate The online logs Into ASM

The only oracle files still on file system are the online redo logs, we will create new redo log groups inside ASM and drop the old groups located on File System. To do that we will use a PL/Sql script provided on the Rman Advanced techniques manual.

----- script changelogs.sql start on next line ----- declare cursor rlc is select group# grp, thread# thr, bytes/1024 bytes_k, 'NO' srl from v$log union select group# grp, thread# thr, bytes/1024 bytes_k, 'YES' srl from v$standby_log order by 1; stmt varchar2(2048);

Page 24: Database Migration to - UserLand Softwarestatic7.userland.com/oracle/gems/alejandroVargas/DatabaseMigration... · Database Migration to Oracle Automatic Storage Management ... List

swtstmt varchar2(1024) := 'alter system switch logfile'; ckpstmt varchar2(1024) := 'alter system checkpoint global'; begin for rlcRec in rlc loop if (rlcRec.srl = 'YES') then stmt := 'alter database add standby logfile thread ' || rlcRec.thr || ' ''+DB1DATADG'' size ' || rlcRec.bytes_k || 'K'; execute immediate stmt; stmt := 'alter database drop standby logfile group ' || rlcRec.grp; execute immediate stmt; else stmt := 'alter database add logfile thread ' || rlcRec.thr || ' ''+DB1DATADG'' size ' || rlcRec.bytes_k || 'K'; execute immediate stmt; begin stmt := 'alter database drop logfile group ' || rlcRec.grp; dbms_output.put_line(stmt); execute immediate stmt; exception when others then execute immediate swtstmt; execute immediate ckpstmt; execute immediate stmt; end; end if; end loop; end; /

Page 25: Database Migration to - UserLand Softwarestatic7.userland.com/oracle/gems/alejandroVargas/DatabaseMigration... · Database Migration to Oracle Automatic Storage Management ... List

----- script end on previous line -----

SQL> alter system archive log current; System altered. SQL> @changelogs PL/SQL procedure successfully completed. SQL> select member from v$logfile; MEMBER -------------------------------------------------------------------------------- +DB1DATADG/redx/onlinelog/group_1.270.642202299 +DB1DATADG/redx/onlinelog/group_2.281.642202315 +DB1DATADG/redx/onlinelog/group_4.271.642202283

23) Check Oracle Files

With the previous step the migration was completed, we can check the new location for the database files:

SQL> select name from v$datafile; NAME -------------------------------------------------------------------------------- +DB1DATADG/redx/datafile/system.275.642146477 +DB1DATADG/redx/datafile/undotbs1.278.642146567 +DB1DATADG/redx/datafile/sysaux.276.642146619

Page 26: Database Migration to - UserLand Softwarestatic7.userland.com/oracle/gems/alejandroVargas/DatabaseMigration... · Database Migration to Oracle Automatic Storage Management ... List

+DB1DATADG/redx/datafile/users.279.642146655 SQL> select name from v$tempfile; NAME -------------------------------------------------------------------------------- +DB1DATADG/redx/tempfile/temp.272.642201919 SQL> select name from v$controlfile; NAME -------------------------------------------------------------------------------- +DB1DATADG/redx/controlfile/current.283.642200127 +DB1FRADG/redx/controlfile/current.354.642200137

24) Remove the File System Old Files

{oracle} /oradisk/app01/oracle/oradata [pollux.com] > ls REDX {oracle} /oradisk/app01/oracle/oradata [pollux.com] > rm -rf REDX/

25) Rename the temporary pfile

mv $ORACLE_HOME/dbs/initredx.ora.tmp $ORACLE_HOME/dbs/initredx.ora

Page 27: Database Migration to - UserLand Softwarestatic7.userland.com/oracle/gems/alejandroVargas/DatabaseMigration... · Database Migration to Oracle Automatic Storage Management ... List

End of the procedure.