SYBASE TECHNICAL NEWS

Volume 8, Number 4 March 1999
Introduction

This issue of Sybase Technical News contains new information about your Sybase software. This newsletter is intended for Sybase customers. All issues of Sybase Technical News are included on the Technical Library CD and web pages.
In This Issue

Tip of the Month

TechNotes:

Other Useful Information

Subscription


Tip of the Month:

Tip: Getting Row Counts in User Tables
Adaptive Server Enterprise keeps row counts of tables in the first OAM page for the object. The system table sybstabstats, introduced in Adaptive Server 11.9.1, also keeps the row count for all user tables. Depending on which server version you are using, there are several ways to obtain the row count for any table: QUERYING THE TABLE (all versions)

In all versions of Adaptive Server and Sybase SQL Server, you can get row counts for any table by querying the table directly. The syntax is:



Using sp_spaceused (SQL Server 4.8 and higher)

To get a row count indirectly, without querying the table, use the sp_spaceused system stored procedure. Keep in mind that sp_spaceused gives an estimate based on an average number of rows per page, and it is more accurate if you run update statistics or dbcc checktable first. The syntax is:



The row count is returned in the column rowtotal.

Using the optdiag utility (11.9.2 and higher)

The optdiag utility, introduced in Adaptive Server 11.9.2, displays statistics that includes Data row count. The syntax is:



For more information on optdiag, see the "Statistics Enhancements" chapter in New Functionality in Adaptive Server Enterprise 11.9.2.
TechNotes
FAQs about XP Server
Background

XP Server, introduced with Adaptive Server Enterprise 11.5, is an Open Server application which runs on the same machine as Adaptive Server and allows you to implement Extended Stored Procedures (ESPs). An extended stored procedure contains procedural language code to carry out functions and tasks external to the server in response to events occurring within the server. For example, the system ESP xp_cmdshell lets you issue an operating system command from within Adaptive Server.

This TechNote clarifies issues on the use and management of XP Server.


FREQUENTLY ASKED QUESTIONS

What variables or path names do I need to define for XP Server?

You need to define the location where extended stored procedures and the associated DLL's reside:
Upon starting Adaptive Server, why don't I see XP Server running?

Starting Adaptive Server does not start XP Server, nor do you need to start it yourself. Adaptive Server starts XP Server automatically when the first extended stored procedure is run.

Note: XP Server does not have a separate RUN_SERVER file of its own. However you can still start XP Server without a RUN_SERVER file, for troubleshooting purposes, as described later in this TechNote. What XP Server Management Options are Available?

You can use the xpserver utility to help maintain XP Server:

Usage: xpserver <options>

where options include:



Why do I get Error Message 11018 ("XP Server must be up for ESP to execute"), and what does it mean?

Error 11018 is raised when Adaptive Server is unable to contact XPServer to execute an ESP. Check that your interfaces file (UNIX) or sql.ini file (NT) has the correct entry for XP Server; the XP Server name must be in all upper case letters and have the format SERVER_NAME_XP. Check also that the server name appears in sysservers, using the isql command:
Retry the ESP after making any necessary corrections.

Sometimes XP Server is not started the first time you issue an ESP. To start XP Server, shut down and restart Adaptive Server, and reissue the ESP. This is only necessary after the initial installation of Adaptive Server.

Why do I get kernel error "XP Server failed to start. Try bringing up XP Server manually. Check SQL Server documentation on how to bring XP Server up"?

This kernel error means that XP Server is unable to start because the XPServer port is in use by another process. To investigate the port assignment:
  1. Identify the port number assigned to XP Server by looking in the interfaces file (UNIX) or sql.ini file (NT).
  2. Check if another XP Server process (or any other process) is using the same port number by entering: netstat -a | grep (UNIX) netstat -a | more (NT) If the port number is present as a local address from the netstat output, you may not use that port for the XP Server because the port is already in use by another process.
  3. To determine whether the XP Server port is in use, try running XPServer manually using the following command: xpserver -S XP Server will not start if the XP Server port number is in use.



If you find processes using the same port number:
  1. If a stale XP Server process was using the port number, terminate the process: o On UNIX, use the operating system kill command. o On NT, press ctrl+alt+delete and click the Task Manager button to open the Windows NT Task Manager window. Select the xpserver process you want to terminate and click the End Process button. Otherwise, if a process other than XP Server was using the port, use another port number for XPServer by modifying the interfaces file (UNIX) or sql.ini file (NT).
  2. Start XP Server manually to verify that it can start successfully: xpserver -S
  3. Terminate the XP Server you started manually.



If you find no processes using the same port number:

  1. Restart Adaptive Server.
  2. Return to executing the ESP. XP Server should start automatically.



When using xp_cmdshell, I get the message "User access denied. Failed to change the user context." What should I do?

This message means that you cannot execute the command because of the current setting of your xp_cmdshell security context. To verify your xp_cmdshell context issue the following isql command:

The Run Value in the output is your current xp_cmdshell context. See the System Administration Guide for possible values of this configuration variable, then set the appropriate context and retry xp_cmdshell.

See also the -x flag for xpserver (NT specific) .

Where can I find the XP Server log file?

By default, the XP Server log file is located in the $SYBASE/install directory (UNIX) or %SYBASE\install (NT). The naming convention is .log.



Adaptive Server Enterprise Suspect Granularity Errors



Errors 12716 and 12717.



Error 12716

Severity 17

Error Message

Data unavailable: Unable to complete because the required data is currently unavailable. The command failed and the transaction aborted. Try again later or contact your System Administrator.

EXPLANATION

Adaptive Server's Recovery Fault Isolation (RFI) feature enables recovery to mark a single page or a set of pages of a user database suspect, while allowing access to the remainder of the database. The bad page(s) are said to be "offline", and may not be used until the problem is corrected. (For a detailed discussion of RFI, refer to "Online Recovery and Recovery Fault Isolation" in "Encyclopedia of Tasks").

Error message 12716 results when you issue a query that requires access to an offline page. This error is followed by Error 12717 (Suspect data encountered: Database '%.*s', object '%.*s', index ID '%ld', page ID '%ld'.).


ACTION

The offline page(s) must be repaired before they can be used. Responsibility for repairing offline pages belongs to a user with sa_role. The System Administrator can bring a page online to make it accessible to sa_role:



where pgid is the page ID shown in the accompanying 12717 error.
WARNING!
When forcing pages online, note that Adaptive Server does not do any consistency checks before onlining pages.

Use existing methods to diagnose and repair problems, checking the server error log for any errors related to the offline page and determining appropriate corrective action. Before making repaired pages available to all users, check that repairs have been made correctly by running dbcc commands or queries with known results.

ADDITONAL INFORMATION

Refer to "Online Recovery and Recovery Fault Isolation" in "Encyclopedia of Tasks" for a detailed discussion of RFI.

Versions in Which This Error is Raised

11.9.2 and later

Error 12717

Severity

17

Error Message

Suspect data encountered: Database '%.*s', object '%.*s', index ID '%ld', page ID '%ld'


EXPLANATION

Adaptive Server's Recovery Fault Isolation (RFI) feature enables recovery to mark a single page or a set of pages of a user database suspect, while allowing access to the remainder of the database. The bad page(s) are said to be "offline", and may not be used until the problem is corrected. (For a detailed discussion of RFI, refer to "Online Recovery and Recovery Fault Isolation" in "Encyclopedia of Tasks").

Error message 12717 results when you issue a query that requires access to an offline page. This error is preceded by Error 12716 (Data unavailable: Unable to complete because the required data is currently unavailable. The command failed and the transaction aborted. Try again later or contact your System Administrator.).


ACTION

The offline page(s) must be repaired before they can be used. Responsibility for repairing offline pages belongs to a user with sa_role. The System Administrator can bring a page online to make it accessible to sa_role:

where pgid is the page ID shown in the 12717 error.

WARNING!
When forcing pages online, note that Adaptive Server does not do any consistency checks before onlining pages.

Use existing methods to diagnose and repair problems, checking the server error log for any errors related to the offline page and determining appropriate corrective action. Before making repaired pages available to all users, check that repairs have been made correctly by running dbcc commands or queries with known results.


ADDITIONAL INFORMATION

Refer to "Online Recovery and Recovery Fault Isolation" in "Encyclopedia of Tasks" for a detailed discussion of RFI.

Versions in Which This Error is Raised

11.9.2 and later




Online Recovery and Recovery Fault Isolation




Fault Isolation (RFI) to enhance the granularity of recovery. This discussion surveys various recovery options and focuses on the difference between traditional online recovery and RFI. We use examples to show how RFI can enhance the recovery scenarios and how it can help to avoid extensive downtime due to recovery problems.

Note: This information also appears in the 11.9.2 Error Messages and Troubleshooting Guide. Unless otherwise specified, all references in this TechNote are to sections of that document.

BACKGROUND

Recovery can mean several things:

ONLINE RECOVERY CONCEPTS AND PRE-11.5 RECOVERY

Online recovery brings the database to a consistent state after you restart the server.

During routine Adaptive Server operation, all changes to the database are written first to the log, then to the data pages on disk. Log pages are written to disk when the transaction completes, that is, when the transaction commits. However, because all changed pages are written to disk whenever a checkpoint occurs, for other reasons prior to commit, changes can be written to the log or data pages as part of an as-yet-incomplete transaction. If the server fails after an uncommitted transaction is written to the log but before the transaction completes, online recovery reads the log and ensures that no uncommitted changes are reflected in the database. Likewise, online recovery ensures that any changes recorded in the log for committed transactions that have not yet been flushed to disk are updated on the data pages and written to disk.

Prior to version 11.5, online recovery was an all-or-nothing proposition. If recovery failed due to some corruption, there was no way to partially recover the database and leave the corrupt portion offline. The preferable option was to restore the database from backups. However, if backups were not available or time constraints made it difficult to go through the extensive procedures necessary to restore through backups, customers often used an undocumented and risky procedure, referred to as "suiciding the log", to skip recovery and get the database back on line.

RECOVERY FROM BACKUPS

The traditional recovery option, when online recovery fails, is to restore the database from dumps, and incrementally apply transaction logs to bring the restored database back to the most current possible state. This is the best solution for restoring to an absolutely consistent state after corruption. It often brings the database to a state of consistency to within seconds of the point of original failure.

However, the drawback with this traditional approach is that the recovery granularity is at the level of the transaction dump. If a transaction causing corruption is dumped, the traditional method means loading a database dump and applying transaction log dumps up to, but not including, the transaction dump containing the offending transaction. This can result in hours of lost transactions.


SUICIDING THE LOG

While suiciding the log can usually bring the server back online, it also frequently results in both physical and logical corruption in the database, because it bypasses the normal process of rolling back incomplete transactions in the log (and rolling forward completed transactions) that takes place during online recovery. Frequently, the resulting corruption is not encountered until a later time, and the connection with the earlier log suicide is not always recognized.

WARNING!
Log suicide is highly risky, and is not recommended except in extreme cases.


RECOVERY WITH RFI

Version 11.5 implements Recovery Fault Isolation (RFI), a new online recovery feature that provides a level of granularity in recovery by means of partial recovery. RFI can isolate corruption, encountered during recovery, to the corrupt pages. This enables you to restore database integrity by isolating and repairing corruption on a page by page (and, consequently, on an object by object) basis without having to restore the entire database and transaction logs from backups.

Note: While RFI can only define granularity at the page or database level, corruption is typically corrected at the object level with, for example, an entire index being recreated or an entire table being replaced.

USING RFI

Note: RFI allows partial recovery only on non-system objects. If it encounters corruption on system tables, recovery fails for the entire database.

RFI allows the database administrator (DBA) to select the granularity of recovery for each user database. The choices are:

Finally, the DBA can set the database to be marked suspect on any recovery failure, then change the setting to recover all but the corrupt pages. In this mode users cannot access the database, enabling the DBA to determine the appropriate course of action and proceed accordingly.

There is a significant difference between RFI's page-level and database-level granularity. Database granularity mandates that all transactions in the database should either be completed and rolled forward, or rolled back and all changes backed out. In either case the database is in a logically consistent state at the end of recovery. In short, recovery is all or nothing. Any interruption in recovery that makes this impossible causes recovery to fail entirely, and the only sure way to guarantee a consistent state is to restore from backups. This can be problematical, depending on how many backups are available, their validity, and how recent they are.

Page level granularity, on the other hand, allows the server to offline corrupt pages in a transaction while onlining other pages. Since recovery has not been able to complete and verify the transactions, this will leave some of the transactions only partially available and all other transactions completely recovered as usual. There is no way to determine whether transactions that involved offlined pages are complete except by manual examination.

If, for example, a transaction changes rows on three pages and the changes on two pages are written to disk before the server stops, recovery would normally assure that the third page also was written to disk. If, however, recovery marks as suspect the page to which the third update is to be made, there is no way to determine whether the transaction is complete or incomplete; that is, whether all three pages are updated or only the first two. A transaction in this state is deemed to be partially available, as the changes to the first two pages are available while the change to the third page is unavailable, and it is not known whether it was changed.

At another level, consider a case where a page from a specific table is marked offline. Subsequent work is dependent on this page but only at an implicit level, meaning that it is assumed that business rules will be handled without explicitly coding referential checks. If the code were to explicitly check for the offline data, an error would be raised; but if this is not done and the work proceeds with only an implicit dependence on the offline pages (which cannot be restored to a consistent state), it may result in logical inconsistencies in the database. This is yet another reason we recommend that all dependencies between data be explicitly coded via declared referential constraints, triggers or existence checks.

It is important to understand that while it is possible to bring corrupt pages online, doing so without first repairing the pages will result in logical and data inconsistency. When restoring a database by repairing offline pages (or by restoring objects to which the offlined pages belonged), therefore, the DBA must explicitly determine the degree to which logical consistency of the database may be suspect according to business rules and coding practices. Of course, restoring the database from a database backup and incremental transaction backups assures both the logical and physical integrity of the database through the last successful load of a transaction dump.

It is also important to run dbcc tablealloc or dbcc indexalloc with the fix option on any objects with suspect pages because the allocation information for these objects is also suspect.


WHAT TO DO WHEN ONLINE RECOVERY FAILS

The options for recovering from a failure in online recovery, in order from most desirable to least, are:




RESTORING FROM BACKUPS

Prior to Version 11.5, this was the only option if recovery failed, the database could not be repaired, and suicide of the log was not desirable. It is still the preferred option for recovering the database after failure during online recovery if a) the entire database is marked suspect due to thresholds being exceeded, or b) system table(s) are corrupt. It is also the preferred method whenever the absolute need for physical and logical consistency overrides all other concerns.

Note: It is highly recommended that you run dbcc checks prior to and following a dump, to ensure that the backup is valid. Refer to Backup and Recovery in the System Administration Guide for details.


PARTIAL ONLINE RECOVERY USING RFI

Implementing RFI gives the DBA many more choices in the event of failure during online recovery. Before opting for log suicide, consider these advantages of RFI over log suicide:

  1. Isolated pages are known and can be examined. You can thus make an informed decision on whether to repair the faults or restore from backups.
      o If the isolated pages belong to an index, the corruption can often be fixed by dropping and recreating the index. o If the isolated page are data pages, the data can sometimes be recovered via other means. You can also leave the pages safely offline; transactions that explicitly depend on their presence will fail until they are made available. o Pages referenced in recovery that are marked suspect, but are subsequently deallocated further along in the recovery process, are assumed to have been properly written for the earlier transaction and are taken off the suspect list, thus making the corruption for that page "self-healing".
  2. You can set thresholds to determine at what level page faults are unacceptable, and at which the whole database should remain unrecovered.
  3. You can make the database available to users while conducting repairs. The database can be configured to allow updates or to allow read-only access.
  4. Faults on system table pages cause recovery to fail for the entire database.
  5. You can implement a limited form of suicide recovery by disregarding all or some of the suspect pages and onlining them even if they are corrupt. The suicide is limited in the sense that only transactions associated with those pages are suspect. Recovery rolls forward (or back) other transactions in the log properly.


IMPLEMENTING RECOVERY WITH RFI

In Version 11.5 and higher, the default granularity of recovery remains at the database level. Take the following steps to implement page level granularity:

  1. Check or implement page granularity on desired databases using the sp_setsuspect_granularity stored procedure:
         sp_setsuspect_granularity [dbname [,{"database" | "page"} [, "read_only"]]]

    If you set the granularity to page level, you have the option to set the database to read_only mode when recovery detects suspect pages. By default, all available pages are accessible for both reads and writes.

    Note: Wherever possible, use the read_only mode. If a query attempts to access an offline page, the server raises error messages 12716 and 12717 regardless of whether the database is read_only. For more information on these errors see the chapter titled "Error Message Writeups."

  2. Set the threshold for escalating page level granularity to database granularity using the sp_setsuspect_threshold stored procedure:
         sp_setsuspect_threshold [dbname [,threshold  ]]
    
    Once the number of offlined pages reaches this threshold value, recovery marks the entire database suspect. The default threshold value is 20 pages. It is unlikely that setting it much higher will be of much use since 20 corrupt pages is very likely to indicate corruption at a level than cannot be effectively repaired.
  3. Bring the suspect pages or database on line. You can print a list of pages or databases that are suspect after recovery using the sp_listsuspect_db and sp_listsuspect_page stored procedures:
         sp_listsuspect_db
         sp_listsuspect_page [dbname]
    
    You can bring these pages or database online using the sp_forceonline_db or sp_forceonline_page stored procedures:
         sp_forceonline_db dbname
           {"sa_on" | "sa_off" | "all_users"}
    
         sp_forceonline_page dbname, pagenumber
           {"sa_on" | "sa_off" | "all_users"}
    
    sa_on and sa_off toggle the database or page online and offline, and allow access to the database or page only to those with the sa_role set on. This permits the DBA to examine and repair the suspect database or pages without other users being able to access them.
    WARNING!
    The all_users option is irreversible and makes the database or page available to all users. If no repairs have been made, this may result in some level of logical inconsistency.


    SUICIDING THE LOG

    The new RFI feature in 11.5 eliminates most of the need for suiciding the log. The two most common reasons for suiciding the log in the past were:

    1. No backups are available or the backups are too old.
    2. Insufficient time to restore.

    There should never, of course, be a situation where backups are unavailable or are too old. Unfortunately that is too often the case, either because the dumps are bad or due to poor planning. In such situations, suiciding the log may be the only recourse. Aside from those situations however, you should never consider suiciding a viable option.

    Note: DBA's should test all backup and restore procedures before relying on them. If you attempt to load a dump on the original database and it completes only partially, you will have eliminated the possibility of using that database again and may even have eliminated the final chance to recover data by suiciding the log.

    RFI Example

    Here is an example of recovery using RFI's page level features:

    During recovery of a database, five pages were marked suspect. The DBA examined the pages and determined that three of them are index pages on a single allpages--locked (APL) table, and that the other two marked suspect are data pages belonging to different tables. The database has been marked as read_only and while users can query the database, no changes can currently take place.

    First the DBA onlines the pages with the sa_on option. The DBA then immediately dumps the transaction log to ensure the ability to recover to this point should something else go wrong. Recovery would involve loading a database dump and all subsequent transaction dumps.

    Before RFI, a dump of a suspect database was not possible. With RFI, the DBA can make a dump of the slightly corrupt database in case it is needed later. Often a recent dump with a few problems is preferable to an older dump with no problems. This is purely a safety measure as the DBA hopes to be able to repair the database, which is currently partly unrecovered.

    Next the DBA runs dbcc indexalloc on the index containing the three offline pages. indexalloc reveals errors, and it is decided that the best thing to do is to rebuild the index. If the index was a nonclustered index, or a data-only-locked (DOL) clustered (placement) index, it could simply be dropped and recreated. However, this is an APL clustered index and any time the clustered index is suspect, the table is suspect as well. The DBA runs dbcc checktable to examine the integrity of the data pages. dbcc checktable always checks the data page linkage before checking the index structures. (Keep in mind that a DOL table's data and non-leaf index pages do not have maintained sibling links that can be followed by dbcc pglinkage type of checks.) By looking at the output of dbcc checktable, the DBA determines that the data page linkage is intact. This means that it is safe to drop the clustered index.

    Note: If the data page linkage also showed corruption, the DBA would have to resort to backups or find another way to restore the table (an offline bcp copy, for example).

    Looking at the data pages for the other two objects, it is found that the first object is a static reference table, and an offline copy of this table's data exists. The DBA decides to truncate the table and bcp in a new copy. For the second object, an APL clustered table, the data page linkage is found to be broken, but the clustered index is still intact. With this information the DBA is able to locate all of the rows, bcp them out, truncate the table and bcp them back in.

    Once all of these tasks are complete, the question of possible incomplete logical changes to the tables due to incomplete transactions still remains. The only way to test for data integrity is to use user-written queries and reports that expose inconsistencies. After doing this, the DBA can determine if those inconsistencies can be tolerated, or repaired, or if backups are the best option.

    The final step is to detect and fix any allocation inconsistencies that may exist due to recovery having only partially completed. The DBA can run dbcc checkalloc to check the entire database, or dbcc tablealloc and dbcc indexalloc can be run on the suspect objects.

    >From this example it is clear that Recovery Fault Isolation makes many more choices available to the DBA. With database-only granularity, the DBA has no way to examine the extent of the corruption and make a decision as to what the best solution to the failed recovery might be.




    Useful dbcc Commands






    checker (dbcc) commands useful for diagnosing and troubleshooting Adaptive Server problems.

    Note: This information also appears in the 11.9.2 Error Messages and Troubleshooting Guide. Unless otherwise specified, all references in this TechNote are to sections of that document.


    STANDARD dbcc COMMANDS The standard, supported dbcc commands used in this document are as follows:
    dbcc CommandPurpose
    tablealloc checks allocation information for the specified table.
    textalloc checks allocation information in text pages for the specified table.
    indexalloc checks allocation information for the specified index.
    checkalloc runs the same checks as tablealloc, for all pages in a database.
    checktable checks the integrity of data and index pages in the specified table.
    checkdb runs the same checks as checktable, for all tables in a database.
    checkstoragecombines some of the checks of the above commands, and provides additional checks. checks the integrity of indexes on user tables. prints a
    reindex message when it finds the first index error and then drops/recreates the index.
    For a complete description of these commands, see the System Administration Guide.

    OTHER dbcc COMMANDS

    This document utilizes a number of additional dbcc commands. These commands, listed below, are useful in specific troubleshooting situations to gather information and diagnose problems.

    WARNING!
    These are undocumented and non-standard commands. Sybase Technical Support does not support them for general use. Although the command syntax is provided here for reference, you should use these commands only to diagnose specific errors as described in this document, and with the specific syntax shown in those sections. Failure to do so could cause performance problems and/or database corruption.

    Command: dbcc page

    Purpose: Prints the contents of a page within a database.

    Usage:

    dbcc page (dbid, pageno,[printopt [,cache [,logical [,cachename]]]])

    or

    dbcc page (dbname, pageno,[printopt [,cache [,logical [,cachename]]]])

    'dbcc page' arguments
    dbid database ID
    dbname database name
    pageno page number
    printopt
    output format: 0 print buffer and page header only (default)
    1 print buffer and page headers, rows and offset table
    2 print buffer and page headers, hex dump of data and offset table
    cache
    where to get the page: 0 read page from disk
    1 read page from cache if present, otherwise read from disk (default)
    logical
    The page type 0 pageno is a virtual page
    1 pageno is a logical page (default)
    cachename
    cachename -1 all caches

    Command: dbcc pglinkage

    Purpose: checks the linkage of a page chain.

    Usage:

    dbcc pglinkage (dbid, start_pg_num, number_pages, printopt, search_for, search_order)

    dbid database ID
    start_pg_num page number at which to start checking
    number_pages
    the number of pages to check: 0 check all pages
    printopt
    denotes which pages to display: 0 display only the number of pages checked
    1 display the last 16 pages checked
    2 display all the page numbers checked
    search_for stop checks when this page number is reached
    search_order
    Search direction: 0 follow previous page pointers
    1 follow next page pointers


    Command: dbcc log

    Purpose: displays transaction log records.

    Usage:

    dbcc log (dbid, objid, pageno, rowno, nrecs, type, printopt)

    dbid Database ID
    objid can be <0, zero, or> 0. Meaning of this option depends on the values of 'pageno' and/or 'rowno'. For example, if objid >0 and 'pageno' and 'rowno' = 0, all records for that object are displayed.
    pageno page number (or 0)
    rowno row number (or 0)
    nrecs number of records and log scan direction
    type Type of log record to display
    printopt
    denotes display options 0 display header and data
    1 display header only


    Command: dbcc traceflags (available with 11.0.3 and later) Purpose: Shows what traceflags, if any, are currently active in the server. Usage:
      dbcc traceflags
      
    Command: dbcc traceon Purpose: activates the specified trace flag. Usage:
      dbcc traceon (trace_flag)
      
    Command: dbcc traceoff Purpose: de-activates the specified trace flag. Usage:
      dbcc traceoff (trace_flag)
      
    Command: dbcc memusage Purpose: Shows memory allocation for server structures and objects, for example the size and number of stored procedures. Usage:
      dbcc memusage
      
    WARNING!
    Running dbcc memusage on a multi-engine server can cause the other running processes to timeslice.
    Avoiding Disaster with Good DBA Practices
    Server Enterprise.

    Note: This information also appears in the 11.9.2 Error Messages and Troubleshooting Guide. Unless otherwise specified, all references in this TechNote are to sections of that document.


    SYSTEM ADMINISTRATION TIPS

    The following practices can keep your Adaptive Server installation working at peak effectiveness. By maintaining these good practices, you can maximize server uptime, correct problems proactively, and be as prepared as possible to handle emergencies.
    1. Keep Up-to-Date Backups Maintaining current backups of your data is vital for any recovery plan. Keep multiple generations of backups, and keep some offsite as an extra precaution. Make regular database dumps of:
      • the master database. To insure that your backup of master is always current, back up master after each maintenance command that affects disks, storage, databases, or segments - for example, after creating or deleting databases, initializing new devices, and creating or modifying segments.
      • the model database
      • the sybsystemprocs database
      • user databases.
    2. Maintain copies of System Tables and DDL Keep the latest offline copies of the following tables:
      • sysusages
      • syslogins
      • sysloginroles
      • sysdatabases
      • sysdevices
      • syscharsets
      • sysconfigures
      • sysservers
      • sysremotelogins
      • sysresourcelimits (11.5 and later)
      • systimeranges (11.5 and later)
      Use the bcp utility to copy out these tables. In addition, maintain a hardcopy by printing the output of the following queries:
             select * from sysusages order by vstart
             select * from sysusages order by dbid, lstart
             select * from syslogins
             select * from sysloginroles
             select * from sysdatabases
             select * from sysdevices
             select * from syscharsets
             select * from sysconfigures
             select * from sysservers
             select * from sysremotelogins
             select * from sysresourcelimits (11.5 and later)
             select * from systimeranges (11.5 and later)
        
      Also maintain:
      • copies of your configuration file.
      • the first two blocks (2 pages) of the master device.
      • a copy of the config block. You can generate this using Sybase Central or Power Designer. On Unix platforms, you can obtain a copy of the config block with this command: dd if=master_device of=$SYBASE/config_block.bak bs=1024 count=8
      • all Data Definition Language (DDL) scripts you use to create user objects, specially stored procedures if you elect to use sp_hidetext (11.5 and later).
      Note: Implement all changes to schema in the same way that the installmaster script is implemented.
    3. Verify Database Consistency Run dbcc checks on a regular basis to monitor the health of your databases. Database-wide checks are available with dbcc checkdb, dbcc checkalloc, and dbcc checkstorage (11.5 and higher). dbcc checkcatalog is also a useful tool. For a brief overview of dbcc commands, see "Useful dbcc Commands". Detailed information appears in the System Administration Guide.

      Since dbcc checks can be resource intensive, consider adopting a strategy to take advantage of object level dbcc's. On a given day run a certain number of checktable and tablealloc commands for a portion of the database. On subsequent days, run different tables. Over a period of days you can accomplish a complete check of your databases for integrity. For example if your database has 200 tables in addition to the system tables, run dbcc's on the system tables on night one, run dbcc's on each of the first 50 of the user tables on night two, the next 50 the next night and so on, until at the end of five nights you have checked every table in the database. On the sixth night you can begin the cycle again.

      Note: Running table-level dbcc's misses the GAM page checks.

      Alternative strategies include:
      • loading the database to another server, and running the dbcc's on that server;
      • dbcc checkstorage (11.5 and higher).

      Building dbcc checks into your regular backup/maintenance schedule can ensure that you have consistent, accurate backups available at all times.
    4. Implement Mirroring Mirroring, either at the Adaptive Server level or at the operating system level, can provide nonstop recovery in the event of media failure.

      The factors you need to consider, and instructions on implementing Adaptive Server mirroring, are detailed in the section titled "Mirroring Database Devices" in the System Administration Guide.
    5. Perform Ongoing Maintenance

      As part of a routine program of server maintenance, you should:
      • Monitor the Adaptive Server error log for errors. Note that users may not report errors of severity 17 or 18 if their work is not interrupted. Set up a routine that browses the error log, searching for errors. See "How to Monitor the Adaptive Server Error Log" for an example. For information on the error log format and severity levels, see the System Administration Guide. Note: NT users can also monitor server messages by means of the Windows NT Event Log. For details, refer to What's New in Sybase Adaptive Server Enterprise Release 11.5. Prune the error log regularly as it grows constantly since Adaptive Server appends informational messages to the log during startup. A full error log with no space to write to may cause the server to freeze. Remember to shut down the server first, and make a copy of the log before pruning. An example of log pruning on Unix follows:
                    % cp errorlog errorlog.date
                    % cp /dev/null errorlog
          	
        where date is the current date.
      • Monitor the operating system log to keep an eye on the health of the hardware and the server environment. Many Adaptive Server errors can be due to underlying hardware problems, and can therefore indicate hardware problems. Refer to "Checking the Operating System Error Log" in "Encyclopedia of Tasks" for information on how to locate your log and how to check it.
      • Monitor space usage with system procedures such as sp_helpsegment, sp_spaceused, and sp_helpdb. By running sp_spaceused regularly, for example, you can determine if a database is running out of space for new objects. Alternatively, you can set up thresholds to monitor free space on database segments. See "Getting Information About Database Storage" and "Creating Threshold Procedures" in the System Administration Guide for details.
      • On Versions prior to 11.9.2, update index statistics. Distribution pages hold statistics on the distribution of index key values. As a table grows and changes, these statistics become old, and the server may start to choose the wrong index strategy for queries. You can address this condition by running update statistics periodically. Version 11.9.2 and later do not utilize distribution pages; instead, they use a different mechanism for maintaining statistics. Refer to New Functionality in Adaptive Server Enterprise 11.9.2 for details.
    6. Avoid Risky Practices
      • Avoid moving tempdb off the master device. When Adaptive Server is installed, tempdb resides on the master device. Although it is possible to move tempdb off the master device later for space considerations, this is not advisable. Once tempdb is moved off the master device, it is difficult and time-consuming to recover if a problem occurs on the master device or the device to which tempdb is moved.
      • Never put anything other than master, model and tempdb on the master device. Storing user databases on the master device may make it difficult to recover the system databases or user databases if either become damaged.
    7. Recovery Tips, Or What to do When Things Go Wrong
      • Choose the correct recovery method. Your choice of methods will be dictated by the type of failure you encounter. For example, loss of a device will require restoring from backups.

        Network/machine failure usually has little impact on the server but could corrupt data in some situations, and recovery may fail.
      • If mirroring is enabled at your site, disable the mirror before loading a dump, thus preserving a copy of what you had before in case dumps are bad.
      • Never run buildmaster on the original master device. It may contain information you need later. Instead, do a buildmaster on a different device, and when your environment is completely restored, you can move back to your original master device.
    8. Additional Tips After an operating system upgrade, check permissions on your sybase devices.

    Other Useful Information

    Browse the most recently released documents.


    For frequent updates, visit the Sybase Technical Library on the World Wide Web at http://techinfo.sybase.com.

    Electronic Case Management and Electronic Software Delivery access remains limited to Sybase support contacts who are registered with SupportPlus Online Services. ECM and ESD requires SSL web browser support. ECM and ESD users also may access the Technical Library from behind the firewall in the usual manner, allowing them to retain the security benefits of using SSL with their web browser.

    Subscription Information

    Send comments to technews@sybase.com. To receive this document by regular email, send email to majordomo@sybase.com, and in the body of your message put subscribe inews-technews-full. For a summary version by email, put subscribe inews-technews-summary. No subject line is necessary.

    Staff

    Principal Editor: Betsy Brazy

    Production Editors: Deborah Blakeney, Rodney Esperanza, Leigh Ann Hussey

    Contributors: Vinaye Misra

    Disclaimer
    No express or implied warranty is made by Sybase or its subsidiaries with regard to any recommendations or information presented in Sybase Technical News. Sybase and its subsidiaries hereby disclaim any and all such warranties, including without limitation any implied warranty of merchantability of fitness for a particular purpose. In no event will Sybase or its subsidiaries be liable for damages of any kind resulting from use of any recommendations or information provided herein, including without limitation loss of profits, loss or inaccuracy of data, or indirect special incidental or consequential damages. Each user assumes the entire risk of acting on or utilizing any item herein including the entire cost of all necessary remedies.


    If you ever want to remove yourself from this mailing list, you can send mail to "majordomo@sybase.com" with the following command in the body of your email message:



    If you ever want to add yourself to the TechNews Summary mailing list, you can send email to "majordomo@sybase.com" with the following command in the body of your email message: