磁盘冷迁移方法 如果Oracle正在使用的磁盘出现了报警,则及时替换磁盘是很有必要的。下面假设系统中hdisk4和hdisk5出现了问题,需要进行替换。当前数据库放在卷组datavg上,查看datavg状态,如下: #lsvg –p datavg datavg: PV_NAME PV STATE TOTAL PPs FREE PPs FREE DISTRIBUTION hdisk2 active 7 1 00 . . 00 . . 00 . . 00 . . 01 hdisk3 active 7 1 00 . . 00 . . 00 . . 00 . . 01 hdisk4 active 7 2 01 . . 00 . . 00 . . 00 . . 01 hdisk5 active 7 2 01 . . 00 . . 00 . . 00 . . 02 将新的磁盘加入到系统中,通过运行cfgmgr命令后,可以查看磁盘在系统中的状态,如下: 注意:磁盘必须支持可热插拔。 #lspv –L hdisk0 0004563fe7bf7fbe rootvg active hdisk1 0004563febd0d4e1 rootvg active hdisk2 0004563f1d374260 datavg active hdisk3 0004563f1d374439 datavg active hdisk4 0004563f1d374260 datavg active hdisk5 0004563f1d374439 datavg active hdisk6 0004563f1d374260 datavg active hdisk7 0004563f1d374439 datavg active 我们看到hdisk6和hdisk7出现在系统中,接着我们将这两块盘添加到卷组datavg中。你可以通过smitty命令或者直接用命令extendvg来添加,这里为了让大家更加清晰理解,我用了smitty方法来添加,如下: #smitty extendvg Set Characteristics of a Volume Group Move cursor to desired item and press Enter. Change a Volume Group Add a Physical Volume from a Volume Group Remove a Physical Volume from a Volume Group Reorganize a Volume group 将hdisk6和hdisk7加入到卷组datavg中,如下: Add a Physical Volume to a Volume Group Type or select values in entry fields. Press Enter AFTER making all desired changes. [Entry Fields] Force the creation of a volume group? no *VOLUME GROUP name [datavg] + *PHYSICAL VOLUME nameS [hdisk6 hdisk7] + 添加成功后,你可以查看到卷组当前磁盘的状态,hdisk6和hdisk7已被添加到datavg中,且所有物理分区(PP)全部为空,如下: #lsvg –p datavg datavg: PV_NAME PV STATE TOTAL PPs FREE PPs FREE DISTRIBUTION hdisk2 active 7 1 00 . . 00 . . 00 . . 00 . . 01 hdisk3 active 7 1 00 . . 00 . . 00 . . 00 . . 01 hdisk4 active 7 2 01 . . 00 . . 00 . . 00 . . 01 hdisk5 active 7 2 01 . . 00 . . 00 . . 00 . . 02 hdisk6 active 7 7 01 . . 00 . . 00 . . 00 . . 02 hdisk7 active 7 7 01 . . 00 . . 00 . . 00 . . 02 为了更好进行数据库迁移,这里需要将Oracle数据库关闭,如下: SQL> show user USER is “SYS” SQL>shutdown immediate Database closed. Database dismounted. ORACLE instance shut down. 当关闭了数据库后,查看Oracle数据库的裸设备工作状态,全部为关闭状态。如下: #lsvg –l datavg datavg: LV NAME TYPE LPs PPs PVs LV STATE MOUNT POINT lv_system s raw 4 4 1 closed /syncd N/A lv_sysaux raw 3 3 1 closed /syncd N/A lv_ctl1 raw 1 1 1 closed /syncd N/A lv_ctl2 raw 1 1 1 closed /syncd N/A lv_redo1 raw 1 1 1 closed /syncd N/A lv_redo2 raw 1 4 1 closed /syncd N/A lv_undotbs01 raw 3 3 1 closed /syncd N/A lv_temp01 raw 2 2 1 closed /syncd N/A lv_users01 raw 2 2 1 closed /syncd N/A lv_spfileorcl raw 1 1 1 closed/syncd N/A lv_pwdorcl raw 1 1 1 closed /syncd N/A lv_test01 raw 1 1 1 closed /syncd N/A lv_test02 raw 1 1 1 closed /syncd N/A 所有前提工作准备就绪后,这里就需要用到一个命令migratepv来进行数据库的迁移,如下: Physical Volumes Move cursor to desired item and press Enter. List ALL Physical Volumes in system Add a Disk Change Characteristics of a Physical Volume List Contents of a Physical Volume Move Contents of a Physical Volume 在SOURCE physical volume name选择磁盘作为源磁盘,如hdisk4;在DESTINATION physical volumes选择磁盘作为目标盘,如hdisk6。如下: Move Contents of a Physical Volume Type or select values in entry fields. Press Enter AFTER making all desired changes. [Entry Fields] *SOURCE physical volume name hdisk4 + *DESTINATION physical volumes [hdisk6] + Move only data belonging to this [ ] LOGICAL VOLUME? 注意:现在物理卷hdisk4上的所有内容开始向hdisk6进行迁移了,在此过程中,datavg卷组处于lock状态,如下面命令执行报错结果,就是因为datavg的lock状态,而无法显示正常的结果。如下: #lsvg –l datavg 0516-1201 lspv: Waring : Volume group datavg is locked. This command will continue retries until lock is free. If lock is inadvertent and needs to be removed, execute ‘chvg –u datavg’. 数据迁移可能需要一断时间,这主要取决于数据的容量有多大了。当迁移成功完成后,查看hdisk4和hdisk6的内容,如下: #lspv –p hdisk4 hdisk4: PP RANGE STATE REGION LV NAME TYPE MOUNT POINT 1-2 free outer edge 3-3 free outer middle 4-4 free center 5-5 free inner middle 6-7 free inner edge #lspv –p hdisk6 hdisk6: PP RANGE STATE REGION LV NAME TYPE MOUNT POINT 1-2 free outer edge 2-2 used outer edge lv_redo1 raw N/A 3-3 used outer middle lv_ctl1 raw N/A 4-4 used center lv_undotbs1 raw N/A 5-5 used inner middle lv_undotbs1 raw N/A 6-7 used inner edge lv_undotbs1 raw N/A 7-7 free inner edge 从上图你可以查看到,hdisk4的数据已经完整地迁移到了hdisk6,现在你可以用同样的方法将hdisk5的数据迁移到hdisk7上,待所有数据都迁移完成后,通过smitty或者命令reducevg直接删除hdisk4和hdisk5,如下: Set Characteristics of a Volume Group Move cursor to desired item and press Enter. Change a Volume Group Add a Physical Volume to a Volume Group Remove a Physical Volume from a Volume Group Reorganize a Volume Group 选择要删除的物理卷hdisk4和hdisk5,按回车键执行,如下: Remove a Physical Volume from a Volume Group Type or select values in entry fields. Press Enter AFTER making all desired changes. [Entry Fields] *VOLUME GROUP name datavg + *PHYSICAL VOLUME nameS [hdisk4] + FORCE deallocation of all partitions on this physical volume? 删除hdisk4和hdisk5成功后,检查卷组datavg目前的使用情况,如下: #reducevg datavg hdisk5 #lsvg –p datavg datavg: PV_NAME PV STATE TOTAL PPs FREE PPs FREE DISTRIBUTION hdisk2 active 7 1 00 . . 00 . . 00 . . 00 . . 01 hdisk3 active 7 1 00 . . 00 . . 00 . . 00 . . 01 hdisk6 active 7 7 01 . . 00 . . 00 . . 00 . . 02 hdisk7 active 7 7 01 . . 00 . . 00 . . 00 . . 01 待一切正常后,重新启动Oracle数据库实例。 这种方法不好的一点就是需要关闭Oracle实例,不能保证业务正常运行。如果不想关闭,可以通过磁盘的热迁移来实现,其实这个磁盘热迁移就是用AIX系统mirror功能。 磁盘热迁移方法 如果你感觉冷迁移不太适合你的生产环境,我们可以采用磁盘的热迁移方法来实现。环境和上面一样,如下: #lsvg –p datavg datavg: PV_NAME PV STATE TOTAL PPs FREE PPs FREE DISTRIBUTION hdisk2 active 7 1 00 . . 00 . . 00 . . 00 . . 01 hdisk3 active 7 1 00 . . 00 . . 00 . . 00 . . 01 hdisk6 active 7 2 01 . . 00 . . 00 . . 00 . . 01 hdisk7 active 7 2 01 . . 00 . . 00 . . 00 . . 01 从上图可以看到,卷组datavg中当前有磁盘hdisk2、hdisk3、hdisk6、hdisk7。需要迁移,就需要磁盘,如下: #lspv hdisk0 0004563fe7bf7fbe rootvg active hdisk1 0004563febd0d4e1 rootvg active hdisk2 0004563f1d374260 datavg active hdisk3 0004563f1d374439 datavg active hdisk4 0004563f1d374260 none hdisk5 0004563f1d374439 none hdisk6 0004563f1d374260 datavg active hdisk7 0004563f1d374439 datavg active hdisk8 0004563f1d374260 none hdisk9 0004563f1d374439 none 从上图lspv显示的结果,可知,目前系统上有hdisk4、hdisk5、hdisk8和hdisk9未被使用。现在将这些磁盘加入到datavg中,如下: #extendvg datavg hdisk4 hdisk5 hdisk8 hdisk9 添加成功后,系统中磁盘状态如下: #lspv hdisk0 0004563fe7bf7fbe rootvg active hdisk1 0004563febd0d4e1 rootvg active hdisk2 0004563f1d374260 datavg active hdisk3 0004563f1d374439 datavg active hdisk4 0004563f1d374260 datavg active hdisk5 0004563f1d374439 datavg active hdisk6 0004563f1d374260 datavg active hdisk7 0004563f1d374439 datavg active hdisk8 0004563f1d374260 datavg active hdisk9 0004563f1d374439 datavg active 现在可以执行mirrorvg命令对datavg进行镜像,然而这个操作可能需要费时间,如下: #mirrorvg datavg 0516-1125 mirrorvg: Quorom requirement turned off, varyoff and varyon volume group for this to take effect. 注意,在镜像期间,对卷组的大多数操作都是禁止的,如下: #lspv hdisk9 0516-1201 lspv: Waring : Volume group datavg is locked. This command will continue retries until lock is free. If lock is inadvertent and needs to be removed, execute ‘chvg –u datavg’. 但是有一点可以确定,数据库实例可以正常运行。查看datavg卷组上裸设备的状态可知,如下: #lsvg –l datavg datavg: LV NAME TYPE LPs PPs PVs LV STATE MOUNT POINT lv_system s raw 4 4 1 open/syncd N/A lv_sysaux raw 3 3 1 open/syncd N/A lv_ctl1 raw 1 1 1 open/syncd N/A lv_ctl2 raw 1 1 1 open/syncd N/A lv_redo1 raw 1 1 1 open/syncd N/A lv_redo2 raw 1 4 1 open/syncd N/A lv_undotbs01 raw 3 3 1 open/syncd N/A lv_temp01 raw 2 2 1 open/syncd N/A lv_users01 raw 2 2 1 open/syncd N/A lv_spfileorcl raw 1 1 1 closed/syncd N/A lv_pwdorcl raw 1 1 1 closed /syncd N/A lv_test01 raw 1 1 1 open/syncd N/A lv_test02 raw 1 1 1 open/syncd N/A 当你完成镜像后,需要拆除镜像,将hdisk2、hdisk3、hdisk6、hdisk7从卷组datavg中删除,如下操作: #reducevg datavg hdisk2 hdisk3 hdisk6 hdisk7 #lspv hdisk0 0004563fe7bf7fbe rootvg active hdisk1 0004563febd0d4e1 rootvg active hdisk2 0004563f1d374260 none hdisk3 0004563f1d374439 none hdisk4 0004563f1d374260 datavg active hdisk5 0004563f1d374439 datavg active hdisk6 0004563f1d374260 none hdisk7 0004563f1d374439 none hdisk8 0004563f1d374260 datavg active hdisk9 0004563f1d374439 datavg active 在查看卷组datavg的状态,如下: # lsvg –p datavg datavg: PV_NAME PV STATE TOTAL PPs FREE PPs FREE DISTRIBUTION hdisk4 active 7 1 00 . . 00 . . 00 . . 00 . . 01 hdisk5 active 7 1 00 . . 00 . . 00 . . 00 . . 01 hdisk8 active 7 2 01 . . 00 . . 00 . . 00 . . 01 hdisk9 active 7 2 01 . . 00 . . 00 . . 00 . . 02 从上图lsvg显示的状态可以知道,hdisk2、hdisk3、hdisk6、hdisk7已从datavg中拆除,现在只由hdisk4、hdisk5、hdisk8和hdisk9构成了datavg。如果在允许的情况下,建议最好重新激活一下卷组datavg,以及设置Quorum参数。如下: #varyoffvg datavg #chvg –Q y datavg #varyonvg datavg 上面两种迁移方法,非常简单易操作,但是为了安全建议对数据还是做一个备份,保证万无一失,如果你对数据库比较熟悉,可以用数据库的恢复方法、数据文件直接迁移的方法。 |