ehxz 发表于 2004-8-5 21:05:04

【转帖】Recovering the master Database or Master Device under ASE 12.5



<FONT face="arial, helvetica, geneva" size=-1>This TechNote describes the new procedure you need to use to load the master database, or recover from master database or device corruption in Adaptive Server Enterprise 12.5. The disaster recovery procedures differ from pre-12.5 servers.</FONT>
<P><!--GUTS OF DOCUMENTS STARTS HERE - START COPY HERE-->
<H2>Contents</H2>1. Background
2. Before You Begin
3. Loading an Older Copy of <I>master</I> Database
4. Recreating the <I>master</I> Database
5. Recreating the Master Device
6. Manually Setting the Backup Server Name

<H3>Section 1. Background</H3>Starting with Adaptive Server version 12.5, there is no <B>buildmaster</B> program to build the master device. Rather, this functionality has been incorporated into the <B>dataserver</B> (unix) and <B>sqlsrvr</B> (Windows) programs. The server now allows you to create master devices and databases with 2K, 4K, 8K or 16K logical page sizes. Due to these and other changes, you cannot use the instructions provided in the <I>ASE Troubleshooting and Error Messages Guide</I> (EMTSG) for disaster recovery tasks like recovering the <I>master</I> database or device.
<P>This TechNote explains how to perform disaster recovery in the 12.5.x server. It is applicable to ASE 12.5.0.1 IR and higher versions.
<P><I>Note</I>:
The EMTSG instructions still apply to the pre-12.5 servers.


<H3>Section 2. Before You Begin</H3>This document describes three key maintenance and disaster recovery tasks:
<UL>
<LI>Loading an older copy of your <I>master</I> database. This assumes that both the master device and <I>master</I> database are intact and free from corruption. </LI></UL>
<UL>
<LI>Recovering from a corrupted <I>master</I> database. This assumes that the master device is intact. </LI></UL>
<UL>
<LI>Recreating a master device and all its databases. </LI></UL>Some points to note before using this information:
<UL>
<LI>This material applies only to ASE 12.5.x and higher. It has been verified with ASE 12.5.0.1 Interim Release (IR), and it is recommended that you use the procedures with this release (or later). For 12.0 and prior versions, use the instructions provided in the <I>ASE Troubleshooting and Error Messages Guide</I>, "System Database Recovery." </LI></UL>
<UL>
<LI>This material assumes that your Adaptive Server was installed with your platform's default sort order. If you have installed a non-default sort order, you must ensure that your (restored) server uses the correct sort order and character set to reflect that in the dump. Refer to the <I>ASE Troubleshooting and Error Messages Guide</I>, "System Database Recovery," section titled "Valid Dump with Non-Default Sort Order" for details; and note that in Step 3 of that section, the <B>sybinit</B> utility has been replaced by the <B>dsedit/dscp </B>utilities. </LI></UL>
<UL>
<LI>All SQL command examples in this document use Transact-SQL syntax. All command-line examples are unix commands; Windows users can find the equivalent NT syntax in <I>ASE Utility Programs for Windows and Windows NT</I>. </LI></UL>
<UL>
<LI>Starting with 12.5, the <B>dataserver</B> command allows a space between option and parameter. </LI></UL>
<UL>
<LI>The examples in this document assume that </LI></UL>             - the <B>dataserver</B> binary is located in <I>$SYBASE/bin/dataserver</I>
             - the master device is <I>$SYBASE/d_master.dat</I>
<P>         Replace this location and device name with those appropriate for your site.
<UL>
<LI>The server must be in single-user mode (that is, started with the <B>-m</B> flag) to load the <I>master</I> database. In this mode only the <I>master</I> database can be loaded. </LI></UL>
<UL>
<LI>You can only load a dump of <I>master</I> that matches your server level. Loading an older version dump to a newer server is not permitted. </LI></UL>
<UL>
<LI>You can use these procedures regardless of which version of the server you were using when you created your old master device. The server will find and correct any placement differences between the old and recreated databases. </LI></UL>
<UL>
<LI>After the load completes but before shutting down, the server does some post-processing to reconcile the newly loaded <I>sysdatabases</I> and <I>sysusages</I> tables against the information in the master device. At this time the server may print a variety of error messages regarding failures to use or find the <I>master</I> database, and/or attempts to insert duplicate keys or duplicate rows to <I>sysusages</I>. Ignore these messages; they occur only during the reconciliation phase, and will not affect the server's operation after it shuts down and is restarted.
</LI></UL>
<H3>Section 3. Loading an older copy of <I>master</I> database</H3>Use the following steps if your <I>master</I> database and the master device are intact, and you simply wish to load an older dump of your <I>master</I> database.
<P><I>Note</I>:
Be sure to read Section 2, Before You Begin.
<P><U>Step 1: Put the Server in Single-user Mode</U>
<P>Shut down and restart the server with the <B>-m</B> flag, which places the server in single-user mode and sets up to load the <I>master</I> database:
<P><B>% $SYBASE/bin/dataserver -d $SYBASE/d_master.dat -m</B>
<P><U>Step 2: Establish the Backup Server Name</U>
<P>This step is necessary to ensure that Adaptive Server has access to its backup server for dumps and loads. Follow the instructions detailed in Section 6, Manually Setting the Backup Server Name.
<P><U>Step 3. Load the master Database</U>
<P>Issue the following <B>isql</B> command:
<P><B><TT>1&gt; load database master from "master_db_dump"</TT></B>
<B><TT>2&gt; go</TT></B>
<P>Adaptive Server shuts itself down after the load is complete.


<H3>Section 4. Recreating the master Database</H3>Use this procedure when the current master device is usable, but you are unable to use the server because of <I>master</I> database corruption. These steps enable you to create a new <I>master</I> database and reload it from backup.
<P><U>Step 1. Create a New master Database</U>
<P>The approach to creating the new <I>master</I> database depends on the extent and nature of the corruption. Three different scenarios are possible:
<UL>
<LI>Basic recreation, which is sufficient if only the data in <I>master</I> was affected. The server reads the master device to determine page and device sizes.
<LI>Recreating when the device's configuration area is corrupted. You will need to provide page and device sizing information.
<LI>Recreating when the master database allocation pages are also corrupted. All corrupt or unallocated extents on the device are allocated to <I>master</I>. </LI></UL><I><U>Basic Recreation of master Database</U></I>
<P>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 <I>master</I> database:
<P><B> % $SYBASE/bin/dataserver -d $SYBASE/d_master.dat -w master</B>
<P>The server creates a <I>master</I> 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 via <B>load database</B>. 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 <I>sa</I> with a <I>null</I> password.
<P>This process produces a large number of "upgrade" messages tracking the progress of database creation which are helpful in troubleshooting any problems. They are "upgrade" messages because the server creates a new <I>master</I> database by "upgrading" the device.
<P><I>Note</I>:
If the configuration area is corrupt or unavailable, this command returns the message: "<TT>The configuration area in device 'xxx' appears to be corrupt. The server needs this data to boot, and so cannot continue</TT>." If this occurs, continue with the instructions below.
<P><I><U>Recreation with a corrupt configuration area</U></I>
<P>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:
<P><B>% ls -l $SYBASE/d_master.dat</B>
<P>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.
<P>Provide this information on the command line as follows:
<P><B>% $SYBASE/bin/dataserver -d $SYBASE/d_master.dat -w master</B>
<B>      -z page_size-b device_size</B>
<P>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:
<P><B>% $SYBASE/bin/dataserver -d $SYBASE/d_master.dat -w master -z 2k -b 51204</B>
<P>You may also specify the device size as Kb, Mb, or Gb; for example, "-b 100M".
<P><I><U>Recreation when master database allocation pages are corrupted</U></I>
<P>If the above procedures for recreating the <I>master</I> 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.)
<P>In this case, you can force the server to allocate all corrupted or unallocated extents to the <I>master</I> database:
<P><B>% $SYBASE/bin/dataserver -d $SYBASE/d_master.dat -w master -f</B>
<P>This allocates ALL corrupted or otherwise unrecognizable extents to the <I>master</I> database.Depending on the extent of your master device corruption, and how much free space it originally had, this will probably leave <I>master</I> much larger than it needs to be, causing it to occupy space that used to belong to other databases like <I>model, tempdb, </I>and <I>sybsystemdb</I>. We will consider recovering from that situation later.
<P><I>Note</I>:
You may combine the <B>-f, -b, </B>and <B>-z</B> options as necessary.
<P><U>Step 2. Restart the Server in Single-user Mode</U>
<P>The server shuts down after recreating the <I>master</I> database. Restart it with the <B>-m</B> flag, which places the server in single-user mode and sets up to load the <I>master</I> database:
<P><B> % $SYBASE/bin/dataserver -d $SYBASE/d_master.dat -m</B>
<P><U>Step 3: Account for Missing Databases (if you used the <B>-f</B> option)</U>
<P><I>Note</I>:
You only need this step if you used the <B>-f </B>option in Step 1 to recreate the <I>master</I> database due to allocation page corruption. If you did not use <B>-f</B>, proceed to Step 4.
<P>Recall that the <B>-f</B> command line option could make the new <I>master</I> 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 <I>should</I> be on the master device to perform this step. For example, if you had moved <I>tempdb</I> to a different device, you will not need <I>tempdb </I>on the master device.If upgrading, you may well have created <I>sybsystemdb </I>on a device other than <I>master</I>; if so, you will not need to account for <I>sybsystemdb</I>.
<P>Log in as <I>sa</I>, and check the databases currently on the master device:
<P><B>1&gt; select name from sysdatabases</B>
<B>2&gt; go</B>
<P>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 <I>and</I> how big they should be, then obtain the free space needed to recreate these databases. </P>

ehxz 发表于 2004-8-5 21:05:14

<P>The following <B>isql</B> script obtains the required space by removing it from the end of the <I>master</I> database. In order, it <UL><LI>    establishes how many logical pages the missing databases need <LI>    subtracts that number from the pages that <I>master</I> occupies <LI>    removes disk usage entries for parts of <I>master</I> above that limit <LI>    restricts the highest logical chunk of <I>master</I> such that its total size leaves the required number of pages free. </LI></UL>You will need to provide the required space value, denoted as "<I>@needed_mb</I>". <P><I>Note</I>:
This sample script is provided to assist you with the disaster recovery task. It is not officially supported by Sybase. <P> <TT>       1&gt; declare @needed_mb int, @needed_pages int, @master_end int,</TT>
<TT>      2&gt;      @pgspermb int</TT>
<TT>      3&gt; select @pgspermb = (1048576 / @@maxpagesize)</TT>
<TT>      4&gt; select @needed_mb = 12 -- <B>replace '12' with required space value</B></TT>
<TT>      5&gt; select @needed_pages = @needed_mb * @pgspermb</TT>
<TT>      6&gt; select @master_end = sum(size) - @needed_pages</TT>
<TT>      7&gt; from master.dbo.sysusages</TT>
<TT>      8&gt; where dbid = 1</TT>
<TT>      9&gt; if (@master_end &gt; (6 * @pgspermb))</TT>
<TT>      10&gt; begin</TT>
<TT>      11&gt;   delete master.dbo.sysusages</TT>
<TT>      12&gt;   where lstart &gt; @master_end</TT>
<TT>      13&gt;   update master.dbo.sysusages</TT>
<TT>      14&gt;   set size = @master_end - lstart</TT>
<TT>      15&gt;   where dbid = 1</TT>
<TT>      16&gt;   and lstart = (select max(lstart) from master.dbo.sysusages</TT>
<TT>      17&gt;                  where dbid = 1)</TT>
<TT>      18&gt; end</TT>
<TT>      19&gt; else</TT>
<TT>      20&gt; begin</TT>
<TT>      21&gt;   print "Can't take enough space from the master database!"</TT>
<TT>      22&gt;   print "Need to find %1! pages", @needed_pages</TT>
<TT>      23&gt;   print "That would leave master with %1! pages", @master_end</TT>
<TT>      24&gt;   print "Cannot continue."</TT>
<TT>      25&gt; end</TT>
<TT>      26&gt; go</TT> <P><I>Note</I>:
If 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 Section 5, Recreating the Master Device. <P>You now have enough space to recreate your required databases. Create them one at a time. For example: <P><B>1&gt; create database model on default = 3</B>
<B>2&gt; go</B> <P>Repeat for each database. Then shut down the server, and restart it in single-user mode using step 2 above. <P><U>Step 4. Establish the Backup Server Name</U> <P>This step is necessary to ensure that Adaptive Server has access to its backup server for dumps and loads. Follow the instructions detailed in Section 6, Manually Setting the Backup Server Name. <P><U>Step 5. Load the master Database</U> <P>Issue the following <B>isql</B> command: <P><B>1&gt; load database master from "master_db_dump"</B>
<B>2&gt; go</B> <P>Unlike during a normal database load, the server may need to perform a lot of extra work, because <I>master</I> contains information about the identity and location of your other databases; that information may have changed for this master device, and the server must check and update it as necessary. <P>At the end of this step, the server contains correct disk usage information about the master device. This may differ from the information in <I>sysusages</I> in the dump, so the server will find and correct both the size and location information for the databases.Any entries for parts of databases that don't actually exist on master will be removed. <P>During post-processing from the load, you may see one or more errors from the server. Read Section 1, Before You Begin, for more information about these errors. <P>After checks and validations are complete, the server will shut down. You may now restart it normally. <P><U>Step 6. Did you recreate any databases in step 3 above?</U> <P>If you recreated databases using the procedure in step 3 above, load those databases.You must restart the server <I>without</I> the <B>-m</B> flag in order to accomplish this.
<H3>Section 5. Recreating the Master Device</H3>Use these steps when the disk that used to contain your master device is not accessible, and you need to start over with a new device. <P>This situation is somewhat similar to the scenario in Section 4 above in which the master device becomes so corrupt that you need to use the <B>-f</B> option, because you will need to know what databases used to be on your master device and how big they were so you can validate and recreate them as necessary. <P><U>Step 1. Create your new master device</U> <P>When creating the new master device, make sure you use the same page size as your old master device and make the new device at least as large as the old one. The following example creates a device with a 2048-byte logical page size, and total size 100 Megabytes + 8 Kilobytes (the 8 KB is extra space for the configuration area.) <P><B>% $SYBASE/bin/dataserver -d $SYBASE/d_master.dat -z 2k -b 51204</B> <P>Use the <B>-s</B> option with this command to specify the server name. You can also specify the "-b" size in Kb, Mb, or Gb. In the above example you would use "-b 100.00782M". Without one of the K, M, or G modifiers, the default device size is expressed in server virtual pages, 2048 bytes each. <P>At device creation, the server issues large numbers of "upgrade" messages tracking its progress; these messages help troubleshoot any problems. They are upgrade messages because the server creates a new installation by doing an "upgrade" of a device that it has just created. <P>When finished, the server shuts down. You now have a <I>master</I> database containing minimal system information, including an <I>sa</I> login whose password is <I>null</I>, and minimally sized <I>master, model, tempdb</I>, and <I>sybsystemdb</I> databases. <P><U>Step 2. Put the Server in Single-user Mode</U> <P>Shut down and restart the server with the <B>-m</B> flag, which places the server in single-user mode and sets up to load the <I>master</I> database: <P><B>% $SYBASE/bin/dataserver -d $SYBASE/d_master.dat -m</B> <P><U>Step 3. Establish the Backup Server Name</U> <P>This step is necessary to ensure that Adaptive Server has access to its backup server for dumps and loads. The new master database contains a default Backup Server entry of <I>SYB_BACKUP</I> for <I>srvnetname</I>, which is probably wrong. Since the<B>sp_addserver</B> procedure is not available at this time, log in to the server as <I>sa</I> and update <I>sysservers</I> directly: <P><B>1&gt; update master.dbo.sysservers</B>
<B>2&gt; set srvnetname = "backup_server_name"</B>
<B>3&gt; where srvname = "SYB_BACKUP"</B>
<B>4&gt; go</B>
(1 row affected) <P><U>Step 4. Load the <I>master</I> Database</U> <P>Issue the following <B>isql</B> command: <P><B>1&gt; load database master from "master_db_dump"</B>
<B>2&gt; go</B> <P>The server inspects the master device and makes any corrections needed in the newly loaded <I>sysdatabases</I> and <I>sysusages</I>. These corrections affect only the master device, since that is the only device that changed -- the server assumes that all your other devices are undamaged and need not be inspected. <P>After this step, it is possible that your new master device contains database entries for databases that also exist on other devices in your system.This may happen if you moved <I>tempdb</I> to a different device, or created <I>sybsystemdb</I> on a different device.The server recognizes and handles this situation: if it finds pre-existing entries for those databases on other devices, it presumes that the existing entries are correct and does not change them. <P>During post-processing from the load, you may see one or more errors from the server.Please read Section 2, Before You Begin, for more information about these errors. <P>After the checks and validations are complete the server shuts down. You may now restart it normally. <P><U>Step 5. Check that the Databases on Master Device Are Correct</U> <P>When you created a new master device in step 1 above, the server created only its default set of databases, with minimal data. You will almost certainly need to load dumps of the databases (notably <I>model</I>) that used to be there. <P>Are the databases on your new master device large enough to hold the dumps you will be loading into them?Are all the necessary databases present? Is there any obsolete data that you need to clean up? <P>Log in as <B>sa</B> and inspect the databases on your system: <P><B> 1&gt; declare @pgspermb int</B>
<B> 2&gt; select @pgspermb = 1048576 / @@maxpagesize</B>
<B> 3&gt; select "db name"=db_name(dbid), dbid, "size"=sum(size) / @pgspermb</B>
<B> 4&gt; from master.dbo.sysusages</B>
<B> 5&gt; group by dbid</B>
<B> 6&gt; go</B> <P>This command shows you all the databases present on your system, and their total size. Note that the <I>size</I> column in the output is expressed in Megabytes. <P>Does this list contain any entries where database name is <I>null</I>? These <I>sysusages</I> entries don't have any matching entries in <I>sysdatabases</I>; they are unnecessary and should be deleted.(You may be specially susceptible to this if you upgraded from pre-12.0 versions, and created <I>sybsystemdb</I> on the older version; <I>sybsystemdb</I> will have a different dbid than the default <I>dbid</I>.)To remove these entries, use a script like the following: <P><B>1&gt; exec sp_configure "allow updates", 1</B>
<B>2&gt; go</B>
<B>1&gt; delete sysusages</B>
<B>2&gt; where db_name(dbid) is null</B>
<B>3&gt; go</B>
<B>1&gt; exec sp_configure "allow updates", 0</B>
<B>2&gt; go</B> <P>Are any databases missing?Create those databases. Are the databases large enough?If not, alter them to be at least large enough to hold the dumps. (It is okay if they are too large; the server simply clears the excess space.)

<H3>Section 6. Manually Setting the Backup Server Name</H3>This procedure updates the <I>sysservers</I> table and is needed to ensure that Adaptive Server can access the correct backup server to carry out dumps and loads. Use it with the instructions for Sections 3 and 4. <P>Execute the following <B>isql</B> commands in Adaptive Server: <P><B>1&gt; use master</B>
<B>2&gt; go</B>
<B>1&gt; select srvname, srvnetname from sysservers</B>
<B>2&gt; where srvname = "SYB_BACKUP"</B>
<B>3&gt; go</B> <P>There are three possible outcomes to this query. Take the appropriate action below depending on the outcome:

<TABLE width="100%" border=0><TR><TD width="40%">Outcome</TD><TD>Action</TD></TR><TR><TD>ASE returns a single row and
<I>srvnetname </I>contains the correct
Backup Server name</TD><TD>No action is needed.</TD></TR><TR><TD>ASE returns a single row
but the <I>srvnetname</I> is not the
correct Backup Server name</TD><TD>Issue the following <B>isql</B> command: <P><B>1&gt; update sysservers</B>
<B>2&gt; set srvnetname = "backup_server_name"</B>
<B>3&gt; where srvname = "SYB_BACKUP"</B>
<B>4&gt; go</B> <P>where <I>backup_server_name </I>is the name of the Backup Server
as it appears in the<I> interfaces </I>file<I>.</I></P></TD></TR><TR><TD>ASE returns 0 rows</TD><TD> Issue the following <B>isql</B> command: <P><B>1&gt; sp_addserver SYB_BACKUP, null,</B>
<B>2&gt; backup_server_name</B>
<B>3&gt; go</B>
</P></TD></TR></TABLE></P>
页: [1]
查看完整版本: 【转帖】Recovering the master Database or Master Device under ASE 12.5

免责声明:
本站所发布的一切破解补丁、注册机和注册信息及软件的解密分析文章仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。如有侵权请邮件与我们联系处理。

Mail To:Admin@SybaseBbs.com