三、rman 資料庫遷移--從檔案系統到裸裝置

haozg_oracle發表於2012-06-19
三、從檔案系統遷移資料庫到lv裸裝置
 
使用備份的控制檔案
 
1、建立對應的lv
引數檔案 spfile
控制檔案
日誌檔案
資料檔案
[root@haozg /]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000ec9c9
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        2611    20458496   8e  Linux LVM
Disk /dev/sdb: 536 MB, 536870912 bytes
64 heads, 32 sectors/track, 512 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x5bbec611
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         512      524272    5  Extended
/dev/sdb5               1          50       51168   83  Linux
/dev/sdb6              51          99       50160   83  Linux
/dev/sdb7             100         148       50160   83  Linux
/dev/sdb8             149         512      372720   83  Linux
Disk /dev/sdc: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/sdc doesn't contain a valid partition table
Disk /dev/mapper/vg_haozg-lv_root: 18.8 GB, 18832424960 bytes
255 heads, 63 sectors/track, 2289 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/vg_haozg-lv_root doesn't contain a valid partition table
Disk /dev/mapper/vg_haozg-lv_swap: 2113 MB, 2113929216 bytes
255 heads, 63 sectors/track, 257 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/vg_haozg-lv_swap doesn't contain a valid partition table
Disk /dev/mapper/vg01-lv_ocr10m: 12 MB, 12582912 bytes
255 heads, 63 sectors/track, 1 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/vg01-lv_ocr10m doesn't contain a valid partition table
[root@haozg /]#
[root@haozg /]#
[root@haozg /]# fdisk /dev/sdc
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x9206bfbf.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-391, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-391, default 391):
Using default value 391
Command (m for help): p
Disk /dev/sdc: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x9206bfbf
   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1         391     3140676   83  Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@haozg /]#
[root@haozg /]#
[root@haozg /]# fdisk -;
Unable to open -
[root@haozg /]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000ec9c9
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        2611    20458496   8e  Linux LVM
Disk /dev/sdb: 536 MB, 536870912 bytes
64 heads, 32 sectors/track, 512 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x5bbec611
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         512      524272    5  Extended
/dev/sdb5               1          50       51168   83  Linux
/dev/sdb6              51          99       50160   83  Linux
/dev/sdb7             100         148       50160   83  Linux
/dev/sdb8             149         512      372720   83  Linux
Disk /dev/sdc: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x9206bfbf
   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1         391     3140676   83  Linux
Disk /dev/mapper/vg_haozg-lv_root: 18.8 GB, 18832424960 bytes
255 heads, 63 sectors/track, 2289 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/vg_haozg-lv_root doesn't contain a valid partition table
Disk /dev/mapper/vg_haozg-lv_swap: 2113 MB, 2113929216 bytes
255 heads, 63 sectors/track, 257 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/vg_haozg-lv_swap doesn't contain a valid partition table
Disk /dev/mapper/vg01-lv_ocr10m: 12 MB, 12582912 bytes
255 heads, 63 sectors/track, 1 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/vg01-lv_ocr10m doesn't contain a valid partition table
[root@haozg /]#
[root@haozg /]# pvcreate /dev/sdc1
  Writing physical volume data to disk "/dev/sdc1"
  Physical volume "/dev/sdc1" successfully created
[root@haozg /]# vgcreate oradata /dev/sdc1
  Volume group "oradata" successfully created
[root@haozg /]# lvcreate -L 10m -n lv_spfile oradata
  Rounding up size to full physical extent 12.00 MiB
  Logical volume "lv_spfile" created
[root@haozg /]# lvcreate -L 20m -n lv_control1 oradata
  Logical volume "lv_control1" created
[root@haozg /]# lvcreate -L 20m -n lv_control2 oradata
  Logical volume "lv_control2" created
[root@haozg /]# lvcreate -L 100m -n lv_redo1 oradata
  Logical volume "lv_redo1" created
[root@haozg /]# lvcreate -L 100m -n lv_redo2 oradata
  Logical volume "lv_redo2" created
[root@haozg /]# lvcreate -L 100m -n lv_redo3 oradata
  Logical volume "lv_redo3" created
[root@haozg /]# lv_create -L 1100m -n lv_system oradata
-bash: lv_create: command not found
[root@haozg /]# lvcreate -L 1100m -n lv_system oradata
  Logical volume "lv_system" created
[root@haozg /]# lvcreate -L 30m -n lv_temp oradata
  Rounding up size to full physical extent 32.00 MiB
  Logical volume "lv_temp" created
[root@haozg /]# lvcreate -L 550m -n lv_sysaux oradata
  Rounding up size to full physical extent 552.00 MiB
  Logical volume "lv_sysaux" created
[root@haozg /]# lvcreate -L 320m -n lv_undo oradata
  Logical volume "lv_undo" created
[root@haozg oradata]# lvcreate -L 700m -n lv_user oradata
  Logical volume "lv_user" created
[root@haozg /]#
2、改變屬組
[root@haozg dev]# chown -R oracle:dba /dev/oradata
[root@haozg dev]# cd oradata
[root@haozg oradata]# ls -al
total 0
drwxr-xr-x.  2 oracle dba   240 May 19 14:47 .
drwxr-xr-x. 21 root   root 4280 May 19 14:47 ..
lrwxrwxrwx.  1 oracle dba     7 May 19 14:38 lv_control1 -> ../dm-4
lrwxrwxrwx.  1 oracle dba     7 May 19 14:38 lv_control2 -> ../dm-5
lrwxrwxrwx.  1 oracle dba     7 May 19 14:40 lv_redo1 -> ../dm-6
lrwxrwxrwx.  1 oracle dba     7 May 19 14:41 lv_redo2 -> ../dm-7
lrwxrwxrwx.  1 oracle dba     7 May 19 14:41 lv_redo3 -> ../dm-8
lrwxrwxrwx.  1 oracle dba     7 May 19 14:37 lv_spfile -> ../dm-3
lrwxrwxrwx.  1 oracle dba     8 May 19 14:46 lv_sysaux -> ../dm-11
lrwxrwxrwx.  1 oracle dba     7 May 19 14:44 lv_system -> ../dm-9
lrwxrwxrwx.  1 oracle dba     8 May 19 14:45 lv_temp -> ../dm-10
lrwxrwxrwx.  1 oracle dba     8 May 19 14:47 lv_undo -> ../dm-12
[root@haozg oradata]#

3、RHEL5中取消了rawdevices對映檔案,可以通過兩種方式開機載入裸裝置,一種是使用UDEV,另外一種是寫入rc.local指令碼,
本文使用rc.local指令碼的方式開機啟用裸裝置。
建立一個/etc/rc.raw指令碼內容如下:
[root@orcl ~]# vi /etc/rc.raw
/bin/raw /dev/raw/raw1 /dev/mapper/oradata-lv_control1
/bin/raw /dev/raw/raw2 /dev/mapper/oradata-lv_control2
/bin/raw /dev/raw/raw3 /dev/mapper/oradata-lv_redo1
/bin/raw /dev/raw/raw4 /dev/mapper/oradata-lv_redo2
/bin/raw /dev/raw/raw5 /dev/mapper/oradata-lv_redo3
/bin/raw /dev/raw/raw6 /dev/mapper/oradata-lv_spfile
/bin/raw /dev/raw/raw7 /dev/mapper/oradata-lv_sysaux
/bin/raw /dev/raw/raw8 /dev/mapper/oradata-lv_system
/bin/raw /dev/raw/raw9 /dev/mapper/oradata-lv_temp
/bin/raw /dev/raw/raw10 /dev/mapper/oradata-lv_undo
/bin/raw /dev/raw/raw11 /dev/mapper/oradata-lv_user
/bin/raw /dev/raw/raw12 /dev/mapper/oradata1-lv_user01
/bin/chown oracle:oinstall /dev/mapper/oradata*
/bin/chown oracle:oinstall /dev/raw/*
/bin/chmod 660 /dev/raw/*
[root@haozg dev]# cd /etc
[root@haozg etc]# more rc.raw
/bin/raw /dev/raw/raw1 /dev/mapper/oradata-lv_control1
/bin/raw /dev/raw/raw2 /dev/mapper/oradata-lv_control2
/bin/raw /dev/raw/raw3 /dev/mapper/oradata-lv_redo1
/bin/raw /dev/raw/raw4 /dev/mapper/oradata-lv_redo2
/bin/raw /dev/raw/raw5 /dev/mapper/oradata-lv_redo3
/bin/raw /dev/raw/raw6 /dev/mapper/oradata-lv_spfile
/bin/raw /dev/raw/raw7 /dev/mapper/oradata-lv_sysaux
/bin/raw /dev/raw/raw8 /dev/mapper/oradata-lv_system
/bin/raw /dev/raw/raw9 /dev/mapper/oradata-lv_temp
/bin/raw /dev/raw/raw10 /dev/mapper/oradata-lv_undo
/bin/raw /dev/raw/raw11 /dev/mapper/oradata-lv_user
/bin/raw /dev/raw/raw12 /dev/mapper/oradata1-lv_user01
/bin/chown oracle:oinstall /dev/mapper/oradata*
/bin/chown oracle:oinstall /dev/raw/*
/bin/chmod 660 /dev/raw/*
[root@haozg etc]#
重啟系統檢視raw
[root@haozg ~]# cd /dev/raw
[root@haozg raw]# ls -al
total 0
drwxr-xr-x.  2 root   root         300 May 19 22:23 .
drwxr-xr-x. 22 root   root        4400 May 19 22:23 ..
crw-rw----.  1 oracle oinstall 162,  1 May 19 22:23 raw1
crw-rw----.  1 oracle oinstall 162, 10 May 19 22:23 raw10
crw-rw----.  1 oracle oinstall 162, 11 May 19 22:23 raw11
crw-rw----.  1 oracle oinstall 162, 12 May 19 22:23 raw12
crw-rw----.  1 oracle oinstall 162,  2 May 19 22:23 raw2
crw-rw----.  1 oracle oinstall 162,  3 May 19 22:23 raw3
crw-rw----.  1 oracle oinstall 162,  4 May 19 22:23 raw4
crw-rw----.  1 oracle oinstall 162,  5 May 19 22:23 raw5
crw-rw----.  1 oracle oinstall 162,  6 May 19 22:23 raw6
crw-rw----.  1 oracle oinstall 162,  7 May 19 22:23 raw7
crw-rw----.  1 oracle oinstall 162,  8 May 19 22:23 raw8
crw-rw----.  1 oracle oinstall 162,  9 May 19 22:23 raw9
crw-rw----.  1 oracle oinstall 162,  0 May 19 22:22 rawctl
[root@haozg raw]# raw -qa
/dev/raw/raw1:  bound to major 253, minor 4
/dev/raw/raw2:  bound to major 253, minor 5
/dev/raw/raw3:  bound to major 253, minor 6
/dev/raw/raw4:  bound to major 253, minor 7
/dev/raw/raw5:  bound to major 253, minor 8
/dev/raw/raw6:  bound to major 253, minor 3
/dev/raw/raw7:  bound to major 253, minor 11
/dev/raw/raw8:  bound to major 253, minor 9
/dev/raw/raw9:  bound to major 253, minor 10
/dev/raw/raw10: bound to major 253, minor 12
/dev/raw/raw11: bound to major 253, minor 13
/dev/raw/raw12: bound to major 253, minor 2
[root@haozg raw]#
 

----建立快鍵方式
ln -s /dev/raw/raw1 /u01/app/rawdevice/control1
ln -s /dev/raw/raw2 /u01/app/rawdevice/control2
ln -s /dev/raw/raw3 /u01/app/rawdevice/redo1
ln -s /dev/raw/raw4 /u01/app/rawdevice/redo2
ln -s /dev/raw/raw5 /u01/app/rawdevice/redo3
ln -s /dev/raw/raw6 /u01/app/rawdevice/spfile
ln -s /dev/raw/raw7 /u01/app/rawdevice/sysaux
ln -s /dev/raw/raw8 /u01/app/rawdevice/system
ln -s /dev/raw/raw9 /u01/app/rawdevice/temp
ln -s /dev/raw/raw10 /u01/app/rawdevice/undo
ln -s /dev/raw/raw11 /u01/app/rawdevice/user
ln -s /dev/raw/raw12 /u01/app/rawdevice/user01
4、 在rman下從檔案系統複製資料檔案到raw裝置,在mount狀態下
---複製資料檔案
copy datafile '/u01/app/oradata/system01.dbf' to '/u01/app/rawdevice/system';
copy datafile '/u01/app/oradata/undo01.dbf' to '/u01/app/rawdevice/undo';
copy datafile '/u01/app/oradata/sysaux01.dbf' to '/u01/app/rawdevice/sysaux';
copy datafile '/u01/app/oradata/user01.dbf' to '/u01/app/rawdevice/user01';
--具體操作過程如下:
[oracle@haozg ~]$ rman target /
Recovery Manager: Release 11.2.0.1.0 - Production on Sat May 19 21:36:00 2012
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
connected to target database: ORA11G (DBID=4179426506, not open)

RMAN> copy datafile '/u01/app/oradata/system01.dbf' to '/u01/app/rawdevice/system';
Starting backup at 19-MAY-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=21 device type=DISK
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001 name=/u01/app/oradata/system01.dbf
output file name=/u01/app/rawdevice/system tag=TAG20120519T213608 RECID=1 STAMP=783725841
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:01:15
Finished backup at 19-MAY-12
RMAN> copy datafile '/u01/app/oradata/undo01.dbf' to '/u01/app/rawdevice/undo';
Starting backup at 19-MAY-12
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00003 name=/u01/app/oradata/undo01.dbf
output file name=/u01/app/rawdevice/undo tag=TAG20120519T213901 RECID=2 STAMP=783725955
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
Finished backup at 19-MAY-12
RMAN> copy datafile '/u01/app/oradata/sysaux01.dbf' to '/u01/app/rawdevice/sysaux';
Starting backup at 19-MAY-12
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002 name=/u01/app/oradata/sysaux01.dbf
output file name=/u01/app/rawdevice/sysaux tag=TAG20120519T214125 RECID=3 STAMP=783726113
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:36
Finished backup at 19-MAY-12
RMAN>
RMAN> copy datafile '/u01/app/oradata/user01.dbf' to '/u01/app/rawdevice/user01';
Starting backup at 19-MAY-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=18 device type=DISK
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=/u01/app/oradata/user01.dbf
output file name=/u01/app/rawdevice/user01 tag=TAG20120519T223532 RECID=4 STAMP=783729380
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:55
Finished backup at 19-MAY-12
RMAN>
5、修改資料檔案在控制檔案中的路徑 在sqlplus下操作, 資料在mount狀態下
alter database rename file '/u01/app/oradata/system01.dbf' to '/u01/app/rawdevice/system';
alter database rename file '/u01/app/oradata/sysaux01.dbf' to '/u01/app/rawdevice/sysaux';
alter database rename file '/u01/app/oradata/undo01.dbf' to '/u01/app/rawdevice/undo';
alter database rename file '/u01/app/oradata/user01.dbf' to '/u01/app/rawdevice/user01';
---具體操作過程如下:
下面的命令立刻生效
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area  146472960 bytes
Fixed Size                  1335080 bytes
Variable Size              92274904 bytes
Database Buffers           50331648 bytes
Redo Buffers                2531328 bytes
Database mounted.
SQL> alter database rename file '/u01/app/oradata/system01.dbf' to '/u01/app/rawdevice/system';
Database altered.
SQL> alter database rename file '/u01/app/oradata/sysaux01.dbf' to '/u01/app/rawdevice/sysaux';
Database altered.
SQL> alter database rename file '/u01/app/oradata/undo01.dbf' to '/u01/app/rawdevice/undo';
Database altered.
SQL> alter database rename file '/u01/app/oradata/user01.dbf' to '/u01/app/rawdevice/user01';
Database altered.
---************************截止到此時能開啟資料庫嗎?*************************************
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/u01/app/rawdevice/system
/u01/app/rawdevice/sysaux
/u01/app/rawdevice/undo
/u01/app/rawdevice/user01
SQL>
6、在sqlplus 下把檔案系統的日誌檔案改到裸裝置上,修改日誌檔案在控制檔案的路徑。

SQL> select group#,status from v$log;
    GROUP# STATUS
---------- ----------------
         1 INACTIVE
         3 CURRENT
         2 INACTIVE
SQL>
alter database drop logfile group 2;
Alter database add logfile group 2 ('/u01/app/rawdevice/redo2') size 80m;

alter database drop logfile group 1;
Alter database add logfile group 1 ('/u01/app/rawdevice/redo1') size 80m;

alter database drop logfile group 3;
Alter database add logfile group 3 ('/u01/app/rawdevice/redo3') size 80m;

具體過程如下:
SQL> select group#,status from v$log;
    GROUP# STATUS
---------- ----------------
         1 INACTIVE
         3 CURRENT
         2 INACTIVE
SQL> select group#,status from v$log;
    GROUP# STATUS
---------- ----------------
         1 INACTIVE
         3 CURRENT
         2 INACTIVE
SQL> alter database drop logfile group 2;
Database altered.
SQL> Alter database add logfile group 2 ('/u01/app/rawdevice/redo2')size 80m;
Database altered.
SQL> alter database open;
Database altered.
SQL>  select group#,status from v$log;
    GROUP# STATUS
---------- ----------------
         1 INACTIVE
         2 CURRENT
         3 INACTIVE
SQL> select * from v$logfiles;
select * from v$logfiles
              *
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> select * from v$logfile;
    GROUP# STATUS  TYPE
---------- ------- -------
MEMBER
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
IS_
---
         1         ONLINE
/u01/app/oradata/log01.dbf
NO
         2         ONLINE
/u01/app/rawdevice/redo2
NO
         3         ONLINE
/u01/app/oradata/log03.dbf
NO

SQL> alter database drop logfile group 1;
Database altered.
SQL> select * from v$logfile;
    GROUP# STATUS  TYPE
---------- ------- -------
MEMBER
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
IS_
---
         2         ONLINE
/u01/app/rawdevice/redo2
NO
         3         ONLINE
/u01/app/oradata/log03.dbf
NO

SQL> Alter database add logfile group 1 ('/u01/app/rawdevice/redo1') size 80m;
Database altered.
SQL> select group#,status from v$log;
    GROUP# STATUS
---------- ----------------
         1 UNUSED
         2 CURRENT
         3 INACTIVE
SQL> alter system switch logfile;
System altered.
SQL>  select group#,status from v$log;
    GROUP# STATUS
---------- ----------------
         1 CURRENT
         2 ACTIVE
         3 INACTIVE
SQL> alter database drop logfile group 3;
Database altered.
SQL> Alter database add logfile group 3 ('/u01/app/rawdevice/redo3')size 80m; 
Database altered.
SQL> select group#,status from v$log;
    GROUP# STATUS
---------- ----------------
         1 CURRENT
         2 ACTIVE
         3 UNUSED
SQL> alter system switch lofile;
alter system switch lofile
                    *
ERROR at line 1:
ORA-01900: LOGFILE keyword expected

SQL> alter system switch logfile;
System altered.
SQL> select group#,status from v$log;
    GROUP# STATUS
---------- ----------------
         1 ACTIVE
         2 ACTIVE
         3 CURRENT
SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/u01/app/rawdevice/redo1
/u01/app/rawdevice/redo2
/u01/app/rawdevice/redo3
SQL>
原則是保持始終有兩個日誌可以切換,刪掉inactive狀態的日誌組,然後切換,把unused狀態的日誌改為active狀態。
最後發出checkpoint。保持所有日誌scn一致。
SQL> alter system checkpoint;
System altered.
7、修改spfile到raw裝置上來
create pfile='/u01/app/newpfile2.ora' from spfile;
create spfile='/u01/app/rawdevice/spfile' from pfile='/u01/app/newpfile2.ora';
--具體操作過程如下
SQL> select status from v$instance;
STATUS
------------
MOUNTED
SQL>
SQL> create pfile='/u01/app/newpfile.ora' from spfile;
File created.
SQL> create spfile='/u01/app/rawdevice/spfile' from pfile='/u01/app/newpfile.ora';
File created.
SQL>
8、使用新的spfile檔案,修改initsid.ora 檔案指向新的spfile檔案
[oracle@haozg dbs]$ mv initora11g.ora initora11g.ora.bak
[oracle@haozg dbs]$ mv spfileora11g.ora  spfileora11g.ora.bak
[oracle@haozg dbs]$ vi initora11g.ora
spfile='/u01/app/rawdevice/spfile'

[oracle@haozg dbs]$ more initora11g.ora
spfile='/u01/app/rawdevice/spfile'
然後刪掉原來的spfile檔案,否則還會找原來的spfile檔案,現在要通過initora11g檔案來找裸裝置上的spfile檔案
[oracle@haozg dbs]$ rm -rf spfileora11g.ora
9、在mount狀態下,把內容變動後的控制檔案備份到裸裝置上,在sqlplus下操作
alter database backup controlfile to '/u01/app/rawdevice/control1';
alter database backup controlfile to '/u01/app/rawdevice/control2';

另: 用dd方式 在關閉的資料庫的情況下
dd if=/u01/app/oradata/control1.ctl f=/u01/app/rawdevice/control1
dd if=/u01/app/oradata/control2.ctl f=/u01/app/rawdevice/control2

10、修改控制檔案在spfile引數檔案中的位置,在nomount情況下

alter system set control_files='/u01/app/rawdevice/control1', '/u01/app/rawdevice/control2' scope=spfile;
具體過程如下
SQL> startup nomount;
ORACLE instance started.
Total System Global Area  146472960 bytes
Fixed Size                  1335080 bytes
Variable Size              92274904 bytes
Database Buffers           50331648 bytes
Redo Buffers                2531328 bytes
SQL>
SQL>
SQL>
SQL> alter system set control_files='/u01/app/rawdevice/control1', '/u01/app/rawdevice/control2' scope=spfile;
System altered.
SQL> shutdown immediate;
ORA-01507: database not mounted

ORACLE instance shut down.
SQL>
SQL>
SQL>
SQL> show parameter control
ORA-01034: ORACLE not available
Process ID: 4215
Session ID: 1 Serial number: 3

SQL> startup
ORACLE instance started.
Total System Global Area  146472960 bytes
Fixed Size                  1335080 bytes
Variable Size              92274904 bytes
Database Buffers           50331648 bytes
Redo Buffers                2531328 bytes
Database mounted.
ORA-01610: recovery using the BACKUP CONTROLFILE option must be done
---在開啟資料庫的時候需要做介質恢復,所以在遷移之前一定要做全庫的rman備份。
--原因是控制檔案在mount狀態關閉庫後會發生變化,當前的控制檔案和備份的控制檔案不一致。
SQL> recover database using backup controlfile;
ORA-00279: change 261584 generated at 05/20/2012 21:51:06 needed for thread 1
ORA-00289: suggestion : /u01/app/archivelog/1_9_783811587.dbf
ORA-00280: change 261584 for thread 1 is in sequence #9

Specify log: {=suggested | filename | AUTO | CANCEL}
auto
ORA-00308: cannot open archived log '/u01/app/archivelog/1_9_783811587.dbf'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3

ORA-00308: cannot open archived log '/u01/app/archivelog/1_9_783811587.dbf'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3

SQL> alter database open resetlogs;
Database altered.
 
 
 
 
 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/23062014/viewspace-733254/,如需轉載,請註明出處,否則將追究法律責任。

相關文章