存档
1、准备环境
首先确保sql.ini中包含主、备服务器名称;
创建master设备所在的目录;
主服务器和备份服务器的RUN_file文件;
2、使用命令初始化master设备
D:\ASE\sybase157\ASE-15_0\bin\sqlsrvr.exe -dD:\ASE\sybase157\data2\master.dat -b100M -Z80M -z2048 -eD:\ASE\sybase157\ASE-15_0\install\ASE157_2K.log -sASE157_2K -MD:\ASE\sybase157\ASE-15_0
3、使用RUN_file启动新创建的服务
在windows创建的主服务的默认字符集为:cp850;
默认包含以下系统数据库:
1> select dbid,name from sysdatabases order by dbid
2> go
dbid name
------ ------------------------------
1 master
2 tempdb
3 model
31513 sybsystemdb
(4 rows affected)
4、创建sybsystemprocs数据库
sybase官方文档上关于设备的dsync,directio这两个属性也是语焉不详,可能不同版本不同平台的ASE这两个属性有不同的默认值。
下面是一位Sybase大牛的论述,很清晰明朗。
The use of dsync/directio (typically) means the dataserver has to wait for a write to complete on the physical disk
before the dataserver considers the write to be 'successful' (aka guaranteed write). While this *wait* will extend the
time it takes to complete the associated database action, the guaranteed write to disk is required to insure
recoverability (in the case of a dataserver/machine/disk subsystem failure).
If dsync/directio are disabled then a dataserver write may finish more quickly due to the disk subsystem *caching* the
write IO. This means the associated dataserver action completes more quickly but there's no guarantee the IO made it to
the physical disk. If the dataserver/machine/disk subsystem fails between the successful disk cache write and the
physical disk write, you could end up losing data (ie, the dataserver thinks the data is on disk while the disk has no
record of the data existing).
For important databases (eg, master, RSSDs, user databases), especially in production environments, the recoverability
of the data usually takes precedence over speed. In these scenarios the dataserver must wait for physical disk writes
to complete 'successfully', with the caveat that the associated database action takes longer to complete.
For trivial/development databases where recoverability is not a concern, or for databases that are rebuilt from scratch
at dataserver startup (eg, temporary databases), guaranteed disk writes are not as important. In these scenarios a
successful write to disk cache is sufficient, with the added benefit that the associated database action completes more
quickly.
So, generally speaking:
dsync/directio enabled : guaranteed disk writes, guaranteed recoverability, associated database actions take more time
to complete
dsync/directio disabled : no guarantee of writes to physical disks, no guarantee of recoverability, associated database
actions take less time to complete
------------------
Now-a-days there are lots of ways to configure disk subsystems ... raw disks, cached disks, cached file systems,
journaled file systems, multiple layers of logical disk management, sans (w/ and w/out cache), etc, etc, etc ...
Some of these configurations may support dsync/directio operations by the dataserver while actually performing the write
to cache, ie, the physical disk write takes place at a later time. For some systems this may be ok if the disk
subsystem vendor can guarantee that those cache writes will always make their way to disk.
The issue here is that regardless of which attribute settings (dsync/directio) are used for dataserver devices, it's the
DBA's responsibility to insure the disk subsystem can really guarantee disk writes for those database actions that
require guaranteed recoverability.
总结一下:文件系统将directio属性关闭。文件系统上临时数据库或者不太“重要”的数据库的设备可以将dsync调整成false,其余数据库为了保证恢复将dsync设置成true。
一、添加镜像
为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 镜像 移动设备
————————————————————————————————-
今天下午一直在研究master设备的内部数据结构,尝试通过编写程序向master设备文件后面追加数据来达到增加master设备大小的目的。
在sybase中初始化一块设备就是向操作系统中的文件系统请求一块空间,并且sybase对这块空间进行了一定的分配初始化。
要是能够手动向master设备文件尾部追加初始化的分配信息数据就可以物理上增加master设备的大小;然后,在 sysdatabases,sysdevices,sysusages表中修改相应的信息。
手动扩展master设备大小的示例:
原master设备大小为50MB,逻辑页号:0 - 25599(逻辑页面大小为2K)。
将master设备增加50MB空间,使得master设备空间变为100MB。
新的master设备逻辑页号: 0 - 51199。
1、修改master设备的high为51199,
update sysdevices set high=51200-1 where name='master'
go
2、给master设备文件尾部增加50MB空间
dd if=/dev/zero of=./master.dat bs=2048 seek=25600 count=25600
3、重启Sybase数据库服务器
4、验证master设备空间大小变为100MB
————————————————————————————————————
——— 本文为andkylee个人原创,请在尊重作者劳动成果的前提下进行转载;
——— 转载务必注明原始出处 : http://www.dbainfo.net
——— 关键字: ASE master 空间 扩展 手动
————————————————————————————————————