oracle 11g R2 单实例 ASM 数据库数据磁盘组迁移

WBOY
풀어 주다: 2016-06-07 15:50:27
원래의
1094명이 탐색했습니다.

oracle 11g R2 单实例 ASM 数据库数据磁盘组迁移 在使用ASM作为数据库存储的时候,可能往往我们会因为某些原因,会考虑将数据的存储数据迁移到一个新的磁盘组。 例如:创建数据库的时候,数据存储在一个External redundancy 的磁盘组,没有冗余镜像。后期我

oracle 11g R2 单实例 ASM 数据库数据磁盘组迁移

     在使用ASM作为数据库存储的时候,可能往往我们会因为某些原因,会考虑将数据的存储数据迁移到一个新的磁盘组。

例如:创建数据库的时候,数据存储在一个External redundancy 的磁盘组,没有冗余镜像。后期我们会考虑将数据库数据迁移到一个Normal redundancy 或者 High redundancy的磁盘组。

测试环境:

主机环境

SQL> host lsb_release -a
LSB Version:    :core-4.0-amd64:core-4.0-ia32:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-ia32:printing-4.0-noarch
Distributor ID: EnterpriseEnterpriseServer
Description:    Enterprise Linux Enterprise Linux Server release 5.7 (Carthage)
Release:        5.7
Codename:       Carthage

数据库版本:

SQL> select instance_name,version from v$instance;

INSTANCE_NAME    VERSION
---------------- -----------------
ORCL             11.2.0.3.0
##单实例


ASM版本

SQL> select instance_name,version from v$instance;

INSTANCE_NAME    VERSION
---------------- -----------------
+ASM             11.2.0.3.0


ASM磁盘组共三个

SQL> select name from v$asm_diskgroup;

NAME
------------------------------
BACKUP
SYSTEMDG
DATA

目前数据数据存储于 SYSTEMDG ,包括(数据文件,临时文件,undo文件,redo文件、控制文件、参数文件) 本测试将数据迁移至DATA磁盘组,BACKUP磁盘组为备份dest。环境交代完毕!

需要迁移的文件:数据文件,临时文件,undo文件,redo文件、控制文件、参数文件

迁移前,先记下数据库的DBID


开始迁移


#首先,consistent 关闭数据库

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

#将数据库启动至mount状态
SQL> startup mount;
ORACLE instance started.

Total System Global Area  542814208 bytes
Fixed Size                  2230152 bytes
Variable Size             180357240 bytes
Database Buffers          352321536 bytes
Redo Buffers                7905280 bytes
Database mounted.


#启动rman工具,将数据库镜像备份至DATA磁盘组
RMAN> backup as copy database format '+DATA';

Starting backup at 28-OCT-13
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=137 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=16 device type=DISK
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001 name=+SYSTEMDG/orcl/datafile/system.261.829928875
channel ORA_DISK_2: starting datafile copy
input datafile file number=00002 name=+SYSTEMDG/orcl/datafile/sysaux.262.829928875
output file name=+DATA/orcl/datafile/system.257.830041439 tag=TAG20131028T230354 RECID=23 STAMP=830041580
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:02:25
channel ORA_DISK_1: starting datafile copy
input datafile file number=00003 name=+SYSTEMDG/orcl/datafile/undotbs1.263.829929061
output file name=+DATA/orcl/datafile/sysaux.256.830041437 tag=TAG20131028T230354 RECID=22 STAMP=830041580
channel ORA_DISK_2: datafile copy complete, elapsed time: 00:02:26
channel ORA_DISK_2: starting datafile copy
input datafile file number=00005 name=+SYSTEMDG/orcl/datafile/users01.264.829929061
output file name=+DATA/orcl/datafile/undotbs1.258.830041581 tag=TAG20131028T230354 RECID=25 STAMP=830041611
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:35
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=+SYSTEMDG/orcl/datafile/users.265.829929107
output file name=+DATA/orcl/datafile/users01.259.830041581 tag=TAG20131028T230354 RECID=24 STAMP=830041611
channel ORA_DISK_2: datafile copy complete, elapsed time: 00:00:35
output file name=+DATA/orcl/datafile/users.260.830041617 tag=TAG20131028T230354 RECID=26 STAMP=830041617
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 28-OCT-13

Starting Control File and SPFILE Autobackup at 28-OCT-13
piece handle=+BACKUP/orcl/autobackup/2013_10_28/s_830041354.262.830041621 comment=NONE
Finished Control File and SPFILE Autobackup at 28-OCT-13

#完成copy

#查看当前控制文件value,并修改为希望的值

SQL> show parameter control_files

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
control_files                        string      +SYSTEMDG/orcl/control01.ctl,
                                                 +BACKUP/orcl/controlfile/curre
                                                 nt.256.829519259
                                                 
SQL> alter system set control_files='+DATA','+BACKUP/orcl/controlfile/current.256.829519259' scope=spfile;

System altered.


#关闭数据库,让修改的control_files参数生效
SQL> shutdown immediate;
ORA-01109: database not open

Database dismounted.
ORACLE instance shut down.         

#将数据库启动至nomount阶段

SQL> startup nomount;
ORACLE instance started.

Total System Global Area  542814208 bytes
Fixed Size                  2230152 bytes
Variable Size             180357240 bytes
Database Buffers          352321536 bytes
Redo Buffers                7905280 bytes

#打开RMAN工具,通过设置dbid的方式,恢复控制文件,此时,数据库会根据control_files设置的值,将控制文件恢复到指定的位置。

[oracle@linusfay-up ~]$ rman target /

Recovery Manager: Release 11.2.0.3.0 - Production on Mon Oct 28 23:56:54 2013

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORCL (not mounted)

RMAN> set dbid=1357299984

executing command: SET DBID


#从自动备份中恢复控制文件
RMAN> restore controlfile from autobackup;

Starting restore at 28-OCT-13
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=136 device type=DISK

recovery area destination: +BACKUP
database name (or database unique name) used for search: ORCL
channel ORA_DISK_1: AUTOBACKUP +backup/ORCL/AUTOBACKUP/2013_10_28/s_830041354.262.830041621 found in the recovery area
channel ORA_DISK_1: looking for AUTOBACKUP on day: 20131028
channel ORA_DISK_1: restoring control file from AUTOBACKUP +backup/ORCL/AUTOBACKUP/2013_10_28/s_830041354.262.830041621
channel ORA_DISK_1: control file restore from AUTOBACKUP complete
output file name=+DATA/orcl/controlfile/current.261.830042181
output file name=+BACKUP/orcl/controlfile/current.256.829519259
Finished restore at 28-OCT-13

#控制文件恢复成功,将数据库启动至mount阶段
RMAN> alter database mount;

#查看之前备份的数据库镜像
RMAN> list copy of database;

List of Datafile Copies
=======================

Key     File S Completion Time Ckp SCN    Ckp Time       
------- ---- - --------------- ---------- ---------------
23      1    A 28-OCT-13       1087234    28-OCT-13      
        Name: +DATA/orcl/datafile/system.257.830041439
        Tag: TAG20131028T230354

22      2    A 28-OCT-13       1087234    28-OCT-13      
        Name: +DATA/orcl/datafile/sysaux.256.830041437
        Tag: TAG20131028T230354

25      3    A 28-OCT-13       1087234    28-OCT-13      
        Name: +DATA/orcl/datafile/undotbs1.258.830041581
        Tag: TAG20131028T230354

26      4    A 28-OCT-13       1087234    28-OCT-13      
        Name: +DATA/orcl/datafile/users.260.830041617
        Tag: TAG20131028T230354

24      5    A 28-OCT-13       1087234    28-OCT-13      
        Name: +DATA/orcl/datafile/users01.259.830041581
        Tag: TAG20131028T230354
database mounted
released channel: ORA_DISK_1             


#将数据库switch至database copy
RMAN> switch database to copy;

Starting implicit crosscheck backup at 28-OCT-13
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=136 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=16 device type=DISK
Crosschecked 5 objects
Finished implicit crosscheck backup at 28-OCT-13

Starting implicit crosscheck copy at 28-OCT-13
using channel ORA_DISK_1
using channel ORA_DISK_2
Crosschecked 5 objects
Finished implicit crosscheck copy at 28-OCT-13

searching for all files in the recovery area
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: +backup/ORCL/AUTOBACKUP/2013_10_28/s_830041354.262.830041621
File Name: +backup/ORCL/AUTOBACKUP/2013_10_27/s_829931410.271.829931413
File Name: +backup/ORCL/AUTOBACKUP/2013_10_27/s_829920770.278.829920963
File Name: +backup/ORCL/AUTOBACKUP/2013_10_27/s_829920770.276.829921283

datafile 1 switched to datafile copy "+DATA/orcl/datafile/system.257.830041439"
datafile 2 switched to datafile copy "+DATA/orcl/datafile/sysaux.256.830041437"
datafile 3 switched to datafile copy "+DATA/orcl/datafile/undotbs1.258.830041581"
datafile 4 switched to datafile copy "+DATA/orcl/datafile/users.260.830041617"
datafile 5 switched to datafile copy "+DATA/orcl/datafile/users01.259.830041581"    


#ok,完成数据文件的switch

#恢复数据库

RMAN> recover database;

#完成恢复,以resetlogs方式打开数据库。

RMAN> alter database open resetlogs;

database opened

SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
+DATA/orcl/datafile/system.257.830041439
+DATA/orcl/datafile/sysaux.256.830041437
+DATA/orcl/datafile/undotbs1.258.830041581
+DATA/orcl/datafile/users.260.830041617
+DATA/orcl/datafile/users01.259.830041581

#数据库打开成功,接下里就是迁移 tempfile,redo lofile,修改 数据库db_create_file_dest=+DATA

SQL> create temporary tablespace temp tempfile '+DATA';

Tablespace created.


SQL> select file_name from dba_temp_files;

FILE_NAME
--------------------------------------------------------------------------------
+SYSTEMDG/orcl/tempfile/temp1.267.830034603
+DATA/orcl/tempfile/temp.262.830042531

#修改默认临时表空间,并删除废弃的临时表空间以及数据文件
SQL> alter database default temporary tablespace temp;

Database altered.

SQL> drop tablespace temp1 including contents and datafiles;

Tablespace dropped.


SQL> show parameter control_files

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
control_files                        string      +DATA/orcl/controlfile/current
                                                 .261.830042181, +BACKUP/orcl/c
                                                 ontrolfile/current.256.8295192
                                                 59

#修改db_create_file_dest
SQL> show parameter db_create_file_dest

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_create_file_dest                  string      +SYSTEMDG


SQL> alter system set db_create_file_dest='+DATA' scope=spfile;

System altered.                         

#重启数据库,让参数生效
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORA-32004: obsolete or deprecated parameter(s) specified for RDBMS instance
ORACLE instance started.

Total System Global Area  542814208 bytes
Fixed Size                  2230152 bytes
Variable Size             180357240 bytes
Database Buffers          352321536 bytes
Redo Buffers                7905280 bytes
Database mounted.
Database opened.                

#最后 迁移redo logfile  采用 新加成员 删除废弃成员的方式来迁移
SQL> select member from v$logfile;

MEMBER
--------------------------------------------------------------------------------
+BACKUP/orcl/onlinelog/group_1.257.829519279
+SYSTEMDG/orcl/onlinelog/group_1.268.830035813
+BACKUP/orcl/onlinelog/group_2.258.829519305
+SYSTEMDG/orcl/onlinelog/group_2.269.830035825
+BACKUP/orcl/onlinelog/group_3.259.829519331
+SYSTEMDG/orcl/onlinelog/group_3.270.830035835

6 rows selected.       


SQL> alter database add logfile member '+DATA' to group 1;

Database altered.

SQL> alter database add logfile member '+DATA' to group 2;

Database altered.

SQL> alter database add logfile member '+DATA' to group 3;

Database altered.


SQL> alter system switch logfile;

System altered.

SQL> alter system checkpoint;

System altered.

SQL> alter database drop  logfile member '+SYSTEMDG/orcl/onlinelog/group_1.268.830035813';

Database altered.

#迁移参数文件
SQL> create pfile='$ORACLE_HOME/dbs/init_orcl.ora' from spfile;

File created.

SQL> shutdown  immediate;
ASM diskgroups dismounted
ASM instance shutdown
SQL> startup pfile='$ORACLE_HOME/dbs/init_orcl.ora';
ASM instance started

Total System Global Area  283930624 bytes
Fixed Size                  2227664 bytes
Variable Size             256537136 bytes
ASM Cache                  25165824 bytes
ASM diskgroups mounted

SQL> create spfile ='+DATA' from pfile='$ORACLE_HOME/dbs/init_orcl.ora';

File created.

SQL> show parameter pfile

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
spfile                               string      +DATA/asm/asmparameterfile/reg
                                                 istry.253.830084811

로그인 후 복사

#迁移redo logfile的时候,删除的时候,可能会因为是current  或者active状态无法删除,此时可根据实际情况
#使用 alter system switch logfile  或者 alter system checkpoint 来改变日志组的状态来达到删除的目的。

#至此,数据库存储从SYSTEMDG DISKGROUP 迁移到 DATA磁盘组完成

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿