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:

   
   
   
   
  1. [sybase@server ~]$ isql -Usa -p -SSERVER -w512   
  2. Password:   
  3. 1> use master   
  4. 2> go   
  5. 1> disk init name='dev01',physname='/u02/sydata/dev01.dat',vdevno=5,size='50M'   
  6. 2> go   
  7. 1> disk init name='dev02',physname='/u02/sydata/dev02.dat',vdevno=6,size='50M'   
  8. 2> go   
  9. 1> disk init name='dev_log',physname='/u02/sydata/devlog.dat',vdevno=7,size='100M'   
  10. 2> go    

You can use following SQL to list currently used identifier:

   
   
   
   
  1. 1> select name,vdevno from master..sysdevices where status&2=2  
  2. 2> go  
  3. name                                                         vdevno       
  4. ------------------------------------------------------------ -----------  
  5. master                                                                 0  
  6. sysprocsdev                                                            1  
  7. systemdbdev                                                            2  
  8. tempdbdev                                                              3  
  9. sybmgmtdev                                                             4   

Deleting a device:

   
   
   
   
  1. 1> use master 
  2. 2> go 
  3. 1> sp_dropdevice dev02 
  4. 2> go 
  5. 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. 1> select name from sysdevices where status&1=1 order by name 
  2. 2> go 
  3.  name                                                          
  4.  ------------------------------------------------------------  
  5.  master                                                         
  6. (1 row affected) 

2.Using sp_helpdevice command:

If you see ‘default disk’in description,then the device as the system default disk.

   
   
   
   
  1. 1> sp_helpdevice master 
  2. 2> go 
  3.  device_name            physical_name                                description                                                                                                                                                                                                          status       cntrltype          vdevno       ***_low        ***_high          
  4.  ---------------------- -------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------ ------------------ ------------ -------------- ----------------  
  5.  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          
  6.  
  7. (1 row affected) 
  8.  dbname                 size                       allocated                              vstart       lstart        
  9.  ---------------------- -------------------------- -------------------------------------- ------------ ------------  
  10.  master                      26.00 MB              Aug 17 2012  7:31PM                         4            0        
  11.  model                        6.00 MB              Aug 17 2012  7:31PM                     13316            0        
  12.  tempdb                       6.00 MB              Aug 17 2012  7:31PM                     16388            0        
  13.  sybsystemdb                  6.00 MB              Aug 17 2012  7:31PM                     19460            0        
  14.  pubs2                        7.00 MB              Aug 17 2012  7:33PM                     22532            0        
  15.  pubs3                        6.00 MB              Aug 17 2012  7:34PM                     26116            0        
  16.  
  17. (1 row affected) 
  18. (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. 1> sp_diskdefault master,defaultoff 
  2. 2> go 
  3. 1> sp_diskdefault dev01,defaulton 
  4. 2> go 
  5. 1> sp_helpdevice master 
  6. 2> go 
  7.  device_name            physical_name                                description                                                                                                                                                                              status       cntrltype          vdevno       ***_low        ***_high          
  8.  ---------------------- -------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------ ------------------ ------------ -------------- ----------------  
  9.  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          
  10.  
  11. (1 row affected) 
  12.  dbname                 size                       allocated                              vstart       lstart        
  13.  ---------------------- -------------------------- -------------------------------------- ------------ ------------  
  14.  master                      26.00 MB              Aug 17 2012  7:31PM                         4            0        
  15.  model                        6.00 MB              Aug 17 2012  7:31PM                     13316            0        
  16.  tempdb                       6.00 MB              Aug 17 2012  7:31PM                     16388            0        
  17.  sybsystemdb                  6.00 MB              Aug 17 2012  7:31PM                     19460            0        
  18.  pubs2                        7.00 MB              Aug 17 2012  7:33PM                     22532            0        
  19.  pubs3                        6.00 MB              Aug 17 2012  7:34PM                     26116            0        
  20. (1 row affected) 
  21. (return status = 0
  22. 1> sp_helpdevice dev01 
  23. 2> go 
  24.  device_name            physical_name                              description                                                                                                                                                                                                          status       cntrltype          vdevno       ***_low        ***_high          
  25.  ---------------------- ------------------------------------------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------ ------------------ ------------ -------------- ----------------  
  26.  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          
  27. (1 row affected) 
  28.  dbname       size     allocated          vstart       lstart        
  29.  ------------ -------- ------------------ ------------ ------------  
  30. (1 row affected) 

The SQL output:

   
   
   
   
  1. 1> select name from sysdevices where status&11=1 order by name 
  2. 2> go 
  3.  name                                                          
  4.  ------------------------------------------------------------  
  5.  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. 1> sp_configure 'disable disk mirror' 
  2. 2> go 
  3.  Parameter Name                                               Default                                  Memory Used            Config Value                             Run Value                                Unit                                     Type                                      
  4.  ------------------------------------------------------------ ---------------------------------------- ---------------------- ---------------------------------------- ---------------------------------------- ---------------------------------------- ----------------------------------------  
  5.  disable disk mirroring                                                 1                                        0                       1                                        1                             switch                                   static                                    

2.Enable this feature:

   
   
   
   
  1. 1> sp_configure 'disable disk mirror',0 
  2. 2> go 
  3.  Parameter Name                                               Default                                  Memory Used            Config Value                             Run Value                                Unit                                     Type                                      
  4.  ------------------------------------------------------------ ---------------------------------------- ---------------------- ---------------------------------------- ---------------------------------------- ---------------------------------------- ----------------------------------------  
  5.  disable disk mirroring                                                 1                                        0                       0                                        1                             switch                                   static                                    

3.Check the status again:

   
   
   
   
  1. 1> sp_configure 'disable disk mirror' 
  2. 2> go 
  3.  Parameter Name                                               Default                                  Memory Used            Config Value                             Run Value                                Unit                                     Type                                      
  4.  ------------------------------------------------------------ ---------------------------------------- ---------------------- ---------------------------------------- ---------------------------------------- ---------------------------------------- ----------------------------------------  
  5.  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. 1> use master 
  2. 2> go 
  3. 1> disk mirror name='master'mirror='/u02/sydata/master_stby.dat',writes = 'serial' 
  4. 2> go 
  5. Creating the physical file for the mirror... 
  6. 00:0002:00000:00026:2012/08/19 15:26:12.05 kernel  mirror for virtual device 0 started using asynchronous (with DIRECTIO) I/O 
  7. Starting Dynamic Mirroring of 18688 pages for logical device 'master'. 
  8.        512 pages mirrored.… 
  9.  
  10.        ………………… 
  11.  
  12.        14336 pages mirrored... 
  13.        14592 pages mirrored... 
  14. The remaining 4096 pages are currently unallocated and will be mirrored as they are allocated. 

Check the information of master:

   
   
   
   
  1. 1> sp_helpdevice master 
  2. 2> go 
  3.  device_name            physical_name                                description                                                                                                                                                                                                                                                                                                                                                            status       cntrltype          vdevno       ***_low        ***_high          
  4.  ---------------------- -------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------ ------------------ ------------ -------------- ----------------  
  5.  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          
  6.  
  7. (1 row affected) 
  8.  dbname                 size                       allocated                              vstart       lstart        
  9.  ---------------------- -------------------------- -------------------------------------- ------------ ------------  
  10.  master                      26.00 MB              Aug 17 2012  7:31PM                         4            0        
  11.  model                        6.00 MB              Aug 17 2012  7:31PM                     13316            0        
  12.  tempdb                       6.00 MB              Aug 17 2012  7:31PM                     16388            0        
  13.  sybsystemdb                  6.00 MB              Aug 17 2012  7:31PM                     19460            0        
  14.  pubs2                        7.00 MB              Aug 17 2012  7:33PM                     22532            0        
  15.  pubs3                        6.00 MB              Aug 17 2012  7:34PM                     26116            0        
  16. (1 row affected) 

(2).Mirroring other devices:

   
   
   
   
  1. 1> disk mirror name='dev01',mirror='/u02/sydata/dev01_stby.dat',writes='serial' 
  2. 2> go 
  3. 00:0002:00000:00026:2012/08/19 15:30:30.06 kernel  mirror for virtual device 5 started using asynchronous (with DIRECTIO) I/O 
  4. Creating the physical file for the mirror... 
  5. Starting Dynamic Mirroring of 12800 pages for logical device 'dev01'. 
  6. The remaining 12800 pages are currently unallocated and will be mirrored as they are allocated. 
  7. 1> disk mirror name='dev_log',mirror='/u02/sydata/devlog_stby.dat',writes='serial' 
  8. 2> go 
  9. 00:0002:00000:00026:2012/08/19 15:31:15.37 kernel  mirror for virtual device 7 started using asynchronous (with DIRECTIO) I/O 
  10. Creating the physical file for the mirror... 
  11. Starting Dynamic Mirroring of 25600 pages for logical device 'dev_log'. 
  12. 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.

Sybase ASE Database Devices Administrator Guide (一)_第1张图片

(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.Sybase ASE Database Devices Administrator Guide (一)_第2张图片

If you unmirror a device in remove mode,you can't remirror it again.

   
   
   
   
  1. 1> disk unmirror name='dev03',mode='remove' 
  2. 2> go 
  3. 00:0002:00000:00026:2012/08/19 15:52:48.07 kernel  Closing the secondary device for virtual device dev03 
  4. 1> disk remirror name='dev03' 
  5. 2> go 
  6. Msg 5131, Level 16, State 2: 
  7. Server 'SERVER', Line 1: 
  8. 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. 1> disk mirror name='dev03',mirror='/u02/sydata/dev03_stby.dat',writes='serial' 
  2. 2> go 
  3. 1> disk unmirror name='dev03',mode='retain' 
  4. 2> go  
  5. 1> disk remirror name='dev03' 
  6. 2> go 

Creating And Dropping Database

Following table show you Commands for managing user databases:Sybase ASE Database Devices Administrator Guide (一)_第3张图片

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. 1> create database db01 on dev01 log on dev_log 
  2. 2> go 
  3. 1> create database db02 on dev02 log on dev_log 
  4. 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:

Sybase ASE Database Devices Administrator Guide (一)_第4张图片

List database storage information:

Sybase ASE Database Devices Administrator Guide (一)_第5张图片

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. 1> alter database db02 on dev03 
  2. 2> go 
  3. 1> sp_helpdb db02 
  4. 2> go 
  5.  name     db_size                    owner      dbid     created                  durability           lobcomplvl           inrowlen         status                        
  6.  -------- -------------------------- ---------- -------- ------------------------ -------------------- -------------------- ---------------- ----------------------------  
  7.  db02           13.0 MB              sa            7     Aug 19, 2012             full                          0               NULL         no options set                
  8.  
  9. (1 row affected) 
  10.  device_fragments                                             size                       usage                                    created                                            free kbytes                       
  11.  ------------------------------------------------------------ -------------------------- ---------------------------------------- -------------------------------------------------- --------------------------------  
  12.  dev02                                                               6.0 MB              data only                                Aug 19 2012  4:11PM                                            2808                  
  13.  dev_log                                                             6.0 MB              log only                                 Aug 19 2012  4:11PM                                not applicable                    
  14.  dev03                                                               1.0 MB              data only                                Aug 19 2012  4:55PM                                            1020                  
  15.                                                                                                                                                                                                                                
  16.  ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  
  17.  log only free kbytes = 6092                                                                                                                                                                                                    

4.Dropping databases:

   
   
   
   
  1. 1> drop database db01 
  2. 2> go 
  3. Execution Time (ms.):    389        Clock Time (ms.):    389 
  4. 1> drop database db02 
  5. 2> go 
  6. 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. 1> sp_helpdb master 
  2. 2> go 
  3.  name         db_size                    owner      dbid     created                  durability           lobcomplvl           inrowlen         status                                
  4.  ------------ -------------------------- ---------- -------- ------------------------ -------------------- -------------------- ---------------- ------------------------------------  
  5.  master             26.0 MB              sa            1     Aug 17, 2012             full                          0               NULL         mixed log and data                    
  6.  
  7. (1 row affected) 
  8.  device_fragments                                             size                       usage                                    created                                            free kbytes                       
  9.  ------------------------------------------------------------ -------------------------- ---------------------------------------- -------------------------------------------------- --------------------------------  
  10.  master                                                             26.0 MB              data and log                             Aug 17 2012  7:31PM                                           11252                  
  11.  device       segment               
  12.  ------------ --------------------  
  13.  master       default               
  14.  master       logsegment            
  15.  master       system                
  16. (return status = 0
  17. Execution Time (ms.):     61        Clock Time (ms.):     65 

2.List all of available database options:

   
   
   
   
  1. 1> sp_dboption 
  2. 2> go 
  3. Settable database options.  
  4. --------------------  
  5. abort tran on log full 
  6. allow nulls by default 
  7. allow wide dol rows 
  8. async log service 
  9. auto identity 
  10. dbo use only 
  11. ddl in tran 
  12. delayed commit 
  13. enforce dump tran sequence 
  14. full logging for all 
  15. full logging for alter table 
  16. full logging for reorg rebuild 
  17. full logging for select into 
  18. identity in nonunique index 
  19. no chkpt on recovery 
  20. no free space acctg 
  21. read only 
  22. select into/bulkcopy/pllsort 
  23. single user 
  24. trunc log on chkpt 
  25. trunc. log on chkpt. 
  26. unique auto_identity index 
  27. (24 rows affected) 
  28. (return status = 0
  29. 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. 1> sp_dboption db01,'single user',true 
  2. 2> go 
  3. 00:0002:00000:00026:2012/08/19 17:46:37.67 server  Database 'db01' set to single user mode. 
  4. Database option 'single user' turned ON for database 'db01'. 
  5. Running CHECKPOINT on database 'db01' for option 'single user' to take effect. 
  6. (return status = 0
  7. Execution Time (ms.):    108        Clock Time (ms.):    108 
  8. 1> use db01 
  9. 2> go 
  10. Execution Time (ms.):      1        Clock Time (ms.):      1 
  11. 1> sp_helpdb db01 
  12. 2> go 
  13.  name     db_size                    owner      dbid     created                  durability           lobcomplvl           inrowlen         status                  
  14.  -------- -------------------------- ---------- -------- ------------------------ -------------------- -------------------- ---------------- ----------------------  
  15.  db01           12.0 MB              sa            6     Aug 19, 2012             full                          0               NULL         single user             
  16.  
  17. (1 row affected) 
  18.  device_fragments                                             size                       usage                                    created                                            free kbytes                       
  19.  ------------------------------------------------------------ -------------------------- ---------------------------------------- -------------------------------------------------- --------------------------------  
  20.  dev01                                                               6.0 MB              data only                                Aug 19 2012  5:34PM                                            2808                  
  21.  dev_log                                                             6.0 MB              log only                                 Aug 19 2012  5:34PM                                not applicable                    
  22.                                                                                                                                                                                                                                
  23.  ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  
  24.  log only free kbytes = 6092                                                                                                                                                                                                   
  25.  device         segment               
  26.  -------------- --------------------  
  27.  dev01          default               
  28.  dev01          system                
  29.  dev_log        logsegment            
  30. (return status = 0
  31. Execution Time (ms.):     95        Clock Time (ms.):    103