In this article,you'll be do following things on Sybase ASE:
■ Initializing Database Devices
■ Designating default devices
■ Mirrorring Database Devices
■ Creating And Dropping Database
■ Setting Database Options
For more information about following command help from here.
Initializing Database Devices
Using disk init command to initialize new database devices.Here,ijust show you initializing a file in the file system as the database device.Next artile,you should be learn how to initialize any piece of a disk (such as a disk partition).I'm going to create three devices: dev01,dev02 and dev_log by following command:
- [sybase@server ~]$ isql -Usa -p -SSERVER -w512
- Password:
- 1> use master
- 2> go
- 1> disk init name='dev01',physname='/u02/sydata/dev01.dat',vdevno=5,size='50M'
- 2> go
- 1> disk init name='dev02',physname='/u02/sydata/dev02.dat',vdevno=6,size='50M'
- 2> go
- 1> disk init name='dev_log',physname='/u02/sydata/devlog.dat',vdevno=7,size='100M'
- 2> go
You can use following SQL to list currently used identifier:
- 1> select name,vdevno from master..sysdevices where status&2=2
- 2> go
- name vdevno
- ------------------------------------------------------------ -----------
- master 0
- sysprocsdev 1
- systemdbdev 2
- tempdbdev 3
- sybmgmtdev 4
Deleting a device:
- 1> use master
- 2> go
- 1> sp_dropdevice dev02
- 2> go
- Device dropped.
Designating default devices
By default,master as the system default device on Sybase ASE.The system has two way to list default system disk: SQL or sp_helpdevice command.
1.Using SQL to list currently system default disk:
- 1> select name from sysdevices where status&1=1 order by name
- 2> go
- name
- ------------------------------------------------------------
- master
- (1 row affected)
2.Using sp_helpdevice command:
If you see ‘default disk’in description,then the device as the system default disk.
- 1> sp_helpdevice master
- 2> go
- device_name physical_name description status cntrltype vdevno ***_low ***_high
- ---------------------- -------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------ ------------------ ------------ -------------- ----------------
- master /u02/sydata/master.dat file system device, special, dsync on, directio off, default disk, physical disk, 73.00 MB, Free: 16.00 MB 3 0 0 0 37375
- (1 row affected)
- dbname size allocated vstart lstart
- ---------------------- -------------------------- -------------------------------------- ------------ ------------
- master 26.00 MB Aug 17 2012 7:31PM 4 0
- model 6.00 MB Aug 17 2012 7:31PM 13316 0
- tempdb 6.00 MB Aug 17 2012 7:31PM 16388 0
- sybsystemdb 6.00 MB Aug 17 2012 7:31PM 19460 0
- pubs2 7.00 MB Aug 17 2012 7:33PM 22532 0
- pubs3 6.00 MB Aug 17 2012 7:34PM 26116 0
- (1 row affected)
- (return status = 0)
3.Setting the system default disk:
Now,i'm going to set the dev01 as the system default disk and unset the master as the system default disk.
- 1> sp_diskdefault master,defaultoff
- 2> go
- 1> sp_diskdefault dev01,defaulton
- 2> go
- 1> sp_helpdevice master
- 2> go
- device_name physical_name description status cntrltype vdevno ***_low ***_high
- ---------------------- -------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------ ------------------ ------------ -------------- ----------------
- master /u02/sydata/master.dat file system device, special, dsync on, directio off, physical disk, 73.00 MB, Free: 16.00 MB 2 0 0 0 37375
- (1 row affected)
- dbname size allocated vstart lstart
- ---------------------- -------------------------- -------------------------------------- ------------ ------------
- master 26.00 MB Aug 17 2012 7:31PM 4 0
- model 6.00 MB Aug 17 2012 7:31PM 13316 0
- tempdb 6.00 MB Aug 17 2012 7:31PM 16388 0
- sybsystemdb 6.00 MB Aug 17 2012 7:31PM 19460 0
- pubs2 7.00 MB Aug 17 2012 7:33PM 22532 0
- pubs3 6.00 MB Aug 17 2012 7:34PM 26116 0
- (1 row affected)
- (return status = 0)
- 1> sp_helpdevice dev01
- 2> go
- device_name physical_name description status cntrltype vdevno ***_low ***_high
- ---------------------- ------------------------------------------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------ ------------------ ------------ -------------- ----------------
- dev01 /u02/sydata/dev01.dat file system device, special, dsync off, directio on, default disk, physical disk, 50.00 MB, Free: 50.00 MB 3 0 5 0 25599
- (1 row affected)
- dbname size allocated vstart lstart
- ------------ -------- ------------------ ------------ ------------
- (1 row affected)
The SQL output:
- 1> select name from sysdevices where status&11=1 order by name
- 2> go
- name
- ------------------------------------------------------------
- dev01
Mirrorring Database Devices
The ASE system does't enable disk mirror feature by default.If you want to use this feature,you must manually enable it.
1.Check the status of the disk mirror feature:
- 1> sp_configure 'disable disk mirror'
- 2> go
- Parameter Name Default Memory Used Config Value Run Value Unit Type
- ------------------------------------------------------------ ---------------------------------------- ---------------------- ---------------------------------------- ---------------------------------------- ---------------------------------------- ----------------------------------------
- disable disk mirroring 1 0 1 1 switch static
2.Enable this feature:
- 1> sp_configure 'disable disk mirror',0
- 2> go
- Parameter Name Default Memory Used Config Value Run Value Unit Type
- ------------------------------------------------------------ ---------------------------------------- ---------------------- ---------------------------------------- ---------------------------------------- ---------------------------------------- ----------------------------------------
- disable disk mirroring 1 0 0 1 switch static
3.Check the status again:
- 1> sp_configure 'disable disk mirror'
- 2> go
- Parameter Name Default Memory Used Config Value Run Value Unit Type
- ------------------------------------------------------------ ---------------------------------------- ---------------------- ---------------------------------------- ---------------------------------------- ---------------------------------------- ----------------------------------------
- disable disk mirroring 1 0 0 0 switch static
4.Mirroring devices:
Master is the major device for Sybase ASE.If it broken,you can't restore system.Another way,you must mirror major devices,such as:user databases,log devices and so on.
(1).Mirroring master device:
- 1> use master
- 2> go
- 1> disk mirror name='master', mirror='/u02/sydata/master_stby.dat',writes = 'serial'
- 2> go
- Creating the physical file for the mirror...
- 00:0002:00000:00026:2012/08/19 15:26:12.05 kernel mirror for virtual device 0 started using asynchronous (with DIRECTIO) I/O
- Starting Dynamic Mirroring of 18688 pages for logical device 'master'.
- 512 pages mirrored.…
- …………………
- 14336 pages mirrored...
- 14592 pages mirrored...
- The remaining 4096 pages are currently unallocated and will be mirrored as they are allocated.
Check the information of master:
- 1> sp_helpdevice master
- 2> go
- device_name physical_name description status cntrltype vdevno ***_low ***_high
- ---------------------- -------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------ ------------------ ------------ -------------- ----------------
- master /u02/sydata/master.dat file system device, special, MIRROR ENABLED, mirror = '/u02/sydata/master_stby.dat', serial writes, dsync on, directio off, reads mirrored, physical disk, 73.00 MB, Free: 16.00 MB 738 0 0 0 37375
- (1 row affected)
- dbname size allocated vstart lstart
- ---------------------- -------------------------- -------------------------------------- ------------ ------------
- master 26.00 MB Aug 17 2012 7:31PM 4 0
- model 6.00 MB Aug 17 2012 7:31PM 13316 0
- tempdb 6.00 MB Aug 17 2012 7:31PM 16388 0
- sybsystemdb 6.00 MB Aug 17 2012 7:31PM 19460 0
- pubs2 7.00 MB Aug 17 2012 7:33PM 22532 0
- pubs3 6.00 MB Aug 17 2012 7:34PM 26116 0
- (1 row affected)
(2).Mirroring other devices:
- 1> disk mirror name='dev01',mirror='/u02/sydata/dev01_stby.dat',writes='serial'
- 2> go
- 00:0002:00000:00026:2012/08/19 15:30:30.06 kernel mirror for virtual device 5 started using asynchronous (with DIRECTIO) I/O
- Creating the physical file for the mirror...
- Starting Dynamic Mirroring of 12800 pages for logical device 'dev01'.
- The remaining 12800 pages are currently unallocated and will be mirrored as they are allocated.
- 1> disk mirror name='dev_log',mirror='/u02/sydata/devlog_stby.dat',writes='serial'
- 2> go
- 00:0002:00000:00026:2012/08/19 15:31:15.37 kernel mirror for virtual device 7 started using asynchronous (with DIRECTIO) I/O
- Creating the physical file for the mirror...
- Starting Dynamic Mirroring of 25600 pages for logical device 'dev_log'.
- The remaining 25600 pages are currently unallocated and will be mirrored as they are allocated.
3).List all of mirror devices :
There are two way to list all of mirror devices:SQL or sp_helpdevice command.Following feature only show you the SQL output.
(4).Unmirror a device:
The mode option changes the status column in sysdevices to indicate that mirroring has been disabled.Its effects on the phyname and mirrorname columns in sysdevices depend on the side argument also, as shown in following Table.
If you unmirror a device in remove mode,you can't remirror it again.
- 1> disk unmirror name='dev03',mode='remove'
- 2> go
- 00:0002:00000:00026:2012/08/19 15:52:48.07 kernel Closing the secondary device for virtual device dev03
- 1> disk remirror name='dev03'
- 2> go
- Msg 5131, Level 16, State 2:
- Server 'SERVER', Line 1:
- The device 'dev03' is not currently mirrored.
But,if you unmirror a device in retain mode,you can remirror it again.The retain mode as the system default effect.
- 1> disk mirror name='dev03',mirror='/u02/sydata/dev03_stby.dat',writes='serial'
- 2> go
- 1> disk unmirror name='dev03',mode='retain'
- 2> go
- 1> disk remirror name='dev03'
- 2> go
Creating And Dropping Database
Following table show you Commands for managing user databases:
1.Creating databases:
Here i'm going to create two user database db01 on dev01 and db02 on dev02,the log device on dev_log.
- 1> create database db01 on dev01 log on dev_log
- 2> go
- 1> create database db02 on dev02 log on dev_log
- 2> go
2.Getting information about database or database storage:
You can use following SQL to get information or use sp_helpdb command.
List database information by SQL:
List database storage information:
3.Altering databases:
If a database does'n have enough space,you must add more devices,you can use alter command to do this.
- 1> alter database db02 on dev03
- 2> go
- 1> sp_helpdb db02
- 2> go
- name db_size owner dbid created durability lobcomplvl inrowlen status
- -------- -------------------------- ---------- -------- ------------------------ -------------------- -------------------- ---------------- ----------------------------
- db02 13.0 MB sa 7 Aug 19, 2012 full 0 NULL no options set
- (1 row affected)
- device_fragments size usage created free kbytes
- ------------------------------------------------------------ -------------------------- ---------------------------------------- -------------------------------------------------- --------------------------------
- dev02 6.0 MB data only Aug 19 2012 4:11PM 2808
- dev_log 6.0 MB log only Aug 19 2012 4:11PM not applicable
- dev03 1.0 MB data only Aug 19 2012 4:55PM 1020
- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- log only free kbytes = 6092
4.Dropping databases:
- 1> drop database db01
- 2> go
- Execution Time (ms.): 389 Clock Time (ms.): 389
- 1> drop database db02
- 2> go
- Execution Time (ms.): 349 Clock Time (ms.): 349
Setting Database Options
Use sp_dboption to change settings for an entire database. You can change options only for user databases. You cannot change options for the master database. To change a database option in a user database (or to display a list of the database options), execute sp_dboption while using the master database.
1.View the options on a database:
- 1> sp_helpdb master
- 2> go
- name db_size owner dbid created durability lobcomplvl inrowlen status
- ------------ -------------------------- ---------- -------- ------------------------ -------------------- -------------------- ---------------- ------------------------------------
- master 26.0 MB sa 1 Aug 17, 2012 full 0 NULL mixed log and data
- (1 row affected)
- device_fragments size usage created free kbytes
- ------------------------------------------------------------ -------------------------- ---------------------------------------- -------------------------------------------------- --------------------------------
- master 26.0 MB data and log Aug 17 2012 7:31PM 11252
- device segment
- ------------ --------------------
- master default
- master logsegment
- master system
- (return status = 0)
- Execution Time (ms.): 61 Clock Time (ms.): 65
2.List all of available database options:
- 1> sp_dboption
- 2> go
- Settable database options.
- --------------------
- abort tran on log full
- allow nulls by default
- allow wide dol rows
- async log service
- auto identity
- dbo use only
- ddl in tran
- delayed commit
- enforce dump tran sequence
- full logging for all
- full logging for alter table
- full logging for reorg rebuild
- full logging for select into
- identity in nonunique index
- no chkpt on recovery
- no free space acctg
- read only
- select into/bulkcopy/pllsort
- single user
- trunc log on chkpt
- trunc. log on chkpt.
- unique auto_identity index
- (24 rows affected)
- (return status = 0)
- Execution Time (ms.): 103 Clock Time (ms.): 127
For more information about what's mean above each option,please view sybase ASE online documents.
3.Changing user database options:
- 1> sp_dboption db01,'single user',true
- 2> go
- 00:0002:00000:00026:2012/08/19 17:46:37.67 server Database 'db01' set to single user mode.
- Database option 'single user' turned ON for database 'db01'.
- Running CHECKPOINT on database 'db01' for option 'single user' to take effect.
- (return status = 0)
- Execution Time (ms.): 108 Clock Time (ms.): 108
- 1> use db01
- 2> go
- Execution Time (ms.): 1 Clock Time (ms.): 1
- 1> sp_helpdb db01
- 2> go
- name db_size owner dbid created durability lobcomplvl inrowlen status
- -------- -------------------------- ---------- -------- ------------------------ -------------------- -------------------- ---------------- ----------------------
- db01 12.0 MB sa 6 Aug 19, 2012 full 0 NULL single user
- (1 row affected)
- device_fragments size usage created free kbytes
- ------------------------------------------------------------ -------------------------- ---------------------------------------- -------------------------------------------------- --------------------------------
- dev01 6.0 MB data only Aug 19 2012 5:34PM 2808
- dev_log 6.0 MB log only Aug 19 2012 5:34PM not applicable
- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- log only free kbytes = 6092
- device segment
- -------------- --------------------
- dev01 default
- dev01 system
- dev_log logsegment
- (return status = 0)
- Execution Time (ms.): 95 Clock Time (ms.): 103