sábado, 7 de marzo de 2009

Trasladando la Base de Datos hacia ASM

Cómo vuela el tiempo, ha pasado ya un mes desde mi último Post, mil disculpas, salí de vacaciones con toda la familia y aun cuando acostumbro tomarme unos días para reponerme de ellas, pues cuando son en familia es dificil descansar, a mi regreso tenía trabajo acumulado así que empecé una Consultoría en el día y el dictado del curso Performance Tuning 10g por las noches, manteniéndome bastante ocupado las últimas semanas. Hoy tengo algo de tiempo por lo que sin más demoras retomaré la serie que iniciara en el Post previo, recordarán que en él les mostré como instalar y configurar el software necesario, así como la creación de la instancia ASM; ahora continuaré con el traslado manual de la base de datos hacia ASM, incluyendo: spfile, control files, datafiles, online redo logs, archive logs, backups, tracking file y flashback logs, veamos entonces la secuencia de pasos a seguir.

Migración de la Base de Datos hacia ASM

1. Obtenemos un backup de los datafiles directamente hacia ASM, como copias y sobre el disk group +DAT.

RMAN> backup as copy incremental level 0 database
2> format '+DAT' tag 'migracion_asm';

Starting backup at 04/02/2009 04:10:11
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=120 device type=DISK
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf
output file name=+DAT/orcl/datafile/system.265.677909423 tag=MIGRACION_ASM RECID=2 STAMP=677909527
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:01:55
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf
output file name=+DAT/orcl/datafile/sysaux.264.677909533 tag=MIGRACION_ASM RECID=3 STAMP=677909606
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:01:26
channel ORA_DISK_1: starting datafile copy
input datafile file number=00005 name=/u01/app/oracle/oradata/orcl/example01.dbf
output file name=+DAT/orcl/datafile/example.258.677909617 tag=MIGRACION_ASM RECID=4 STAMP=677909630
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile copy
input datafile file number=00003 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf
output file name=+DAT/orcl/datafile/undotbs1.267.677909633 tag=MIGRACION_ASM RECID=5 STAMP=677909641
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile copy
copying current control file
output file name=+DAT/orcl/controlfile/backup.260.677909647 tag=MIGRACION_ASM RECID=6 STAMP=677909648
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf
output file name=+DAT/orcl/datafile/users.263.677909651 tag=MIGRACION_ASM RECID=7 STAMP=677909651
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting incremental level 0 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 04/02/2009 04:14:12
channel ORA_DISK_1: finished piece 1 at 04/02/2009 04:14:13
piece handle=+DAT/orcl/backupset/2009_02_04/nnsnn0_migracion_asm_0.259.677909653 tag=MIGRACION_ASM comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 04/02/2009 04:14:13

2. Creamos una copia del spfile en ASM, para lo cual lo restauramos a partir del backup obtenido en el paso anterior. Recuerda que si obtenemos un backup total o si en él está incluido el tablespace system, el spfile y el control file son automáticamente respaldados.

RMAN> restore spfile to "+DAT/orcl/spfileorcl.ora";

Starting restore at 04/02/2009 04:39:36
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=153 device type=DISK

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: restoring SPFILE
output file name=+DAT/orcl/spfileorcl.ora
channel ORA_DISK_1: reading from backup piece +DAT/orcl/backupset/2009_02_04/nnsnn0_migracion_asm_0.259.677909653
channel ORA_DISK_1: piece handle=+DAT/orcl/backupset/2009_02_04/nnsnn0_migracion_asm_0.259.677909653 tag=MIGRACION_ASM
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:07
Finished restore at 04/02/2009 04:39:44

3. Bajamos la base de datos para poder hacer algunos ajustes a la configuración de la instancia.

RMAN> shutdown immediate

database closed
database dismounted
Oracle instance shut down

4. Reemplazamos el spfile.ora por un init.ora que referencia al spfile que acabamos de copiar en ASM.

[oracle@urania ~]$ cd $ORACLE_HOME/dbs
[oracle@urania dbs]$ rm spfileorcl.ora
[oracle@urania dbs]$ more initorcl.ora
SPFILE='+DAT/orcl/spfileorcl.ora'

5. Levantamos la instancia solamente (nomount) y hacemos ajustes a los parámetros control_files, db_create_file_dest y db_recovery_file_dest para que ahora apunten a ubicaciones al interior de ASM.

SYS@orcl> startup nomount;
ORACLE instance started.

Total System Global Area  318046208 bytes
Fixed Size                  1313120 bytes
Variable Size             180356768 bytes
Database Buffers          130023424 bytes
Redo Buffers                6352896 bytes

SYS@orcl> alter system set control_files='+DAT','+FRA' scope=spfile;

System altered.

SYS@orcl> alter system set db_create_file_dest='+DAT';

System altered.

SYS@orcl> alter system set db_recovery_file_dest='+FRA';

System altered.

6. Para que estos cambios surtan efecto reiniciamos la instancia (nomount).

SYS@orcl> startup force nomount;
ORACLE instance started.

Total System Global Area  318046208 bytes
Fixed Size                  1313120 bytes
Variable Size             180356768 bytes
Database Buffers          130023424 bytes
Redo Buffers                6352896 bytes

7. Usamos RMAN para crear los control files dentro de ASM en base al existente fuera de él.

RMAN> restore controlfile from '/u01/app/oracle/oradata/orcl/control01.ctl';

Starting restore at 04/02/2009 04:45:23
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=151 device type=DISK

channel ORA_DISK_1: copied control file copy
output file name=+DAT/orcl/controlfile/current.269.677911525
output file name=+FRA/orcl/controlfile/current.265.677911527
Finished restore at 04/02/2009 04:45:28

8. Ahora montamos la base de datos y procedemos a actualizar el control file para que los datafiles existentes en ASM sean usados en lugar de los existentes fuera de él.

RMAN> alter database mount;

database mounted
released channel: ORA_DISK_1

RMAN> switch database to copy;

datafile 1 switched to datafile copy "+DAT/orcl/datafile/system.265.677909423"
datafile 2 switched to datafile copy "+DAT/orcl/datafile/sysaux.264.677909533"
datafile 3 switched to datafile copy "+DAT/orcl/datafile/undotbs1.267.677909633"
datafile 4 switched to datafile copy "+DAT/orcl/datafile/users.263.677909651"
datafile 5 switched to datafile copy "+DAT/orcl/datafile/example.258.677909617"

9. Como es posible que entre el momento que obtuvimos el backup del paso 1 y el momento en que hicimos el switch de los datafiles a ASM, se haya generado redo, hacemos un recover para tener los datafiles debidamente actualizados.

RMAN> recover database;

Starting recover at 04/02/2009 04:46:58
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=149 device type=DISK

starting media recovery
media recovery complete, elapsed time: 00:00:04

Finished recover at 04/02/2009 04:47:05

10. Los tempfiles no son respaldados y por tanto no son recuperables, lo que hace necesario recrearlos manualmente, ubicándose en ASM.

RMAN> run {
2> set newname for tempfile 1 to '+DAT';
3> switch tempfile all;
4> }

executing command: SET NEWNAME

renamed tempfile 1 to +DAT in control file

11. Si teníamos habilitado el block change tracking (es una "mejor práctica" si usamos Enterprise Edition), debemos deshabilitarlo temporalmente para habilitarlo nuevamente pero ahora dentro de ASM.

SYS@orcl> alter database disable block change tracking;

Database altered.

SYS@orcl> alter database enable block change tracking using file '+DAT';

Database altered.

12. Si estamos usando flashback logs, debemos proceder de forma similar al paso 11. Ojo que los flashback logs existentes fuera de ASM no pueden ser trasladados hacia ASM.

SYS@orcl> alter database flashback off;

Database altered.

SYS@orcl> alter database flashback on;

Database altered.

13. Finalmente podemos abrir la base de datos

SYS@orcl> alter database open;

Database altered.

14. Los más observadores ya lo habrán notado: los redo logs aún están fuera de ASM, hay que crear nuevos y deshacernos de los antiguos.

SYS@orcl> select a.group#, b.member, a.status
  2  from v$log a, v$logfile b
  3  where a.group#=b.group#
  4  order by a.group#;

 GROUP# MEMBER                                   STATUS
------- ---------------------------------------- ---------
      1 /u01/app/oracle/oradata/orcl/redo01.log  CURRENT
      2 /u01/app/oracle/oradata/orcl/redo02.log  INACTIVE
      3 /u01/app/oracle/oradata/orcl/redo03.log  INACTIVE

6 rows selected.

SYS@orcl> alter database add logfile size 50M;

Database altered.

SYS@orcl> alter database add logfile size 50M;

Database altered.

SYS@orcl> alter database add logfile size 50M;

Database altered.

SYS@orcl> alter database drop logfile group 2;

Database altered.

SYS@orcl> alter database drop logfile group 3;

Database altered.

SYS@orcl> alter system switch logfile;

System altered.

SYS@orcl> alter system checkpoint;

System altered.

SYS@orcl> alter database drop logfile group 1;

Database altered.

SYS@orcl> select a.group#, b.member, a.status
  2  from v$log a, v$logfile b
  3  where a.group#=b.group#
  4  order by a.group#;

 GROUP# MEMBER                                     STATUS
------- ------------------------------------------ ---------
      4 +DAT/orcl/onlinelog/group_4.267.680822441  CURRENT
      4 +FRA/orcl/onlinelog/group_4.258.680822445  CURRENT
      5 +DAT/orcl/onlinelog/group_5.268.680822463  INACTIVE
      5 +FRA/orcl/onlinelog/group_5.259.680822465  INACTIVE
      6 +FRA/orcl/onlinelog/group_6.260.680822473  INACTIVE
      6 +FRA/orcl/onlinelog/group_6.260.680822475  INACTIVE
     

15. Por el lado de la base de datos ya está todo concluido, la operatividad es normal y todos los archivos requeridos ya están residiendo en ASM, pero opcionalmente podemos mover los backups al disk group +FRA.

RMAN> run {
2> backup as copy archivelog all delete input;
3> backup backupset all delete input;
4> }

Starting backup at 04/02/2009 04:57:43
current log archived
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=115 device type=DISK
channel ORA_DISK_1: starting archived log copy
input archived log thread=1 sequence=2 RECID=1 STAMP=677907178
output file name=+FRA/orcl/archivelog/2009_02_04/thread_1_seq_2.275.677912267 RECID=5 STAMP=677912275
channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:16
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2009_02_04/o1_mf_1_2_4rlnomdm_.arc RECID=1 STAMP=677907178
channel ORA_DISK_1: starting archived log copy
input archived log thread=1 sequence=3 RECID=2 STAMP=677908766
output file name=+FRA/orcl/archivelog/2009_02_04/thread_1_seq_3.260.677912283 RECID=6 STAMP=677912287
channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:08
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2009_02_04/o1_mf_1_3_4rlp7bnl_.arc RECID=2 STAMP=677908766
channel ORA_DISK_1: starting archived log copy
input archived log thread=1 sequence=4 RECID=3 STAMP=677912036
output file name=+FRA/orcl/archivelog/2009_02_04/thread_1_seq_4.262.677912291 RECID=7 STAMP=677912291
channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:03
channel ORA_DISK_1: deleting archived log(s)
archived log file name=+FRA/orcl/archivelog/2009_02_04/thread_1_seq_4.257.677912033 RECID=3 STAMP=677912036
channel ORA_DISK_1: starting archived log copy
input archived log thread=1 sequence=5 RECID=4 STAMP=677912263
output file name=+FRA/orcl/archivelog/2009_02_04/thread_1_seq_5.257.677912295 RECID=8 STAMP=677912294
channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=+FRA/orcl/archivelog/2009_02_04/thread_1_seq_5.272.677912263 RECID=4 STAMP=677912263
Finished backup at 04/02/2009 04:58:15

Starting backup at 04/02/2009 04:58:19
using channel ORA_DISK_1
input backup set count=1 STAMP=677908586 creation_time=04/02/2009 03:56:26
channel ORA_DISK_1: starting piece 1 at 04/02/2009 04:58:20
channel ORA_DISK_1: backup piece /u01/app/oracle/flash_recovery_area/ORCL/backupset/2009_02_04/o1_mf_nnnd0_BACKUP_ORCL.LOCALD_0_4rlp1wqr_.bkp
piece handle=+FRA/orcl/backupset/2009_02_04/nnndf0_0.272.677912301 comment=NONE
channel ORA_DISK_1: finished piece 1 at 04/02/2009 04:59:05
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:45
deleted backup piece
backup piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2009_02_04/o1_mf_nnnd0_BACKUP_ORCL.LOCALD_0_4rlp1wqr_.bkp RECID=1 STAMP=677908588
input backup set count=2 STAMP=677908753 creation_time=04/02/2009 03:59:13
channel ORA_DISK_1: starting piece 1 at 04/02/2009 04:59:06
channel ORA_DISK_1: backup piece /u01/app/oracle/flash_recovery_area/ORCL/backupset/2009_02_04/o1_mf_ncsn0_BACKUP_ORCL.LOCALD_0_4rlp752m_.bkp
piece handle=+FRA/orcl/backupset/2009_02_04/ncsnf0_0.270.677912347 comment=NONE
channel ORA_DISK_1: finished piece 1 at 04/02/2009 04:59:09
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
deleted backup piece
backup piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2009_02_04/o1_mf_ncsn0_BACKUP_ORCL.LOCALD_0_4rlp752m_.bkp RECID=2 STAMP=677908757
input backup set count=3 STAMP=677908767 creation_time=04/02/2009 03:59:27
channel ORA_DISK_1: starting piece 1 at 04/02/2009 04:59:09
channel ORA_DISK_1: backup piece /u01/app/oracle/flash_recovery_area/ORCL/backupset/2009_02_04/o1_mf_annnn_BACKUP_ORCL.LOCALD_0_4rlp7hsk_.bkp
piece handle=+FRA/orcl/backupset/2009_02_04/annnf0_0.256.677912351 comment=NONE
channel ORA_DISK_1: finished piece 1 at 04/02/2009 04:59:17
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
deleted backup piece
backup piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2009_02_04/o1_mf_annnn_BACKUP_ORCL.LOCALD_0_4rlp7hsk_.bkp RECID=3 STAMP=677908767
input backup set count=10 STAMP=677909652 creation_time=04/02/2009 04:14:12
channel ORA_DISK_1: starting piece 1 at 04/02/2009 04:59:17
channel ORA_DISK_1: backup piece +DAT/orcl/backupset/2009_02_04/nnsnn0_migracion_asm_0.259.677909653
piece handle=+FRA/orcl/backupset/2009_02_04/nnnnf0_0.271.677912357 comment=NONE
channel ORA_DISK_1: finished piece 1 at 04/02/2009 04:59:18
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
deleted backup piece
backup piece handle=+DAT/orcl/backupset/2009_02_04/nnsnn0_migracion_asm_0.259.677909653 RECID=4 STAMP=677909652
Finished backup at 04/02/2009 04:59:19

16. Con los archivos de la base de datos, los archive logs y los backups residiendo en ASM, no hay problema en eliminar los archivos que aún quedan en los file systems.

[oracle@urania ~]$ rm -rf /u01/app/oracle/oradata/orcl
[oracle@urania ~]$ rm -rf /u01/app/oracle/flash_recovery_area/ORCL

¡Tarea concluída!, no fué tan dificil y como beneficio contamos ahora con una base de datos operando exclusivamente sobre ASM. Tengan en cuenta que no es necesario que todo esto se haga en el mismo momento, el backup tipo copia lo pueden obtener en el momento que deseen y mientras no pierdan los archive logs y/o sus backups, el resto de pasos lo pueden postergar para el momento más oportuno, con lo que la suspensión del servicio se reduce al tiempo que tome ejecutar el procedimiento de switch (paso 8) y recover (paso 9), que en la práctica puede representar unos pocos minutos. En un siguiente Post les mostraré lo fácil que resulta hacer esta migración usando Database Console y también cómo realizar un upgrade a ASM, hasta la próxima...

Post Relacionados:

¿Te pareció interesante este artículo?, ¿te quedaron algunas dudas?, ¿quieres sugerirme un tema a tratar?, pues déjame tus comentarios o envíame un email y para que NO te pierdas ningún Post, suscríbete por email ahora mismo!

4 comentarios, agrega el tuyo!

Anónimo dijo...

Hola Enrique, te felicito por tu membresía en la página de Oracle Latinoamérica, veo que compartimos los mismos intereses, aunque a mi me colocaron en otro lugar y la página, deja bastante que desear, ya que está hasta mal traducida...

Pero bueno, así es Oracle y felicitaciones por el Oracle ACE, ¿cómo lo conseguiste?

Enrique Orbegozo dijo...

Gracias Héctor y que bueno tenerte de visita. Pues lo del ACE me cayó de sorpresa hace un par de días, tengo entendido que alguien tiene que nominarte y luego Oracle te evalúa. Mayor detalle lo obtienes en esta página, bien podrías ser el próximo!

Unknown dijo...

Hola Enrique, Felicidades por tu premio. Me ha ayudado mucho tu pagina, y siempte estoy pendiente de tus actualizaciones. Precisamente me ayudo el procedimiento para pasar a ASM. Y tengo una duda sobre esto. estoy haciendo una prueba.

Servidor de produccion: RAC 3 nodos oracle10.2.0.4
Servidor de Prueba: RAC 2 nodos Oracle 10.2.0.4

Todo me fue bien hasta el momento de recuperar,


archive log thread 3 sequence 1 is already on disk as file /oracle/IAS/arch/arch_688574464_3_1.arc
unable to find archive log
archive log thread=3 sequence=11823
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 06/04/2009 13:34:13
RMAN-06054: media recovery requesting unknown log: thread 3 seq 11823 lowscn 7293786466303

Estoy buscando este archivelog en las vistas en produccion y no lo encuentro. Por favor me podrias guiar sobre esto?.

De antemano gracias por tu colaboracion

Enrique Orbegozo dijo...

Hola Yennis, se requiere mas información para poder saber qué pasó, los contenidos del alert.log y el detalle de los comandos ejecutados con sus respectivas salidas servirán para empezar.