将数据库从普通文件系统迁移到ASM中
数据库存储的是普通的文件系统,现在将数据库迁移到ASM存储中。
准备ASM环境:
[oracle@kel ~]$ asmcmd ASMCMD> ls ASM/ KEL/ ASMCMD>
在本实例中,将数据库文件都存储在KEL磁盘组中。
对数据库做一个全备份,利用备份来恢复数据文件,从而达到转移存储的目的:
RMAN> run 2> { 3> backup as copy database format '+KEL'; 4> }
修改数据库相关参数:
SQL> show parameter db_recovery_file NAME TYPE VALUE ------------------------------------ ---------------------- ------------------------------ db_recovery_file_dest string /home/oracle/flash_recovery_ar ea db_recovery_file_dest_size big integer 2G
db_recovery_file_dest参数表示default database recovery file location
DB_RECOVERY_FILE_DEST_SIZE specifies (in bytes) the hard limit on the total space to be used by target database recovery files created in the flash recovery area
修改参数如下:(闪回区创建在磁盘组中)
SQL> alter system set db_recovery_file_dest_size=3g scope=both; System altered. SQL> alter system set db_recovery_file_dest='+KEL' scope=both; System altered.
联机日志和自动创建数据文件文件位置的参数如下:
SQL> show parameter db_create_ NAME TYPE VALUE ------------------------------------ ---------------------- ------------------------------ db_create_file_dest string db_create_online_log_dest_1 string db_create_online_log_dest_2 string db_create_online_log_dest_3 string db_create_online_log_dest_4 string db_create_online_log_dest_5 string
DB_CREATE_ONLINE_LOG_DEST_n (where n = 1, 2, 3, ... 5) specifies the default location for Oracle-managed control files and online redo logs. If more than one DB_CREATE_ONLINE_LOG_DEST_n parameter is specified, then the control file or online redo log is multiplexed across the locations of the other DB_CREATE_ONLINE_LOG_DEST_n parameters. One member of each online redo log is created in each location, and one control file is created in each location.
DB_CREATE_FILE_DEST initializationparameter in your initialization parameter file to identify the defaultlocation for the database server to create:
Datafiles
Tempfiles
Redo log files
Control files
Block change tracking files
修改参数如下:(将联机日志和自动创建数据文件位置指定为磁盘组,并且是多路复用)
SQL> alter system set db_create_file_dest='+KEL' scope=both; System altered. SQL> alter system set db_create_online_log_dest_1='+KEL' scope=both; System altered. SQL> alter system set db_create_online_log_dest_2='+ASM' scope=both; System altered.
查看目前联机日志和standby日志位置:
SQL> select group#,member from v$logfile; GROUP# MEMBER ---------- ---------------------------------------- 3 /home/oracle/oradata/ipap/redo03.log 2 /home/oracle/oradata/ipap/redo02.log 1 /home/oracle/oradata/ipap/redo01.log
通过给每个日志组添加一个成员在磁盘组中,然后删除老的日志,从而达到替换的目的:
添加日志组:
SQL> alter database add logfile member '+ASM','+KEL' to group 1; Database altered. SQL> alter database add logfile member '+ASM','+KEL' to group 2; Database altered.
SQL> alter database add logfile member '+ASM','+KEL' to group 3; Database altered.删除原来的联机日志组:
SQL> alter system switch logfile; System altered. SQL> alter database drop logfile member '/home/oracle/oradata/ipap/redo01.log'; Database altered. SQL> alter system switch logfile; System altered. SQL> alter database drop logfile member '/home/oracle/oradata/ipap/redo02.log'; Database altered. SQL> alter system switch logfile; System altered. SQL> alter database drop logfile member '/home/oracle/oradata/ipap/redo03.log'; Database altered.
在删除的时候,必须要等待状态为inactive才能进行删除,可以通过以下来进行查询:
SQL> select group#,status from v$log; GROUP# STATUS ---------- -------------------------------- 1 CURRENT 2 ACTIVE 3 ACTIVE
如果存在standby日志,那么只要通过删除原来的,进行重建即可:
SQL> alter database drop standby logfile group 4; Database altered. SQL> alter database add standby logfile group 4 size 50m; Database altered.
检查联机日志,确认全部迁移到ASM中:(存在多路复用)
SQL> select group#,member from v$logfile order by 1; GROUP# MEMBER ------ ------------------------------------------------ 1 +KEL/ipap/onlinelog/group_1.260.850694639 1 +ASM/ipap/onlinelog/group_1.265.850694631 2 +ASM/ipap/onlinelog/group_2.261.850694671 2 +KEL/ipap/onlinelog/group_2.262.850694685 3 +ASM/ipap/onlinelog/group_3.259.850694709 3 +KEL/ipap/onlinelog/group_3.264.850694717 4 +ASM/ipap/onlinelog/group_4.257.850695777 4 +KEL/ipap/onlinelog/group_4.275.850695773 8 rows selected.
查看当前临时表空间的配置:
SQL> select ts#,name from v$tempfile; TS# NAME ---------- --------------------------------------------- 3 /home/oracle/oradata/ipap/temp01.dbf
SQL> select ts#,name from v$tablespace where ts#=3; TS# NAME ---------- --------------------------------------------- 3 TEMP
给临时表空间添加文件,存储在ASM中:(注意临时表空间的大小)
SQL> alter tablespace temp add tempfile size 300m; Tablespace altered.
查看增加的数据文件,是否存在ASM中:
SQL> select name from v$tempfile; NAME --------------------------------------------- +KEL/ipap/tempfile/temp.277.850696379 /home/oracle/oradata/ipap/temp01.dbf删除旧的临时表空间文件:
SQL> alter database tempfile '/home/oracle/oradata/ipap/temp01.dbf' drop ; Database altered.再次确认临时表空间:
SQL> select name from v$tempfile; NAME --------------------------------------------- +KEL/ipap/tempfile/temp.277.850696379
把数据文件、控制文件迁移到ASM,在整个过程中,在这一步需要对数据库进行重启
查看当前控制文件位置:
SQL> show parameter control_files NAME TYPE VALUE ------------------------------------ ---------------------- ------------------------------ control_files string /home/oracle/oradata/ipap/cont rol01.ctl, /home/oracle/oradat a/ipap/control02.ctl, /home/or acle/oradata/ipap/control03.ct l
SQL> alter system set control_files='+KEL/ipap/controlfile/control01.ctl','+KEL/ipap/controlfile/control02.ctl','+KEL/ipap/controlfile/control03.ctl' scope=spfile; System altered.
关闭数据库:
SQL> shutdown immediate Database closed. Database dismounted. ORACLE instance shut down.
将数据库启动到nomount阶段:
SQL> startup nomount;
在RMAN中进行完全恢复:
首先恢复控制文件:
RMAN> restore controlfile from autobackup; Starting restore at 20-JUN-14 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: sid=151 devtype=DISK recovery area destination: +KEL database name (or database unique name) used for search: IPAP channel ORA_DISK_1: autobackup found in the recovery area channel ORA_DISK_1: autobackup found: +kel/IPAP/AUTOBACKUP/2014_06_20/s_850696380.278.850696381 channel ORA_DISK_1: control file restore from autobackup complete output filename=+KEL/ipap/controlfile/control01.ctl output filename=+KEL/ipap/controlfile/control02.ctl output filename=+KEL/ipap/controlfile/control03.ctl Finished restore at 20-JUN-14
将数据库进行挂载:
RMAN> alter database mount; database mounted released channel: ORA_DISK_1
切换数据文件:
RMAN> switch database to copy; Starting implicit crosscheck backup at 20-JUN-14 allocated channel: ORA_DISK_1 channel ORA_DISK_1: sid=151 devtype=DISK Crosschecked 10 objects Finished implicit crosscheck backup at 20-JUN-14 Starting implicit crosscheck copy at 20-JUN-14 using channel ORA_DISK_1 Crosschecked 4 objects Finished implicit crosscheck copy at 20-JUN-14 searching for all files in the recovery area cataloging files... cataloging done List of Cataloged Files ======================= File Name: +kel/IPAP/AUTOBACKUP/2014_06_20/s_850696380.278.850696381 datafile 1 switched to datafile copy "+KEL/ipap/datafile/system.259.850692939" datafile 2 switched to datafile copy "+KEL/ipap/datafile/undotbs1.257.850693039" datafile 3 switched to datafile copy "+KEL/ipap/datafile/sysaux.258.850693003" datafile 4 switched to datafile copy "+KEL/ipap/datafile/users.256.850693045"
恢复数据库:
RMAN> recover database; Starting recover at 20-JUN-14 using channel ORA_DISK_1 starting media recovery archive log thread 1 sequence 8 is already on disk as file +KEL/ipap/archivelog/2014_06_20/thread_1_seq_8.266.850695305 archive log thread 1 sequence 9 is already on disk as file +KEL/ipap/archivelog/2014_06_20/thread_1_seq_9.267.850695485 archive log thread 1 sequence 10 is already on disk as file +KEL/ipap/archivelog/2014_06_20/thread_1_seq_10.268.850695485 archive log thread 1 sequence 11 is already on disk as file +KEL/ipap/archivelog/2014_06_20/thread_1_seq_11.269.850695489 archive log thread 1 sequence 12 is already on disk as file +KEL/ipap/archivelog/2014_06_20/thread_1_seq_12.271.850695533 archive log thread 1 sequence 13 is already on disk as file +KEL/ipap/archivelog/2014_06_20/thread_1_seq_13.273.850695551 archive log thread 1 sequence 14 is already on disk as file +ASM/ipap/onlinelog/group_1.265.850694631 archive log filename=+KEL/ipap/archivelog/2014_06_20/thread_1_seq_8.266.850695305 thread=1 sequence=8 archive log filename=+KEL/ipap/archivelog/2014_06_20/thread_1_seq_9.267.850695485 thread=1 sequence=9 archive log filename=+KEL/ipap/archivelog/2014_06_20/thread_1_seq_10.268.850695485 thread=1 sequence=10 archive log filename=+KEL/ipap/archivelog/2014_06_20/thread_1_seq_11.269.850695489 thread=1 sequence=11 archive log filename=+KEL/ipap/archivelog/2014_06_20/thread_1_seq_12.271.850695533 thread=1 sequence=12 archive log filename=+KEL/ipap/archivelog/2014_06_20/thread_1_seq_13.273.850695551 thread=1 sequence=13 archive log filename=+ASM/ipap/onlinelog/group_1.265.850694631 thread=1 sequence=14 media recovery complete, elapsed time: 00:00:04 Finished recover at 20-JUN-14
打开数据库:
RMAN> alter database open resetlogs; database opened
确认所有文件已经迁移到ASM中:
控制文件:
SQL> select name from v$controlfile; NAME -------------------------------------------------------------------------------- +KEL/ipap/controlfile/control01.ctl +KEL/ipap/controlfile/control02.ctl +KEL/ipap/controlfile/control03.ctl
数据文件:
SQL> select name,status from v$datafile; NAME STATUS -------------------------------------------------- -------------- +KEL/ipap/datafile/system.259.850692939 SYSTEM +KEL/ipap/datafile/undotbs1.257.850693039 ONLINE +KEL/ipap/datafile/sysaux.258.850693003 ONLINE +KEL/ipap/datafile/users.256.850693045 ONLINE
联机日志:
SQL> select member from v$logfile; MEMBER -------------------------------------------------------------------------------- +KEL/ipap/onlinelog/group_4.275.850695773 +ASM/ipap/onlinelog/group_4.257.850695777 +ASM/ipap/onlinelog/group_1.265.850694631 +KEL/ipap/onlinelog/group_1.260.850694639 +ASM/ipap/onlinelog/group_2.261.850694671 +KEL/ipap/onlinelog/group_2.262.850694685 +ASM/ipap/onlinelog/group_3.259.850694709 +KEL/ipap/onlinelog/group_3.264.850694717 8 rows selected.
临时表空间:
SQL> select name,status from v$tempfile; NAME STATUS -------------------------------------------------- -------------- +KEL/ipap/tempfile/temp.277.850696379 ONLINE
for linux and python