数据库

位置:IT落伍者 >> 数据库 >> 浏览文章

利用RMAN将数据库从文件系统迁移到ASM


发布日期:2018年05月07日
 
利用RMAN将数据库从文件系统迁移到ASM

打开ASM实例

[oracle@ASM ~]$ echo $ORACLE_SID

+ASM

[oracle@ASM ~]$ sqlplus /nolog

SQL*Plus: Release Production on Mon Apr ::

Copyright (c) Oracle All rights reserved

SQL> conn / as sysdba

Connected to an idle instance

SQL> startup

ASM instance started

Total System Global Area bytes

Fixed Size bytes

Variable Size bytes

ASM Cache bytes

ASM diskgroups mounted

SQL> select namestate from v$asm_diskgroup;

NAME STATE

DATA MOUNTED

DGROUP MOUNTED

修改目标数据库(TOASM)的SPFILE

SQL> ALTER SYSTEM SET CONTROL_FILES=+DGROUP SCOPE=SPFILE;

System altered

SQL> ALTER SYSTEM SET DB_CREATE_FILE_DEST=+DGROUP SCOPE=SPFILE;

System altered

关闭目标数据库

SQL> SHUTDOWN IMMEDIATE

Database closed

Database dismounted

ORACLE instance shut down

通过RMAN连接到目标数据库并启动到NOMOUNT状态

[oracle@ASM admin]$ rman target /

Recovery Manager: Release Production on Mon Apr ::

Copyright (c) Oracle All rights reserved

connected to target database (not started)

RMAN> startup nomount

Oracle instance started

Total System Global Area bytes

Fixed Size bytes

Variable Size bytes

Database Buffers bytes

Redo Buffers bytes

RMAN>

还原控制文件到ASM磁盘组并将数据库启动到MOUNT状态

RMAN> RESTORE CONTROLFILE FROM /u/oradata/TOASM/controlctl;

Starting restore at APR

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_

channel ORA_DISK_: sid= devtype=DISK

channel ORA_DISK_: copied control file copy

output filename=+DGROUP/toasm/controlfile/backup

Finished restore at APR

RMAN> ALTER DATABASE MOUNT;

database mounted

released channel: ORA_DISK_

RMAN>

利用RMAN复制数据文件到ASM磁盘组

RMAN > BACKUP AS COPY DATABASE FORMAT +DGROUP;

Starting backup at APR

allocated channel: ORA_DISK_

channel ORA_DISK_: sid= devtype=DISK

channel ORA_DISK_: starting datafile copy

input datafile fno= name=/u/oradata/TOASM/systemdbf

output filename=+DGROUP/toasm/datafile/system tag=TAGT recid= stamp=

channel ORA_DISK_: datafile copy complete elapsed time: ::

channel ORA_DISK_: starting datafile copy

input datafile fno= name=/u/oradata/TOASM/sysauxdbf

output filename=+DGROUP/toasm/datafile/sysaux tag=TAGT recid= stamp=

channel ORA_DISK_: datafile copy complete elapsed time: ::

channel ORA_DISK_: starting datafile copy

input datafile fno= name=/u/oradata/TOASM/exampledbf

output filename=+DGROUP/toasm/datafile/example tag=TAGT recid= stamp=

channel ORA_DISK_: datafile copy complete elapsed time: ::

channel ORA_DISK_: starting datafile copy

input datafile fno= name=/u/oradata/TOASM/undotbsdbf

output filename=+DGROUP/toasm/datafile/undotbs tag=TAGT recid= stamp=

channel ORA_DISK_: datafile copy complete elapsed time: ::

channel ORA_DISK_: starting datafile copy

input datafile fno= name=/u/oradata/TOASM/usersdbf

output filename=+DGROUP/toasm/datafile/users tag=TAGT recid= stamp=

channel ORA_DISK_: datafile copy complete elapsed time: ::

channel ORA_DISK_: starting datafile copy

copying current control file

output filename=+DGROUP/toasm/controlfile/backup tag=TAGT recid= stamp=

channel ORA_DISK_: datafile copy complete elapsed time: ::

channel ORA_DISK_: starting full datafile backupset

channel ORA_DISK_: specifying datafile(s) in backupset

including current SPFILE in backupset

channel ORA_DISK_: starting piece at APR

channel ORA_DISK_: finished piece at APR

piece handle=+DGROUP/toasm/backupset/__/nnsnf_tagt_ tag=TAGT comment=NONE

channel ORA_DISK_: backup set complete elapsed time: ::

Finished backup at APR

RMAN>

利用RMAN的SWITCH 命令修改控制文件内数据文件的指针使其指向新位置

RMAN> SWITCH DATABASE TO COPY;

datafile switched to datafile copy +DGROUP/toasm/datafile/system

datafile switched to datafile copy +DGROUP/toasm/datafile/undotbs

datafile switched to datafile copy +DGROUP/toasm/datafile/sysaux

datafile switched to datafile copy +DGROUP/toasm/datafile/users

datafile switched to datafile copy +DGROUP/toasm/datafile/example

RMAN> RECOVER DATABASE;

Starting recover at APR

using channel ORA_DISK_

starting media recovery

media recovery complete elapsed time: ::

Finished recover at APR

RMAN>

打开数据库

RMAN> ALTER DATABASE OPEN;

database opened

RMAN>

迁移临时文件

由于临时文件不会被迁移所以我们只需要删除原来的增加新的就可以

SQL> SELECT NAME FROM V$TEMPFILE;

NAME

/u/oradata/TOASM/tempdbf

SQL> ALTER TABLESPACE TEMP ADD TEMPFILE +DGROUP;

Tablespace altered

SQL> ALTER TABLESPACE TEMP DROP TEMPFILE /u/oradata/TOASM/tempdbf;

Tablespace altered

SQL> SELECT NAME FROM V$TEMPFILE;

NAME

+DGROUP/toasm/tempfile/temp

SQL>

增加新的ONLINE REDOLOGS 到ASM

SQL> SELECT * FROM V$LOG;

GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM

YES INACTIVE APR

NO CURRENT APR

YES INACTIVE APR

SQL> ALTER DATABASE ADD LOGFILE +DGROUP SIZE M;

Database altered

SQL> ALTER DATABASE ADD LOGFILE +DGROUP SIZE M;

Database altered

SQL> ALTER DATABASE ADD LOGFILE +DGROUP SIZE M;

Database altered

SQL> ALTER DATABASE DROP LOGFILE GROUP ;

Database altered

SQL> ALTER SYSTEM SWITCH LOGFILE;

System altered

SQL> ALTER SYSTEM SWITCH LOGFILE;

System altered

SQL> SQL> ALTER DATABASE DROP LOGFILE GROUP ;

ALTER DATABASE DROP LOGFILE GROUP

*

ERROR at line :

ORA: log needed for crash recovery of instance TOASM (thread )

ORA: online log thread : /u/oradata/TOASM/redolog

SQL> ALTER SYSTEM CHECKPOINT;

System altered

SQL> ALTER DATABASE DROP LOGFILE GROUP ;

Database altered

SQL>ALTER DATABASE DROP LOGFILE GROUP ;

Database altered

SQL> SELECT MEMBER FROM V$LOGFILE;

MEMBER

+DGROUP/toasm/onlinelog/group_

+DGROUP/toasm/onlinelog/group_

+DGROUP/toasm/onlinelog/group_

SQL>

十一最后删除原来的数据库文件

[oracle@ASM ~]$ ls lh /u/oradata/TOASM/

total M

rwr oracle oinstall M Apr : controlctl

rwr oracle oinstall M Apr : controlctl

rwr oracle oinstall M Apr : controlctl

rwr oracle oinstall M Apr : exampledbf

rwr oracle oinstall M Apr : redolog

rwr oracle oinstall M Apr : redolog

rwr oracle oinstall M Apr : redolog

rwr oracle oinstall M Apr : sysauxdbf

rwr oracle oinstall M Apr : systemdbf

rwr oracle oinstall M Apr : undotbsdbf

rwr oracle oinstall M Apr : usersdbf

[oracle@ASM ~]$ rm rf /u/oradata/TOASM/*

[oracle@ASM ~]$ ls lh /u/oradata/TOASM/

total

[oracle@ASM ~]$

迁移完毕!

               

上一篇:ORACLE的数据字典用途实例

下一篇:Oracle回滚表空间丢失或损坏处理方法(2)