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

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

Jun 07, 2016 pm 03:50 PM
asm oracle Example data database

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

Copy after login

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

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

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MySQL: An Introduction to the World's Most Popular Database MySQL: An Introduction to the World's Most Popular Database Apr 12, 2025 am 12:18 AM

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

What to do if the oracle can't be opened What to do if the oracle can't be opened Apr 11, 2025 pm 10:06 PM

Solutions to Oracle cannot be opened include: 1. Start the database service; 2. Start the listener; 3. Check port conflicts; 4. Set environment variables correctly; 5. Make sure the firewall or antivirus software does not block the connection; 6. Check whether the server is closed; 7. Use RMAN to recover corrupt files; 8. Check whether the TNS service name is correct; 9. Check network connection; 10. Reinstall Oracle software.

Why Use MySQL? Benefits and Advantages Why Use MySQL? Benefits and Advantages Apr 12, 2025 am 12:17 AM

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

How to solve the problem of closing oracle cursor How to solve the problem of closing oracle cursor Apr 11, 2025 pm 10:18 PM

The method to solve the Oracle cursor closure problem includes: explicitly closing the cursor using the CLOSE statement. Declare the cursor in the FOR UPDATE clause so that it automatically closes after the scope is ended. Declare the cursor in the USING clause so that it automatically closes when the associated PL/SQL variable is closed. Use exception handling to ensure that the cursor is closed in any exception situation. Use the connection pool to automatically close the cursor. Disable automatic submission and delay cursor closing.

How to create cursors in oracle loop How to create cursors in oracle loop Apr 12, 2025 am 06:18 AM

In Oracle, the FOR LOOP loop can create cursors dynamically. The steps are: 1. Define the cursor type; 2. Create the loop; 3. Create the cursor dynamically; 4. Execute the cursor; 5. Close the cursor. Example: A cursor can be created cycle-by-circuit to display the names and salaries of the top 10 employees.

How to stop oracle database How to stop oracle database Apr 12, 2025 am 06:12 AM

To stop an Oracle database, perform the following steps: 1. Connect to the database; 2. Shutdown immediately; 3. Shutdown abort completely.

What steps are required to configure CentOS in HDFS What steps are required to configure CentOS in HDFS Apr 14, 2025 pm 06:42 PM

Building a Hadoop Distributed File System (HDFS) on a CentOS system requires multiple steps. This article provides a brief configuration guide. 1. Prepare to install JDK in the early stage: Install JavaDevelopmentKit (JDK) on all nodes, and the version must be compatible with Hadoop. The installation package can be downloaded from the Oracle official website. Environment variable configuration: Edit /etc/profile file, set Java and Hadoop environment variables, so that the system can find the installation path of JDK and Hadoop. 2. Security configuration: SSH password-free login to generate SSH key: Use the ssh-keygen command on each node

How to create oracle dynamic sql How to create oracle dynamic sql Apr 12, 2025 am 06:06 AM

SQL statements can be created and executed based on runtime input by using Oracle's dynamic SQL. The steps include: preparing an empty string variable to store dynamically generated SQL statements. Use the EXECUTE IMMEDIATE or PREPARE statement to compile and execute dynamic SQL statements. Use bind variable to pass user input or other dynamic values ​​to dynamic SQL. Use EXECUTE IMMEDIATE or EXECUTE to execute dynamic SQL statements.

See all articles