将文件系统数据库迁移到ASM中

使用裸设备配置ASM实例

http://www.cnblogs.com/myrunning/p/4270849.html

1.查看我们创建的磁盘组

[[email protected] ~]$ export ORACLE_SID=+ASM
[[email protected] ~]$ sqlplus ‘/as sysdba‘

SQL*Plus: Release 10.2.0.4.0 - Production on Mon Feb 2 13:37:25 2015

Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select name,total_mb,free_mb from v$asm_diskgroup;

NAME                             TOTAL_MB    FREE_MB
------------------------------ ---------- ----------
DATA                                 4094       4042
FLA                                  4094       4042

2.启动数据库实例查看数据文件等

SQL> select * from v$dbfile;   

     FILE# NAME
---------- --------------------------------------------------
         4 /u02/app/oradata/ZDJS/users01.dbf
         3 /u02/app/oradata/ZDJS/sysaux01.dbf
         2 /u02/app/oradata/ZDJS/undotbs01.dbf
         1 /u02/app/oradata/ZDJS/system01.dbf
         5 /u02/app/oradata/ZDJS/example01.dbf
         6 /u02/app/oradata/ZDJS/rlsc01.dbf

6 rows selected.

SQL> select file#,name from v$tempfile;

     FILE# NAME
---------- --------------------------------------------------
         1 /u02/app/oradata/ZDJS/temp01.dbf

SQL> show parameter control_

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
control_file_record_keep_time        integer     7
control_files                        string      /u02/app/oradata/ZDJS/control0
                                                 1.ctl, /u02/app/oradata/ZDJS/c
                                                 ontrol02.ctl, /u02/app/oradata
                                                 /ZDJS/control03.ctl
SQL> show parameter spfile

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
spfile                               string      /u02/app/product/10.2.0/db_1/d
                                                 bs/spfileZDJS.ora

SQL> select group#,member from v$logfile;

    GROUP# MEMBER
---------- --------------------------------------------------
         3 /u02/app/oradata/ZDJS/redo03.log
         2 /u02/app/oradata/ZDJS/redo02.log
         1 /u02/app/oradata/ZDJS/redo01.log   

3.对RDBMS做一个备份

[[email protected] ~]$ rman target /

Recovery Manager: Release 10.2.0.4.0 - Production on Mon Feb 2 13:54:00 2015

Copyright (c) 1982, 2007, Oracle.  All rights reserved.

connected to target database: ZDJS (DBID=3501190711)

RMAN> backup as copy database format ‘+DATA‘;

Starting backup at 02-FEB-15
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=144 devtype=DISK
channel ORA_DISK_1: starting datafile copy
input datafile fno=00001 name=/u02/app/oradata/ZDJS/system01.dbf
output filename=+DATA/zdjs/datafile/system.256.870616471 tag=TAG20150202T135428 recid=3 stamp=870616521
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:55
channel ORA_DISK_1: starting datafile copy
input datafile fno=00002 name=/u02/app/oradata/ZDJS/undotbs01.dbf
output filename=+DATA/zdjs/datafile/undotbs1.257.870616525 tag=TAG20150202T135428 recid=4 stamp=870616567
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:46
channel ORA_DISK_1: starting datafile copy
input datafile fno=00003 name=/u02/app/oradata/ZDJS/sysaux01.dbf
output filename=+DATA/zdjs/datafile/sysaux.258.870616569 tag=TAG20150202T135428 recid=5 stamp=870616596
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:35
channel ORA_DISK_1: starting datafile copy
input datafile fno=00005 name=/u02/app/oradata/ZDJS/example01.dbf
output filename=+DATA/zdjs/datafile/example.259.870616605 tag=TAG20150202T135428 recid=6 stamp=870616616
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile copy
input datafile fno=00006 name=/u02/app/oradata/ZDJS/rlsc01.dbf
output filename=+DATA/zdjs/datafile/rlsc.260.870616621 tag=TAG20150202T135428 recid=7 stamp=870616629
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile copy
input datafile fno=00004 name=/u02/app/oradata/ZDJS/users01.dbf
output filename=+DATA/zdjs/datafile/users.261.870616635 tag=TAG20150202T135428 recid=8 stamp=870616636
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting datafile copy
copying current control file
output filename=+DATA/zdjs/controlfile/backup.262.870616639 tag=TAG20150202T135428 recid=9 stamp=870616641
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
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 02-FEB-15
channel ORA_DISK_1: finished piece 1 at 02-FEB-15
piece handle=+DATA/zdjs/backupset/2015_02_02/nnsnf0_tag20150202t135428_0.263.870616647 tag=TAG20150202T135428 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 02-FEB-15

4.修改RDBMS参数

SQL> alter system set db_recovery_file_dest_size=3g scope=both;

System altered.

SQL> alter system set db_recovery_file_dest=‘+FLA‘ scope=both;

System altered.

SQL> alter system set db_create_file_dest=‘+DATA‘ scope=both;  

System altered.

SQL> alter system set db_create_online_log_dest_1=‘+DATA‘ scope=spfile;

System altered.

5.迁移联机日志到ASM磁盘

SQL> select a.group#,a.status,b.member from v$log a,v$logfile b
  2  where a.group#=b.group#;

    GROUP# STATUS           MEMBER
---------- ---------------- --------------------------------------------------
         3 INACTIVE         /u02/app/oradata/ZDJS/redo03.log
         2 INACTIVE         /u02/app/oradata/ZDJS/redo02.log
         1 CURRENT          /u02/app/oradata/ZDJS/redo01.log

SQL> alter database add logfile member ‘+DATA‘,‘+FLA‘ to group 1;

Database altered.

SQL> alter database add logfile member ‘+DATA‘,‘+FLA‘ to group 2;

Database altered.

SQL> alter database add logfile member ‘+DATA‘,‘+FLA‘ to group 3;

Database altered.

SQL> select a.group#,a.status,b.member from v$log a,v$logfile b
  2  where a.group#=b.group#;

    GROUP# STATUS           MEMBER
---------- ---------------- --------------------------------------------------
         3 INACTIVE         /u02/app/oradata/ZDJS/redo03.log
         2 INACTIVE         /u02/app/oradata/ZDJS/redo02.log
         1 CURRENT          /u02/app/oradata/ZDJS/redo01.log
         1 CURRENT          +DATA/zdjs/onlinelog/group_1.264.870617701
         1 CURRENT          +FLA/zdjs/onlinelog/group_1.256.870617713
         2 INACTIVE         +DATA/zdjs/onlinelog/group_2.265.870617759
         2 INACTIVE         +FLA/zdjs/onlinelog/group_2.257.870617769
         3 INACTIVE         +DATA/zdjs/onlinelog/group_3.266.870618057
         3 INACTIVE         +FLA/zdjs/onlinelog/group_3.258.870618067

9 rows selected.

删除原来的状态为INACTIVE的联机日志,通过alter system switch logfile;命令切换日志

SQL> alter database drop logfile member ‘/u02/app/oradata/ZDJS/redo01.log‘;

Database altered.

SQL> alter database drop logfile member ‘/u02/app/oradata/ZDJS/redo02.log‘;

Database altered.

SQL> alter database drop logfile member ‘/u02/app/oradata/ZDJS/redo03.log‘;

Database altered.

SQL> select a.group#,a.status,b.member from v$log a,v$logfile b
  2  where a.group#=b.group# order by group#;

    GROUP# STATUS           MEMBER
---------- ---------------- --------------------------------------------------
         1 CURRENT          +DATA/zdjs/onlinelog/group_1.264.870617701
         1 CURRENT          +FLA/zdjs/onlinelog/group_1.256.870617713
         2 INACTIVE         +DATA/zdjs/onlinelog/group_2.265.870617759
         2 INACTIVE         +FLA/zdjs/onlinelog/group_2.257.870617769
         3 INACTIVE         +DATA/zdjs/onlinelog/group_3.266.870618057
         3 INACTIVE         +FLA/zdjs/onlinelog/group_3.258.870618067

6 rows selected.

6.迁移临时表空间到ASM磁盘

SQL> select tablespace_name,file_name,bytes/1024/1024 size_m
  2  from dba_temp_files;

TABLESPACE_NAME      FILE_NAME                                    SIZE_M
-------------------- ---------------------------------------- ----------
TEMP                 /u02/app/oradata/ZDJS/temp01.dbf                 30

SQL> alter tablespace temp add tempfile size 100m;

Tablespace altered.

SQL> select tablespace_name,file_name,bytes/1024/1024 size_m
  2  from dba_temp_files;

TABLESPACE_NAME      FILE_NAME                                    SIZE_M
-------------------- ---------------------------------------- ----------
TEMP                 +DATA/zdjs/tempfile/temp.267.870619111          100
TEMP                 /u02/app/oradata/ZDJS/temp01.dbf                 30

SQL> alter database tempfile ‘/u02/app/oradata/ZDJS/temp01.dbf‘ drop ;

Database altered.

SQL> select tablespace_name,file_name,bytes/1024/1024 size_m
  2  from dba_temp_files;

TABLESPACE_NAME      FILE_NAME                                    SIZE_M
-------------------- ---------------------------------------- ----------
TEMP                 +DATA/zdjs/tempfile/temp.267.870619111          100

7.迁移控制文件、数据文件到ASM磁盘

在整个迁移过程中,只有这一步需要对数据库实例进行关闭、启动;这一步实际就是一个完全恢复的过程。

SQL> show parameter control 

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
control_file_record_keep_time        integer     7
control_files                        string      /u02/app/oradata/ZDJS/control0
                                                 1.ctl, /u02/app/oradata/ZDJS/c
                                                 ontrol02.ctl, /u02/app/oradata
                                                 /ZDJS/control03.ctl
SQL> alter system set control_files=‘+DATA/ZDJS/CONTROLFILE/control01.ctl‘,
  2  ‘+DATA/ZDJS/CONTROLFILE/control02.ctl‘,‘+DATA/ZDJS/CONTROLFILE/control03.ctl‘
  3  scope=spfile;

System altered.

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup nomount
ORACLE instance started.

Total System Global Area  608174080 bytes
Fixed Size                  1268896 bytes
Variable Size             197133152 bytes
Database Buffers          402653184 bytes
Redo Buffers                7118848 bytes

把数据库启动到nomount状态后使用rman进行恢复:

[[email protected] ~]$ rman target /

Recovery Manager: Release 10.2.0.4.0 - Production on Mon Feb 2 14:55:01 2015

Copyright (c) 1982, 2007, Oracle.  All rights reserved.

connected to target database: ZDJS (not mounted)

RMAN> restore controlfile from ‘/u02/app/oradata/ZDJS/control01.ctl‘;

Starting restore at 02-FEB-15
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=155 devtype=DISK

channel ORA_DISK_1: copied control file copy
output filename=+DATA/zdjs/controlfile/control01.ctl
output filename=+DATA/zdjs/controlfile/control02.ctl
output filename=+DATA/zdjs/controlfile/control03.ctl
Finished restore at 02-FEB-15

使用rman从最近的控制文件直接恢复控制文件,我们使用asmcmd工具确认一下恢复的控制文件是否存在:

ASMCMD> pwd
+DATA/ZDJS/CONTROLFILE
ASMCMD> ls
Backup.262.870616639
control01.ctl
control02.ctl
control03.ctl
current.268.870620187
current.269.870620189
current.270.870620189

mount数据库后使用rman switch数据库:

SQL> alter database mount;

Database altered.
[[email protected] ~]$ rman target /

Recovery Manager: Release 10.2.0.4.0 - Production on Mon Feb 2 15:00:57 2015

Copyright (c) 1982, 2007, Oracle.  All rights reserved.

connected to target database: ZDJS (DBID=3501190711, not open)

RMAN> list copy;

using target database control file instead of recovery catalog

List of Datafile Copies
Key     File S Completion Time Ckp SCN    Ckp Time        Name
------- ---- - --------------- ---------- --------------- ----
3       1    A 02-FEB-15       901700     02-FEB-15       +DATA/zdjs/datafile/system.256.870616471
4       2    A 02-FEB-15       901709     02-FEB-15       +DATA/zdjs/datafile/undotbs1.257.870616525
5       3    A 02-FEB-15       901720     02-FEB-15       +DATA/zdjs/datafile/sysaux.258.870616569
8       4    A 02-FEB-15       901739     02-FEB-15       +DATA/zdjs/datafile/users.261.870616635
6       5    A 02-FEB-15       901731     02-FEB-15       +DATA/zdjs/datafile/example.259.870616605
7       6    A 02-FEB-15       901735     02-FEB-15       +DATA/zdjs/datafile/rlsc.260.870616621

List of Control File Copies
Key     S Completion Time Ckp SCN    Ckp Time        Name
------- - --------------- ---------- --------------- ----
9       A 02-FEB-15       901740     02-FEB-15       +DATA/zdjs/controlfile/backup.262.870616639
2       A 02-FEB-15       901040     02-FEB-15       +DATA/zdjs/controlfile/backup.256.870616081

List of Archived Log Copies
Key     Thrd Seq     S Low Time  Name
------- ---- ------- - --------- ----
1       1    35      A 20-JAN-15 /u02/ZDJS_ARCH/1_35_869134589.dbf
2       1    36      A 02-FEB-15 /u02/ZDJS_ARCH/1_36_869134589.dbf
3       1    37      A 02-FEB-15 /u02/ZDJS_ARCH/1_37_869134589.dbf
4       1    38      A 02-FEB-15 /u02/ZDJS_ARCH/1_38_869134589.dbf
5       1    39      A 02-FEB-15 /u02/ZDJS_ARCH/1_39_869134589.dbf
6       1    40      A 02-FEB-15 /u02/ZDJS_ARCH/1_40_869134589.dbf
7       1    41      A 02-FEB-15 /u02/ZDJS_ARCH/1_41_869134589.dbf
8       1    42      A 02-FEB-15 /u02/ZDJS_ARCH/1_42_869134589.dbf
9       1    43      A 02-FEB-15 /u02/ZDJS_ARCH/1_43_869134589.dbf

RMAN> switch database to copy;

datafile 1 switched to datafile copy "+DATA/zdjs/datafile/system.256.870616471"
datafile 2 switched to datafile copy "+DATA/zdjs/datafile/undotbs1.257.870616525"
datafile 3 switched to datafile copy "+DATA/zdjs/datafile/sysaux.258.870616569"
datafile 4 switched to datafile copy "+DATA/zdjs/datafile/users.261.870616635"
datafile 5 switched to datafile copy "+DATA/zdjs/datafile/example.259.870616605"
datafile 6 switched to datafile copy "+DATA/zdjs/datafile/rlsc.260.870616621"

RMAN> recover database;  --切换后现在使用的是磁盘组里的备份文件,所有我们需要进行恢复

Starting recover at 02-FEB-15
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=151 devtype=DISK

starting media recovery

archive log thread 1 sequence 35 is already on disk as file /u02/ZDJS_ARCH/1_35_869134589.dbf
archive log thread 1 sequence 36 is already on disk as file /u02/ZDJS_ARCH/1_36_869134589.dbf
archive log thread 1 sequence 37 is already on disk as file /u02/ZDJS_ARCH/1_37_869134589.dbf
archive log thread 1 sequence 38 is already on disk as file /u02/ZDJS_ARCH/1_38_869134589.dbf
archive log thread 1 sequence 39 is already on disk as file /u02/ZDJS_ARCH/1_39_869134589.dbf
archive log thread 1 sequence 40 is already on disk as file /u02/ZDJS_ARCH/1_40_869134589.dbf
archive log thread 1 sequence 41 is already on disk as file /u02/ZDJS_ARCH/1_41_869134589.dbf
archive log thread 1 sequence 42 is already on disk as file /u02/ZDJS_ARCH/1_42_869134589.dbf
archive log thread 1 sequence 43 is already on disk as file /u02/ZDJS_ARCH/1_43_869134589.dbf
archive log filename=/u02/ZDJS_ARCH/1_35_869134589.dbf thread=1 sequence=35
archive log filename=/u02/ZDJS_ARCH/1_36_869134589.dbf thread=1 sequence=36
archive log filename=/u02/ZDJS_ARCH/1_37_869134589.dbf thread=1 sequence=37
archive log filename=/u02/ZDJS_ARCH/1_38_869134589.dbf thread=1 sequence=38
archive log filename=/u02/ZDJS_ARCH/1_39_869134589.dbf thread=1 sequence=39
archive log filename=/u02/ZDJS_ARCH/1_40_869134589.dbf thread=1 sequence=40
archive log filename=/u02/ZDJS_ARCH/1_41_869134589.dbf thread=1 sequence=41
media recovery complete, elapsed time: 00:00:06
Finished recover at 02-FEB-15

RMAN> alter database open;

database opened

8.验证迁移后的文件

SQL> select * from v$dbfile;

     FILE# NAME
---------- --------------------------------------------------
         4 +DATA/zdjs/datafile/users.261.870616635
         3 +DATA/zdjs/datafile/sysaux.258.870616569
         2 +DATA/zdjs/datafile/undotbs1.257.870616525
         1 +DATA/zdjs/datafile/system.256.870616471
         5 +DATA/zdjs/datafile/example.259.870616605
         6 +DATA/zdjs/datafile/rlsc.260.870616621

6 rows selected.

SQL> select file#,name from v$tempfile;

     FILE# NAME
---------- --------------------------------------------------
         2 +DATA/zdjs/tempfile/temp.267.870619111

SQL> show parameter control_

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
control_file_record_keep_time        integer     7
control_files                        string      +DATA/zdjs/controlfile/control
                                                 01.ctl, +DATA/zdjs/controlfile
                                                 /control02.ctl, +DATA/zdjs/con
                                                 trolfile/control03.ctl

SQL> select group#,member from v$logfile;

    GROUP# MEMBER
---------- --------------------------------------------------
         1 +DATA/zdjs/onlinelog/group_1.264.870617701
         1 +FLA/zdjs/onlinelog/group_1.256.870617713
         2 +DATA/zdjs/onlinelog/group_2.265.870617759
         2 +FLA/zdjs/onlinelog/group_2.257.870617769
         3 +DATA/zdjs/onlinelog/group_3.266.870618057
         3 +FLA/zdjs/onlinelog/group_3.258.870618067

6 rows selected.

#ASM和OS文件系统之间交换可以使用dbms_file_transfer包或rman的convert方法

时间: 2024-10-09 23:22:45

将文件系统数据库迁移到ASM中的相关文章

使用RMAN迁移文件系统数据库到ASM

--================================== -- 使用RMAN迁移文件系统数据库到ASM --================================== 在实际的工作过程中,由于ASM磁盘管理的便利性,因此很多时候需要将文件系统的数据库迁移到ASM,本文演示了如何将文件系统数据库迁移到ASM实例. 有关如何创建ASM实例及ASM磁盘管理请参考 创建ASM实例及数据库 ASM 磁盘组及磁盘的管理 使用 ASMCMD 工具管理ASM实例 一.主要步骤(假定AS

oracle表空间文件系统迁移到ASM

1.配置测试环境创建数据表空间create tablespace test logging datafile '/home/oracle/test.dbf' size 10m autoextend on next 10m maxsize 2048m extent management local;创建用户并指定表空间create user test identified by 123456 default tablespace test;给用户授予权限grant connect,resource

使用 Code First 数据库迁移

当 Entity Framework Code First 的数据模型发生改变时,默认会引发一个System.InvalidOperationException 的异常.解决方法是使用DropCreateDatabaseAlways 或DropCreateDatabaseIfModelChanges,让Entity Framework 自动将数据库删除,然后重新创建.不过,这种方式过于残暴,应该使用更人性化的方式,让Entity Framework 帮助我们自动调整数据库架构.并且仍然保留现有数

Code First 数据库迁移

当 Entity Framework Code First 的数据模型发生改变时,默认会引发一个System.InvalidOperationException 的异常.解决方法是使用DropCreateDatabaseAlways 或DropCreateDatabaseIfModelChanges,让Entity Framework 自动将数据库删除,然后重新创建.不过,这种方式过于残暴,应该使用更人性化的方式,让Entity Framework 帮助我们自动调整数据库架构.并且仍然保留现有数

flask-migrate数据库迁移

数据库迁移 在Flask中可以使用Flask-Migrate扩展,来实现数据迁移.并且集成到Flask-Script中,所有操作通过命令就能完成. 为了导出数据库迁移命令,Flask-Migrate提供了一个MigrateCommand类,可以附加到flask-script的manager对象上. 创建迁移仓库 python3 database.py db init 创建迁移脚本 自动创建迁移脚本有两个函数 upgrade():函数把迁移中的改动应用到数据库中. downgrade():函数则将

数据库迁移:文件系统迁至ASM

数据库迁移:文件系统迁至ASM 系统环境: 操作系统:AIX5.3-08 Oracle:  Oracle 10gR2 1.实施操作,选择可行性迁移方案: 2.前期:准备工作,创建ASM磁盘组.启动ASM实例等: 3.中期:完成参数文件.控制文件.数据文件的迁移等: 4.后期:完成临时表空间.日志文件迁移等. ***************************************************************************************** *前期目标

sql server 2005 数据库迁移问题总结——"错误15023:当前数据库中已存在用户或角色"

在数据库迁移过程中,如何设置不好用户与登录,会造成"错误15023:当前数据库中已存在用户或角色". 现在整理下思路: 1.在原数据库进行数据库备份 ***.bak 文件: 2.在新建数据库,建立与原数据库相同的登录名: 3.在新数据库上恢复备份的数据库文件 ***.bak 文件:选择覆盖原数据库文件: 4.将数据库恢复到其他服务器时,需要处理"孤立用户"的问题.具体解决办法如下: 用户和权限,但可能没有相应的登录或者登录所关联的用户可能不是相同的用户.这种情况被称

【Azure】ASM虚拟机迁移到ARM中

这两天开始讲之前在老门户(ASM)中的虚拟机往新门户(ARM)中进行迁移,阅读了很多博主的文章和微软云网站的介绍,在下使用微软云官网介绍的迁移工具进行迁移. 在开始迁移体验之前,了解一下整个迁移的流程,总共分四步: 验证:是在后台对进行迁移的资源执行数据分析,并在资源能够进行迁移时返回成功/失败 准备:是要模拟将 IaaS 资源从经典资源转换为 Resource Manager 资源的过程,并以并排方式让此转换过程直观可见. 检查:登录到门户并抽查属性和资源,来验证元数据的迁移是否正常. 提交/

2. Code First Migrations With Entity Framework【EF中 Code-First 方式的数据库迁移】

前面的文章中,学习了EF 中的几种关系,一对一,一对多,多对多.但是相信大家肯定会有疑问: 1.我难道每次都要创建数据库么? 2.我怎么样从已经存在的表中,添加字段和移除字段呢? 3.当我向表中,添加字段或者移除字段,我怎么来避免丢失数据呢? 4.当数据库发生改变的时候,我怎么获取到创建数据库的脚本呢? 不用着急,这篇文章,我会向大家一一讲到: 首先,说说我们为什么要使用数据库迁移技术吧,因为我们的实体总是变动地很频繁,在上篇文章中,我们使用了数据库初始化策略来做,也就是每次当数据库不存在的时候