ASE 12.5 and Later

Use this procedure when the current master device is usable, but you are unable to use the server because of master database corruption. These steps enable you to create a new master database and reload it from backup.

NoteUse this procedure only for ASE version 12.5.x and higher. The examples shown here apply to unix platforms; for equivalent Windows commands, see your platform’s Utility Guide and operating system manual as appropriate.


Step 1. Create a New master Database

The approach to creating the new master database depends on the extent and nature of the corruption. Three different scenarios are possible:

If you are unsure of the scope of corruption, start with the “Basic Recreation” steps below; use the instructions for the other scenarios only if necessary.

Basic Recreation of master Database

This command instructs the server to read the device’s configuration area to obtain page size and device size and determine where to place the master database:

 % dataserver -d <device_name> -w master

The server creates a master of the same size, and in the same locations on disk, as the database it is replacing. It will not have the old database’s data! Instead, it contains a default set of data that you will replace later using load database. The default data includes information about any databases existing on the master device, but no other devices. It also has minimal system information, including a login for sa with a null password.

This process produces a large number of messages tracking the progress of database creation which are helpful in troubleshooting any problems. They are "upgrade" messages because the server creates a new master database by "upgrading" the device.

NoteIf the configuration area is corrupt or unavailable, this command returns the message: "The configuration area in device ’xxx’ appears to be corrupt. The server needs this data to boot, and so cannot continue." If this occurs, continue with the instructions below.

Recreation with a corrupt configuration area

The "Basic Recreation" process above may fail if the device’s configuration area has become corrupt. If so, you must supply sizing information. You will need two parameters: the page size (you need to know what this was), and the device size, which you can determine directly from the device:

% ls -l $SYBASE/d_master.dat

Divide the size shown by the page size (2048, say) to obtain the number of server pages, by 1024 to obtain KB, or by 1048576 to obtain MB.

Provide this information on the command line as follows:

% $SYBASE/bin/dataserver -d $SYBASE/d_master.dat -w master
-z page_size  -b device_size

For example, if your page size is 2K and the device size is 51204 server pages (100 MB, plus 8K space for the configuration area), the command looks like this:

 % $SYBASE/bin/dataserver -d $SYBASE/d_master.dat -w master 
-z 2k -b 51204

You may also specify the device size as Kb, Mb, or Gb; for example,-b 100M.

Recreation when master database allocation pages are corrupted

If the above procedures for recreating the master database fail, the database’s allocation pages are corrupt. (This may happen, for instance, if the database device was inadvertently written over by a completely different file.)

In this case, you can force the server to allocate all corrupted or unallocated extents to the master database:

 % $SYBASE/bin/dataserver -d $SYBASE/d_master.dat -w master -f

This allocates all corrupted or otherwise unrecognizable extents to the master database. Depending on the extent of your master device corruption, and how much free space it originally had, this will probably leave master much larger than it needs to be, causing it to occupy space that used to belong to other databases like model, tempdb, and sybsystemdb. We will consider recovering from that situation later.

NoteYou may combine the -f, -b, and -z options as necessary.

The server shuts down after recreating the master database.


Step 2: Account for Missing Databases (if you used -f)

NoteThis step is only needed if you used the -f option in Step 1 to recreate the master database due to allocation page corruption. If you did not use -f, skip this step.

Recall that the -f command line option could make the new master larger than needed at the expense of other required databases on the master device. You will need to check for these databases before proceeding. This step has many possible permutations, so you must know what databases should be on the master device to perform this step. For example, if you had moved tempdb to a different device, you will not need tempdb on the master device. If upgrading, you may well have created sybsystemdb on a device other than master; if so, you will not need to account for sybsystemdb.

Start Adaptive Server in single-user mode. Refer to How to Start Adaptive Server in Single-User Mode.

Log in as sa, and check the databases currently on the master device:

1> select name from sysdatabases
2> go

Do you see all the databases that should be on the master device? If so, skip the rest of this step. Otherwise, you will need to determine which databases are missing and how big they should be, then obtain the free space needed to recreate these databases.

The following isql script obtains the required space by removing it from the end of the master database. In order, it

You will need to provide the required space value, denoted as @needed_mb.

NoteThis sample script is provided to assist you with the disaster recovery task. It is not officially supported by Sybase.

1> declare @needed_mb int, @needed_pages int, @master_end int,
2>      @pgspermb int
3> select @pgspermb = (1048576 / @@maxpagesize)
4> select @needed_mb = 12 -- replace ’12’ with required space value
5> select @needed_pages = @needed_mb * @pgspermb
6> select @master_end = sum(size) - @needed_pages
7> from master.dbo.sysusages
8> where dbid = 1
9> if (@master_end > (6 * @pgspermb))
10> begin
11>     delete master.dbo.sysusages
12>     where lstart > @master_end
13>     update master.dbo.sysusages
14>     set size = @master_end - lstart
15>     where dbid = 1
16>     and lstart = (select max(lstart) from master.dbo.sysusages
17>                  where dbid = 1)
18> end
19> else
20> begin
21>     print "Can’t take enough space from the master database!"
22>     print "Need to find %1! pages", @needed_pages
23>     print "That would leave master with %1! pages", @master_end
24>     print "Cannot continue."
25> end
26> go

NoteIf the procedure fails, your master device is not big enough to hold all the databases you are trying to create. Check the required MBs of space that you specified. If it is correct, it may be necessary to create a new master device using the instructions in How to Build a New Master Device.

You now have enough space to recreate your required databases. Create them one at a time. For example:

1> create database model on default = 3
2> go

Repeat for each database. Then shut down the server.