oracle數據庫存儲遷移參考

基本環境

os版本:centos5.5
db版本:oracle10.2.0.1

  1. export PS1="`/bin/hostname -s`-> "
  2. export EDITOR=vi
  3. export ORACLE_SID=orcl
  4. export ORACLE_BASE=/database
  5. export ORACLE_HOME=$ORACLE_BASE/oracle
  6. export LD_LIBRARY_PATH=$ORACLE_HOME/lib
  7. export PATH=$ORACLE_HOME/bin:$PATH
  8. umask 022

測試信息

  1. create tablespace wql datafile '/database/oradata/orcl/wql.dbf' size 100M;
  2. create user wql identified by oracle default tablespace wql;
  3. grant connect,resource to wql;
  4. conn wql/oracle
  5. create table t(id int,name varchar(15));
  6. insert into t values(1,'wql');
  7. select * from t;
  8. ID NAME
  9. ---------- ---------------
  10. 1 wql

替換規劃

原有的:
數據文件:/dev/sda /database/oradata
歸檔:/dev/sda /arch

新存儲:
/dev/sdb1、/dev/sdc1、/dev/sdd1對應asm的+DG1
存放數據文件

/dev/sde1 對應asm的+DG2 存放歸檔日誌
/dev/sdf1 對應asm的+DG3 閃回區域

實施過程

安裝配置asmlib

安裝

  1. [root@db2awse ~]# rpm -qa|grep oracle
  2. oracleasm-2.6.18-398.el5-2.0.5-1.el5
  3. oracleasmlib-2.0.4-1.el5
  4. oracleasm-support-2.1.8-1.el5

配置

  1. [root@db2awse ~]# /etc/init.d/oracleasm configure
  2. Configuring the Oracle ASM library driver.
  3. Default user to own the driver interface []: oracle
  4. Default group to own the driver interface []: dba
  5. Start Oracle ASM library driver on boot (y/n) [n]: y
  6. Scan for Oracle ASM disks on boot (y/n) [y]: y
  7. Writing Oracle ASM library driver configuration: done
  8. Initializing the Oracle ASMLib driver: [ OK ]
  9. Scanning the system for Oracle ASMLib disks: [ OK ]

使用fdisk /dev/sdx配置磁盤,過程略

創建asmdisk

  1. [root@db2awse ~]# /etc/init.d/oracleasm createdisk VOL1 /dev/sdb1
  2. Marking disk "VOL1" as an ASM disk: [ OK ]
  3. [root@db2awse ~]# /etc/init.d/oracleasm createdisk VOL2 /dev/sdc1
  4. Marking disk "VOL2" as an ASM disk: [ OK ]
  5. [root@db2awse ~]# /etc/init.d/oracleasm createdisk VOL3 /dev/sdd1
  6. Marking disk "VOL3" as an ASM disk: [ OK ]
  7. [root@db2awse ~]# /etc/init.d/oracleasm createdisk VOL4 /dev/sde1
  8. Marking disk "VOL4" as an ASM disk: [ OK ]
  9. [root@db2awse ~]# /etc/init.d/oracleasm createdisk VOL5 /dev/sdf1
  10. Marking disk "VOL5" as an ASM disk: [ OK ]
  11. [root@db2awse ~]# /etc/init.d/oracleasm listdisks
  12. VOL1
  13. VOL2
  14. VOL3
  15. VOL4
  16. VOL5

配置asm實例

啓動css,以root執行

  1. [root@db2awse ~]# whoami
  2. root
  3. [root@db2awse ~]# /database/oracle/bin/localconfig add
  4. /etc/oracle does not exist. Creating it now.
  5. Successfully accumulated necessary OCR keys.
  6. Creating OCR keys for user 'root', privgrp 'root'..
  7. Operation successful.
  8. Configuration for local CSS has been initialized
  9. Adding to inittab
  10. Startup will be queued to init within 90 seconds.
  11. Checking the status of new Oracle init process...
  12. Expecting the CRS daemons to be up within 600 seconds.
  13. CSS is active on these nodes.
  14. db2awse
  15. CSS is active on all nodes.
  16. Oracle CSS service is installed and running under init(1M)

創建ASM實例的pfile文件,內容如下:

  1. $ cat $ORACLE_HOME/dbs/init+ASM.ora
  2. instance_type=asm
  3. large_pool_size=12M
  4. remote_login_passwordfile=exclusive
  5. asm_diskstring='/dev/oracleasm/disks/VOL*'
  6. background_dump_dest=/database/admin/+ASM/bdump
  7. core_dump_dest=/database/admin/+ASM/cdump
  8. user_dump_dest=/database/admin/+ASM/udump

創建ASM實例的password文件

  1. db2awse-> orapwd file=orapw+ASM entries=5 password=oracle

啓動asm實例,還沒創建diskgroup,報錯忽略

  1. db2awse-> export ORACLE_SID=+ASM
  2. db2awse-> sqlplus '/as sysdba'
  3. SQL*Plus: Release 10.2.0.1.0 - Production on Mon Dec 5 13:40:48 2016
  4. Copyright (c) 1982, 2005, Oracle. All rights reserved.
  5. Connected to an idle instance.
  6. SQL> startup
  7. ASM instance started
  8. Total System Global Area 130023424 bytes
  9. Fixed Size 2019032 bytes
  10. Variable Size 102838568 bytes
  11. ASM Cache 25165824 bytes
  12. ORA-15110: no diskgroups mounted

創建diskgroup

  1. SQL> create diskgroup dg1 external redundancy disk '/dev/oracleasm/disks/VOL1','/dev/oracleasm/disks/VOL2','/dev/oracleasm/disks/VOL3';
  2. Diskgroup created.
  3. SQL> create diskgroup dg2 external redundancy disk '/dev/oracleasm/disks/VOL4';
  4. Diskgroup created.
  5. SQL> create diskgroup recover external redundancy disk '/dev/oracleasm/disks/VOL5';
  6. Diskgroup created.

創建數據庫備份

  1. db2awse-> rman target /
  2. Recovery Manager: Release 10.2.0.1.0 - Production on Mon Dec 5 13:51:54 2016
  3. Copyright (c) 1982, 2005, Oracle. All rights reserved.
  4. connected to target database: ORCL (DBID=1457578197)
  5. RMAN> run {
  6. 2> backup as copy database format '+DG1';
  7. 3> }
  8. Starting backup at 05-DEC-16
  9. using target database control file instead of recovery catalog
  10. allocated channel: ORA_DISK_1
  11. channel ORA_DISK_1: sid=158 devtype=DISK
  12. channel ORA_DISK_1: starting datafile copy
  13. input datafile fno=00001 name=/database/oradata/orcl/system01.dbf
  14. output filename=+DG1/orcl/datafile/system.256.929800377 tag=TAG20161205T135248 recid=1 stamp=929800380
  15. channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
  16. channel ORA_DISK_1: starting datafile copy
  17. input datafile fno=00003 name=/database/oradata/orcl/sysaux01.dbf
  18. output filename=+DG1/orcl/datafile/sysaux.257.929800385 tag=TAG20161205T135248 recid=2 stamp=929800385
  19. channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
  20. channel ORA_DISK_1: starting datafile copy
  21. input datafile fno=00005 name=/database/oradata/orcl/wql.dbf
  22. output filename=+DG1/orcl/datafile/wql.258.929800387 tag=TAG20161205T135248 recid=3 stamp=929800387
  23. channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
  24. channel ORA_DISK_1: starting datafile copy
  25. input datafile fno=00002 name=/database/oradata/orcl/undotbs01.dbf
  26. output filename=+DG1/orcl/datafile/undotbs1.259.929800389 tag=TAG20161205T135248 recid=4 stamp=929800388
  27. channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
  28. channel ORA_DISK_1: starting datafile copy
  29. input datafile fno=00004 name=/database/oradata/orcl/users01.dbf
  30. output filename=+DG1/orcl/datafile/users.260.929800389 tag=TAG20161205T135248 recid=5 stamp=929800389
  31. channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
  32. channel ORA_DISK_1: starting datafile copy
  33. copying current control file
  34. output filename=+DG1/orcl/controlfile/backup.261.929800391 tag=TAG20161205T135248 recid=6 stamp=929800390
  35. channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
  36. channel ORA_DISK_1: starting full datafile backupset
  37. channel ORA_DISK_1: specifying datafile(s) in backupset
  38. including current SPFILE in backupset
  39. channel ORA_DISK_1: starting piece 1 at 05-DEC-16
  40. channel ORA_DISK_1: finished piece 1 at 05-DEC-16
  41. piece handle=+DG1/orcl/backupset/2016_12_05/nnsnf0_tag20161205t135248_0.262.929800393 tag=TAG20161205T135248 comment=NONE
  42. channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
  43. Finished backup at 05-DEC-16

修改數據庫參數

修改閃回參數

  1. SQL> show parameter db_recovery
  2. NAME TYPE VALUE
  3. ------------------------------------ ----------- ------------------------------
  4. db_recovery_file_dest string /database/flash_recovery_area
  5. db_recovery_file_dest_size big integer 2G
  6. SQL> alter system set db_recovery_file_dest_size=3G scope=both;
  7. System altered.
  8. SQL> alter system set db_recovery_file_dest='+RECOVERY' scope=both;
  9. System altered.
  10. SQL> show parameter db_recovery
  11. NAME TYPE VALUE
  12. ------------------------------------ ----------- ------------------------------
  13. db_recovery_file_dest string +RECOVERY
  14. db_recovery_file_dest_size big integer 3G

將聯機日誌和自動創建的數據文件位置指定爲磁盤組:

  1. SQL> alter system set db_create_file_dest='+DG1' scope=both;
  2. System altered.
  3. SQL> show parameter db_create_file_dest
  4. NAME TYPE VALUE
  5. ------------------------------------ ----------- ------------------------------
  6. db_create_file_dest string +DG1
  7. SQL> alter system set db_create_online_log_dest_1='+DG1' scope=both;
  8. System altered.
  9. SQL> alter system set db_create_online_log_dest_2='+DG2' scope=both;
  10. System altered.
  11. SQL> show parameter db_create_online
  12. NAME TYPE VALUE
  13. ------------------------------------ ----------- ------------------------------
  14. db_create_online_log_dest_1 string +DG1
  15. db_create_online_log_dest_2 string +DG2

遷移聯機日誌

當前日誌配置

  1. SQL> select group#,member from v$logfile;
  2. GROUP# MEMBER
  3. ---------- ----------------------------------------
  4. 3 /database/oradata/orcl/redo03.log
  5. 2 /database/oradata/orcl/redo02.log
  6. 1 /database/oradata/orcl/redo01.log

爲每個聯機日誌組添加兩個成員。然後刪除舊成員來遷移聯機日誌。因爲前面設置了db_create_online_log_dest_1/2,所以新建的會自動在dg中創建。

  1. SQL> alter database add logfile member '+DG1','+DG2' to group 1;
  2. Database altered.
  3. SQL> alter database add logfile member '+DG1','+DG2' to group 2;
  4. Database altered.
  5. SQL> alter database add logfile member '+DG1','+DG2' to group 3;
  6. Database altered.

通過執行alter system switch logfile;切換日誌,然後刪除舊的聯機日誌。

  1. alter database drop logfile member '/database/oradata/orcl/redo01.log';
  2. alter database drop logfile member '/database/oradata/orcl/redo02.log';
  3. alter database drop logfile member '/database/oradata/orcl/redo03.log';
  4. SQL> select group#,member,status from v$logfile order by 1;
  5. GROUP# MEMBER STATUS
  6. ---------- -------------------------------------------------- -------
  7. 1 +DG1/orcl/onlinelog/group_1.263.929801375
  8. 1 +DG2/orcl/onlinelog/group_1.256.929801375
  9. 2 +DG1/orcl/onlinelog/group_2.264.929801379
  10. 2 +DG2/orcl/onlinelog/group_2.257.929801379
  11. 3 +DG1/orcl/onlinelog/group_3.265.929801383
  12. 3 +DG2/orcl/onlinelog/group_3.258.929801383

遷移臨時表空間到asm

當前的tmp表空間配置

  1. SQL> select ts#,bytes/1024/1024,name from v$tempfile;
  2. TS# BYTES/1024/1024 NAME
  3. ---------- --------------- ----------------------------------------
  4. 3 20 /database/oradata/orcl/temp01.dbf
  5. SQL> select ts#,name from v$tablespace where ts#=3;
  6. TS# NAME
  7. ---------- ----------------------------------------
  8. 3 TEMP

爲臨時表空間增加文件,自動創建到dg中,然後刪除舊文件

  1. SQL> alter tablespace temp add tempfile size 30M;
  2. Tablespace altered.
  3. SQL> select ts#,bytes/1024/1024,name from v$tempfile;
  4. TS# BYTES/1024/1024 NAME
  5. ---------- --------------- ----------------------------------------
  6. 3 30 +DG1/orcl/tempfile/temp.266.929802143
  7. 3 20 /database/oradata/orcl/temp01.dbf
  8. SQL> alter database tempfile '/database/oradata/orcl/temp01.dbf' drop;
  9. Database altered.
  10. SQL> select ts#,bytes/1024/1024,name from v$tempfile;
  11. TS# BYTES/1024/1024 NAME
  12. ---------- --------------- ----------------------------------------
  13. 3 30 +DG1/orcl/tempfile/temp.266.929802143

遷移控制文件和數據文件(需關停實例)

檢查控制文件,並修改參數

  1. SQL> show parameter control_files
  2. NAME TYPE VALUE
  3. ------------------------------------ ----------- ------------------------------
  4. control_files string /database/oradata/orcl/control
  5. 01.ctl, /database/oradata/orcl
  6. /control02.ctl, /database/orad
  7. ata/orcl/control03.ctl
  8. SQL> alter system set control_files='+DG1/ORCL/CONTROLFILE/control01','+DG2/ORCL/CONTROLFILE/control02' scope=spfile;
  9. System altered.

關閉數據庫,並啓動到nomount狀態

  1. SQL> shutdown immediate
  2. Database closed.
  3. Database dismounted.
  4. ORACLE instance shut down.
  5. SQL> startup nomount
  6. ORACLE instance started.
  7. Total System Global Area 1224736768 bytes
  8. Fixed Size 2020384 bytes
  9. Variable Size 318770144 bytes
  10. Database Buffers 889192448 bytes
  11. Redo Buffers 14753792 bytes
  12. SQL>

在rman中進行完全恢復,恢復控制文件,可以看到,恢復到了指定位置

  1. db2awse-> rman target /
  2. Recovery Manager: Release 10.2.0.1.0 - Production on Mon Dec 5 14:31:22 2016
  3. Copyright (c) 1982, 2005, Oracle. All rights reserved.
  4. connected to target database: orcl (not mounted)
  5. RMAN> restore controlfile from '/database/oradata/orcl/control01.ctl';
  6. Starting restore at 05-DEC-16
  7. using target database control file instead of recovery catalog
  8. allocated channel: ORA_DISK_1
  9. channel ORA_DISK_1: sid=156 devtype=DISK
  10. channel ORA_DISK_1: copied control file copy
  11. output filename=+DG1/orcl/controlfile/control01
  12. output filename=+DG2/orcl/controlfile/control02
  13. Finished restore at 05-DEC-16

掛載數據庫,並切換數據文件

  1. RMAN> alter database mount;
  2. database mounted
  3. released channel: ORA_DISK_1
  4. RMAN> switch database to copy;
  5. datafile 1 switched to datafile copy "+DG1/orcl/datafile/system.256.929800377"
  6. datafile 2 switched to datafile copy "+DG1/orcl/datafile/undotbs1.259.929800389"
  7. datafile 3 switched to datafile copy "+DG1/orcl/datafile/sysaux.257.929800385"
  8. datafile 4 switched to datafile copy "+DG1/orcl/datafile/users.260.929800389"
  9. datafile 5 switched to datafile copy "+DG1/orcl/datafile/wql.258.929800387"

recover database並打開數據庫

  1. RMAN> recover database;
  2. Starting recover at 05-DEC-16
  3. allocated channel: ORA_DISK_1
  4. channel ORA_DISK_1: sid=156 devtype=DISK
  5. starting media recovery
  6. archive log thread 1 sequence 2 is already on disk as file /arch/1_2_929797463.dbf
  7. archive log thread 1 sequence 3 is already on disk as file /arch/1_3_929797463.dbf
  8. archive log thread 1 sequence 4 is already on disk as file /arch/1_4_929797463.dbf
  9. archive log thread 1 sequence 5 is already on disk as file /arch/1_5_929797463.dbf
  10. archive log filename=/arch/1_2_929797463.dbf thread=1 sequence=2
  11. archive log filename=/arch/1_3_929797463.dbf thread=1 sequence=3
  12. media recovery complete, elapsed time: 00:00:05
  13. Finished recover at 05-DEC-16
  14. RMAN> alter database open;
  15. database opened

確認遷移成功

  1. SQL> select name from v$controlfile;
  2. NAME
  3. ------------------------------------------
  4. +DG1/orcl/controlfile/control01
  5. +DG2/orcl/controlfile/control02
  6. SQL> select name,status from v$datafile;
  7. NAME STATUS
  8. ------------------------------------------ -------
  9. +DG1/orcl/datafile/system.256.929800377 SYSTEM
  10. +DG1/orcl/datafile/undotbs1.259.929800389 ONLINE
  11. +DG1/orcl/datafile/sysaux.257.929800385 ONLINE
  12. +DG1/orcl/datafile/users.260.929800389 ONLINE
  13. +DG1/orcl/datafile/wql.258.929800387 ONLINE
  14. SQL> select member from v$logfile;
  15. MEMBER
  16. --------------------------------------------------------------------------------
  17. +DG1/orcl/onlinelog/group_1.263.929801375
  18. +DG2/orcl/onlinelog/group_1.256.929801375
  19. +DG1/orcl/onlinelog/group_2.264.929801379
  20. +DG2/orcl/onlinelog/group_2.257.929801379
  21. +DG1/orcl/onlinelog/group_3.265.929801383
  22. +DG2/orcl/onlinelog/group_3.258.929801383
  23. 6 rows selected.
  24. SQL> select name,status from v$tempfile;
  25. NAME STATUS
  26. ------------------------------------------ -------
  27. +DG1/orcl/tempfile/temp.266.929802143 ONLINE

遷移成功,刪除原有的oradata目錄即可。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章