存档

2010年6月7日 的存档,文章数:1

一、添加镜像

为master设备添加镜像设备:

1> disk mirror
2> name='master',
3> mirror='D:\sybase\data\master_mirr.dat'
4> go
Msg 5155, Level 16, State 1:
Server 'TEST', Line 1:
The command 'DISK MIRROR' cannot be executed since disk mirroring has been
disabled. In order to enable disk mirroring, use: sp_configure 'disable disk
mirroring',0 and restart the server.

 

ASE默认是关闭设备镜像功能的,需要配置参数启用。disable disk mirroring 这是一个静态参数,配置完之后需要重启ASE服务器。

1> sp_configure "disable disk mirroring",0
2> go
 Parameter Name                 Default     Memory Used Config Value
         Run Value    Unit                 Type
 ------------------------------ ----------- ----------- ------------
         ------------ -------------------- ----------
 disable disk mirroring                   1           0            0
                    1 switch               static
(1 row affected)
Configuration option changed. Since the option is static, Adaptive Server must
be rebooted in order for the change to take effect.
Changing the value of 'disable disk mirroring' to '0' reduces the amount of
memory ASE uses by 18636 K. The reduced memory may be reused when this configure
value changes, but will not be released until ASE restarts.
(return status = 0)

 

重启ASE服务器之后。

执行命令镜像master设备

1> disk mirror
2> name='master',
3> mirror='D:\sybase\data\master_mirr.dat'
4> go
Creating the physical file for the mirror...
Starting Dynamic Mirroring of 20480 pages for logical device 'master'.
         512 pages mirrored...
        1024 pages mirrored...
        1536 pages mirrored...
        2048 pages mirrored...
        2560 pages mirrored...
        3072 pages mirrored...
        3584 pages mirrored...
        4096 pages mirrored...
        4608 pages mirrored...
        5120 pages mirrored...
        5632 pages mirrored...
        6144 pages mirrored...
        6656 pages mirrored...
        7168 pages mirrored...
        7680 pages mirrored...
        8192 pages mirrored...
        8704 pages mirrored...
        9216 pages mirrored...
        9728 pages mirrored...
The remaining 10752 pages are currently unallocated and will be mirrored as they
are allocated.
1>

 

成功完成!

利用过程sp_helpdevice查看master设备目前的状态。

1> sp_helpdevice master
2> go
 device_name physical_name
         description
         status cntrltype vdevno vpn_low vpn_high
 ----------- -------------------------
         -------------------------------------------------------------------------
         ------ --------- ------ ------- --------
 master      D:\sybase\data\master.dat
         file system device, special, MIRROR ENABLED, mirror = 'D:\sybase\data\m
         aster_mirr.dat',
serial writes, dsync on, directio off, reads mirrored,
          default disk, physical disk, 80.00 MB, Free: 42.00 MB
            739         0      0       0    40959
(1 row affected)
 dbname      size          allocated           vstart lstart
 ----------- ------------- ------------------- ------ ------
 master           26.00 MB Dec  2 2009  6:58PM      4      0
 model             6.00 MB Dec  2 2009  6:58PM  13316      0
 sybsystemdb       6.00 MB Dec  2 2009  6:58PM  19460      0
(1 row affected)
(return status = 0)

 

下面来解析一下被镜像后master设备的状态字段。

master设备被镜像后,在sysdevices系统表中并没有增加记录行;仅仅是更新了master设备对应的记录行中的status和mirrorname两个字段的内容。

1> select * from sysdevices
2> where name='master'
3> go
 low         high        status cntrltype name                           phyname                                                                                                                         mirrorname                                                                                                                      vdevno      crdate                     resizedate                 status2
 ----------- ----------- ------ --------- ------------------------------ ------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------- ----------- -------------------------- -------------------------- -----------
           0       40959    739         0 master                         D:\sybase\data\master.dat                                                                                                       D:\sybase\data\master_mirr.dat                                                                                                            0        Dec  2 2009  6:58PM        Mar 27 2010  4:32PM           0
(1 row affected)
1>
 

从上面可以看出master设备对应的status变成了739。status字段用bit位来表示各个状态的信息。

739 = 1 + 2 + 32 + 64 + 128 + 512

其中:

1:缺省磁盘; 

2:物理磁盘 

32:串行写 

64:设备已镜像 

128: 读已镜像

512:已允许镜像

这几个状态和sp_helpdevice master 中查看到的相一致。 呵呵, 要是看过sp_helpdevice的源代码的话,自然很好理解。

 

二、取消镜像

unmirror分两种情况:user-initiated 和 system-initiated 。 在镜像设备上如果出现了IO错误会导致系统自动取消该设备的镜像。

用户手动取消镜像的语法为:

 disk unmirror

name="logical_device_name"

[,side={"primary"|secondary}]

[,mode={retain|remove}]

其中side和mode两个选项是可选的。side的默认值为:secondary,意思是取消哪一边的镜像设备(有主设备和镜像设备两个)。 mode的默认值是retain,意思是本次取消是临时的(retain,下次还可以激活设备以再次用来镜像)还是永久的(remove,删除设备了)。

下面测试临时取消master设备的镜像功能!

1> disk unmirror
2> name='master',side=secondary,mode=retain
3> go
1>

 

执行完,没有任何提示信息。在errlog文件中看到有这么一条信息:00:00000:00030:2010/06/07 13:20:59.59 kernel  Closing the secondary device for virtual device master

现在再来看看master设备的状态信息:

1> sp_helpdevice master
2> go
 device_name physical_name             description                                                                                                                                                                                           status cntrltype vdevno vpn_low vpn_high
 ----------- ------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------ --------- ------ ------- --------
 master      D:\sybase\data\master.dat file system device, special, MIRROR DISABLED, mirror = 'D:\sybase\data\master_mirr.dat', serial writes, dsync on, directio off, reads mirrored, default disk, physical disk, 80.00 MB, Free: 42.00 MB   2275         0      0       0    40959
(1 row affected)
 dbname      size          allocated           vstart lstart
 ----------- ------------- ------------------- ------ ------
 master           26.00 MB Dec  2 2009  6:58PM      4      0
 model             6.00 MB Dec  2 2009  6:58PM  13316      0
 sybsystemdb       6.00 MB Dec  2 2009  6:58PM  19460      0
(1 row affected)
(return status = 0)
1> select * from sysdevices where name='master'
2> go
 low         high        status cntrltype name                           phyname                                                                                                                         mirrorname                                                                                                                      vdevno      crdate                     resizedate                 status2
 ----------- ----------- ------ --------- ------------------------------ ------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------- ----------- -------------------------- -------------------------- -----------
           0       40959   2275         0 master                         D:\sybase\data\master.dat                                                                                                       D:\sybase\data\master_mirr.dat                                                                                                            0        Dec  2 2009  6:58PM        Mar 27 2010  4:32PM           0
(1 row affected)
1>
 

sp_helpdevice显示master设备已被MIRROR DISABLED。 sysdevices系统表中master对应的status列为:2275 = 2048 + 128 + 64 + 32 + 2 + 1 。状态为2048表示镜像已禁用(内部使用)。


三、重新激活镜像

语法:disk remirror name="logical_device_name"

在设备的镜像功能因为用户或者系统的缘故而被中止时,可以利用此命令恢复设备上的镜像功能。发出该命令后,ASE服务器会将镜像主设备上的数据拷贝到镜像次设备上面去。

恢复本文上面暂时取消的master上的镜像。

1> disk remirror
2> name='master'
3> go
Starting Dynamic Mirroring of 20480 pages for logical device 'master'.
         512 pages mirrored...
        1024 pages mirrored...
        1536 pages mirrored...
        2048 pages mirrored...
        2560 pages mirrored...
        3072 pages mirrored...
        3584 pages mirrored...
        4096 pages mirrored...
        4608 pages mirrored...
        5120 pages mirrored...
        5632 pages mirrored...
        6144 pages mirrored...
        6656 pages mirrored...
        7168 pages mirrored...
        7680 pages mirrored...
        8192 pages mirrored...
        8704 pages mirrored...
        9216 pages mirrored...
        9728 pages mirrored...
The remaining 10752 pages are currently unallocated and will be mirrored as they are allocated.
1>
 

在errorlog文件中有下面的日志内容:00:00000:00030:2010/06/07 13:31:03.26 kernel  mirror for virtual device 0 started using asynchronous (with DIRECTIO) I/O

再次查看status状态信息,

1> select name,status,phyname,mirrorname from sysdevices where name='master'
2> go
 name                           status phyname                                                                                                                         mirrorname
 ------------------------------ ------ ------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------
 master                            739 D:\sybase\data\master.dat                                                                                                       D:\sybase\data\master_mirr.dat
(1 row affected)

 

可以看到重新恢复镜像后,master设备的status状态信息和刚开始添加镜像时相同。个人感觉重新激活镜像(remirror)和新添加镜像 已经是一样的。只是不用告诉系统镜像到什么位置了而已;还有初次镜像的时候secondary设备文件必须不存在而激活镜像则相反。

 

四、利用镜像功能来移动设备的物理位置

可以利用镜像功能将数据库设备移动到其它物理位置。比如设备A原来在C盘,要是将其移动到D盘。 需要两个步骤:

1.将设备A镜像到D盘的设备文件上;

2.取消设备A在C盘的主镜像文件。

下面演示将tempdb的设备文件由D:\sybase\data\tempdbdev.dat移动到D:\syb_data\tempdbdev.dat

1> disk mirror
2> name='tempdbdev',
3> mirror='d:\syb_data\tempdbdev.dat'
4> go
Creating the physical file for the mirror...
Starting Dynamic Mirroring of 51200 pages for logical device 'tempdbdev'.
         512 pages mirrored...
        1024 pages mirrored...
        1536 pages mirrored...
        2048 pages mirrored...
        2560 pages mirrored...
        3072 pages mirrored...
        3584 pages mirrored...
        4096 pages mirrored...
        4608 pages mirrored...
        5120 pages mirrored...
        5632 pages mirrored...
        6144 pages mirrored...
        6656 pages mirrored...
        7168 pages mirrored...
        7680 pages mirrored...
        8192 pages mirrored...
        8704 pages mirrored...
        9216 pages mirrored...
        9728 pages mirrored...
       10240 pages mirrored...
       10752 pages mirrored...
       11264 pages mirrored...
       11776 pages mirrored...
       12288 pages mirrored...
       12800 pages mirrored...
       13312 pages mirrored...
       13824 pages mirrored...
       14336 pages mirrored...
       14848 pages mirrored...
       15360 pages mirrored...
       15872 pages mirrored...
       16384 pages mirrored...
       16896 pages mirrored...
       17408 pages mirrored...
       17920 pages mirrored...
       18432 pages mirrored...
       18944 pages mirrored...
       19456 pages mirrored...
       19968 pages mirrored...
       20480 pages mirrored...
       20992 pages mirrored...
       21504 pages mirrored...
       22016 pages mirrored...
       22528 pages mirrored...
       23040 pages mirrored...
       23552 pages mirrored...
       24064 pages mirrored...
       24576 pages mirrored...
       25088 pages mirrored...
       25600 pages mirrored...
       26112 pages mirrored...
       26624 pages mirrored...
       27136 pages mirrored...
       27648 pages mirrored...
       28160 pages mirrored...
       28672 pages mirrored...
       29184 pages mirrored...
       29696 pages mirrored...
       30208 pages mirrored...
       30720 pages mirrored...
       31232 pages mirrored...
       31744 pages mirrored...
       32256 pages mirrored...
       32768 pages mirrored...
       33280 pages mirrored...
       33792 pages mirrored...
       34304 pages mirrored...
       34816 pages mirrored...
       35328 pages mirrored...
       35840 pages mirrored...
       36352 pages mirrored...
       36864 pages mirrored...
       37376 pages mirrored...
       37888 pages mirrored...
       38400 pages mirrored...
       38912 pages mirrored...
       39424 pages mirrored...
       39936 pages mirrored...
       40448 pages mirrored...
       40960 pages mirrored...
       41472 pages mirrored...
       41984 pages mirrored...
       42496 pages mirrored...
       43008 pages mirrored...
       43520 pages mirrored...
       44032 pages mirrored...
       44544 pages mirrored...
       45056 pages mirrored...
       45568 pages mirrored...
       46080 pages mirrored...
       46592 pages mirrored...
       47104 pages mirrored...
       47616 pages mirrored...
       48128 pages mirrored...
       48640 pages mirrored...
       49152 pages mirrored...
       49664 pages mirrored...
       50176 pages mirrored...
       50688 pages mirrored...
       51200 pages mirrored...
1> disk unmirror
2> name='tempdbdev',
3> side='primary',
4> mode=remove
5> go
1> sp_helpdevice tempdbdev
2> go
 device_name physical_name             description                                                                                  status cntrltype vdevno vpn_low vpn_high
 ----------- ------------------------- -------------------------------------------------------------------------------------------- ------ --------- ------ ------- --------
 tempdbdev   d:\syb_data\tempdbdev.dat file system device, special, dsync on, directio off, physical disk, 200.00 MB, Free: 0.00 MB  16386         0      2       0   102399
(1 row affected)
 dbname size          allocated           vstart lstart
 ------ ------------- ------------------- ------ ------
 tempdb     100.00 MB Dec  2 2009  7:01PM      0      0
 tempdb      50.00 MB Dec  8 2009 11:16AM  51200  25600
 tempdb      50.00 MB Dec  8 2009 11:16AM  76800  38400
(1 row affected)
(return status = 0)
1> select name,status,phyname,mirrorname from sysdevices where name='tempdbdev'
2> go
 name                           status phyname                                                                                                                         mirrorname
 ------------------------------ ------ ------------------------------------------------------------------------------------------------------------------------------- -------------
 tempdbdev                       16386 d:\syb_data\tempdbdev.dat                                                                                                       NULL
(1 row affected)
1>
 

对应于errorlog中的信息为: 00:00000:00030:2010/06/07 13:45:33.34 kernel  mirror for virtual device 2 started using asynchronous I/O
00:00000:00030:2010/06/07 13:46:56.00 kernel  Closing the primary device for virtual device tempdbdev
00:00000:00030:2010/06/07 13:46:56.00 kernel  The new primary device is now d:\syb_data\tempdbdev.dat

其中status:16386 = 16384 + 2 这是一个普通的物理设备文件。

 

五、对master设备进行镜像的另外一种方法

对master设备镜像还有一种方法,就是直接利用命令参数。 windows下sqlsrvr.exe的参数中有个是: -r mirror_file          - master device's mirror device name

可以修改RUN_SEVERNAME文件来加入-r这个参数来镜像master设备。

如改为:

D:\sybase\ASE-15_0\bin\sqlsrvr.exe  -dD:\sybase\data\master.dat -sTEST -eD:\sybase\ASE-15_0\install\TEST.log -iD:\sybase\ini -MD:\sybase\ASE-15_0 -rd:\syb_data\master_mirr.dat

 

在windows下的ASE还需要修改注册表中的配置信息, 才能用系统工具中的服务正常启动数据。 不过你要是习惯每次都用RUN_SERVERNAME这个命令行来启动数据库的话, 也不用改注册表了。至于如何改注册表, 本篇暂时不介绍。

好了,关于ASE中的mirror就介绍这么多吧。

 

————————————————————————————————-
—- 本文为andkylee个人原创,请在尊重作者劳动成果的前提下进行转载;
—- 转载务必注明原始出处 : http://www.dbainfo.net
—- 关键字:mirror unmirror remirror 镜像  移动设备
————————————————————————————————-