Sybase: Extending the transaction log

This will show you how to extend the transaction log on a user database by adding an additional log device. In many cases dumping the transaction log or increasing the size of the existing device would be better but in some occasions, I’ve needed this…

First you have to create a new device on the hard disk using “disk init”:

use master
disk init name = "log_2_dev", physname = "/db_data/devices/log_2_dev", size=204800

In this example, “log_2_dev” is the name of the new device in ASE. It will be created in the file “/db_data/devices/log_2_dev”. And its size will be 400 MB (204800 pages, 2KB each). Instead of specifying a size in 2K-blocks you can also write 400M to directly define a size in megabytes.

You can check whether the device has been properly created like this:


Then you need to assign this device to the transaction log of your database (assuming the name of the database is mydb):

use master
alter database mydb log on log_2_dev = '400M'

It tells Sybase to additionally use the new device for the transaction log (using 400 MB).

You can check with the following whether everything went fine:

sp_helpdb mydb

You should see two log devices e.g.:

1> sp_helpdb mydb
2> go
 name                     db_size       owner                    dbid
 ------------------------ ------------- ------------------------ ------
 mydb                         1797.0 MB sa                            4
         Jan 24, 2012
         select into/bulkcopy/pllsort

(1 row affected)
 device_fragments               size          usage
         created             free kbytes
 ------------------------------ ------------- --------------------
         ------------------- ----------------
 data_1_dev                          991.0 MB data only
         Jan 24 2012 11:33PM           809514
 log_1_dev                           109.0 MB log only
         Jan 24 2012 11:33PM not applicable
 index_1_dev                         297.0 MB data only
         Jan 24 2012 11:34PM           243404
log_2_dev                           400.0 MB log only
         Jan 25 2012  3:57AM not applicable

 log only free kbytes = 292174
(return status = 0)

After that you shouldn’t have problems anymore with the transaction log getting full too quickly.

If you need to remove the log device later on, please use the following:

use master
sp_dboption mydb, "single user", true
use mydb
sp_dropsegment 'logsegment','mydb','log_2_dev'
use master
sp_configure 'allow updates', 1
delete from sysusages where dbid=db_id('mydb') and vstart=(select low from sysdevices where name='log_2_dev')
sp_configure 'allow updates', 0
sp_dropdevice 'log_2_dev'
sp_dboption mydb, "single user", false

The sing user mode means that no other connection than the one you’re working with will be available. This ensures that no other activities are done in parallel.
Allow updates allows you to modify system tables manually.

One thought on “Sybase: Extending the transaction log

Leave a Reply

Your email address will not be published.