sp_iqcheckdb procedure

Function

Checks validity of the current database and optionally repairs indexes and allocation problems.

This stored procedure reads all storage in the database. On successful completion, the database free list (an internal allocation map) is updated to reflect the true storage allocation for the database, if the -iqdroplks server switch is used. sp_iqcheckdb then generates a report listing the actions it has performed.

If an error is found, sp_iqcheckdb reports the name of the object and the type of error. sp_iqcheckdb does not update the free list, if any errors are detected.

The sp_iqcheckdb stored procedure also allows you to check the consistency of, and optionally repair, a specified table, index, index type, or the entire database.

Notesp_iqcheckdb is the user interface to the IQ Database Consistency Checker (DBCC) and is sometimes referred to as DBCC.

Syntax

sp_iqcheckdb 'mode target [...] [ resources resource-percent ]'

This is the general syntax of sp_iqcheckdb. There are three modes for checking database consistency, and one repair mode. The syntax for each mode is listed separately below. If mode and target are not both specified in the parameter string, Sybase IQ returns the error message “At least one mode and target must be specified to DBCC.”

Parameters

mode: { allocation | check | verify } | repair

target: [ main | local | indextype index-type […] ] database | database resetclocks | { [ indextype index-type ] […] table table-name | index index-name […] }

Allocation mode

sp_iqcheckdb 'allocation target [ resources resource-percent ]'

Check mode

sp_iqcheckdb 'check target [ resources resource-percent ]'

Verify mode

sp_iqcheckdb 'verify target [ resources resource-percent ]'

Repair mode

sp_iqcheckdb 'repair target [ resources resource-percent ]'

Usage

main All tables and indexes checked are from the IQ Store. In a multiplex, they are from the shared IQ Store.

local All tables and indexes checked are from the local IQ Store on a particular query server in a multiplex.

index-type The index-type parameter is one of the following index types: FP, CMP, LF, HG, HNG, WD, DATE, TIME, DTTM.

If the specified index-type does not exist in the target, an error message is returned. If multiple index types are specified and the target contains only some of these index types, the existing index types are processed by sp_iqcheckdb.

index-name The index-name parameter may contain owner and table qualifiers: [[owner.]table-name.]index-name

If owner is not specified, current user and database owner (dbo) are substituted in that order. If table is not specified, index-name must be unique.

table-name The table-name parameter may contain an owner qualifier: [owner.]table-name

If owner is not specified, current user and database owner (dbo) are substituted in that order. table-name cannot be a temporary or pre-join table.

NoteIf either the table name or the index name contains spaces, enclose the table-name or index-name parameter in double quotes, as shown in this example:

sp_iqcheckdb 'check index "dbo.ss tab.i2" resources 75'

resource-percent The input parameter resource-percent must be an integer greater than 0. The resources percentage allows you to limit the CPU utilization of the database consistency checker by controlling the number of threads with respect to the number of CPUs. If resource-percent = 100, then 1 thread is created per CPU. If resource-percent > 100, then there are more threads than CPUs, which might increase performance for some machine configurations. The minimum number of threads is 1. The default value of resource-percent is 100.

NoteThe sp_iqcheckdb parameter string must be enclosed in single quotes and cannot be greater than 255 bytes in length.

Allocation problems can be repaired in check, verify, and allocation mode by starting the database with the -iqdroplks server switch.

Description

sp_iqcheckdb checks the allocation of every block in the database and saves the information in the current session until the next sp_iqdbstatistics procedure is issued. sp_iqdbstatistics displays the latest result from the most recent execution of sp_iqcheckdb.

sp_iqcheckdb can perform several different functions, depending on the parameters specified. The four modes for checking and repairing database consistency are:

Allocation mode Checks allocation with blockmap information for the entire database, a specific index, a specific index type, or a specific table; repairs the free list if the -iqdroplks server switch is specified. Does not check index consistency.

sp_iqcheckdb cannot check or repair all allocation problems, if you specify the name of a single index, index type, or table in the input parameter string.

When to run in allocation mode:

The DBCC option resetclocks is used only with allocation mode. The resetclocks option is used in conjunction with forced recovery to convert a multiplex query server to a write server. resetclocks corrects the values of internal database versioning clocks, in the event that these clocks are behind. Do not use the resetclocks option for any other purpose, unless you contact Sybase IQ Technical Support.

The resetclocks option must be run in single-user mode and is allowed only with the DBCC command “allocation database”. resetclocks does not require the -iqdroplks server start-up switch. The syntax of the resetclocks command is:

sp_iqcheckdb 'allocation database resetclocks'

Check mode Checks allocation with index information; performs quick index checks for the entire database, a specific index, a specific index type, or a specific table. Detects all types of allocation problems and most types of index inconsistencies.

Run in check mode if metadata, null count, or distinct count errors are returned when running a query.

Verify mode Checks allocation with index information; performs detailed index checks for the entire database, a specific index, a specific index type, or a specific table. Detects all types of allocation problems and all types of index inconsistencies.

Run in verify mode if metadata, null count, or distinct count errors are returned when running a query.

Repair mode Performs a detailed check and repair of all indexes, a specific index, or a specific table. Does not check allocation.

Run in repair mode if index errors are reported in sp_iqcheckdb check or verify mode.

Notesp_iqcheckdb does not check referential integrity or repair referential integrity violations.

See Chapter 2, “System Recovery and Database Repair” in the Sybase IQ Troubleshooting and Recovery Guide for details on using sp_iqcheckdb and more information on checking database consistency.

Examples

The following examples illustrate the use of the sp_iqcheckdb procedure.

In this example, sp_iqcheckdb checks the allocation for the entire database:

sp_iqcheckdb 'allocation database'

In the second example, sp_iqcheckdb performs a detailed check on indexes i1, i2, and dbo.t1.i3. If you do not specify a new mode, sp_iqcheckdb applies the same mode to the remaining targets, as shown in the following command:

sp_iqcheckdb 'verify index i1 index i2 index dbo.t1.i3'

You can combine all modes, except for repair mode, and run multiple checks on a database in a single session. In the following example, sp_iqcheckdb performs a quick check of table t2, a detailed check of index i1, and allocation checking for the entire database using half of the CPUs:

sp_iqcheckdb 'check table t2 verify index i1
allocation database resources 50'

This example checks all indexes of the type FP in the database:

sp_iqcheckdb 'check indextype FP database'

The following example verifies the FP and HG indexes in the table t1 and the LF indexes in the table t2:

sp_iqcheckdb 'verify indextype FP indextype HG table t1 indextype LF table t2'

DBCC performance

The execution time of DBCC varies according to the size of the database for an entire database check, the number of tables or indexes specified, and the size of the machine. Checking only a subset of the database (that is, only specified tables, indexes, or index types) requires less time than checking an entire database.

Table 10-2 summarizes the actions and output of the four sp_iqcheckdb modes.

Table 10-2: Actions and output of sp_iqcheckdb modes

Mode

Errors detected

Output

Speed

allocation

Allocation errors

Allocation statistics only

4TB per hour

check

Allocation errors most index errors

All available statistics

60GB per hour

verify

Allocation errors All index errors

All available statistics

15GB per hour

repair

All index errors

Repair statistics

15+GB per hour*

* The processing time of sp_iqcheckdb repair mode depends on the number of errors repaired.

Output

The output of sp_iqcheckdb contains summary results, errors, informational statistics, and repair statistics, depending on the execution mode. The output may contain as many as three results sets, if you specify multiple modes in a single session. Error statistics are indicated by asterisks (*****) and are displayed only if errors are detected.

Repair statistics are displayed only in repair mode and only if repairs are actually made. Asterisks (*****) indicate repairs that were made, not errors. If sp_iqcheckdb encounters errors and makes repairs, some of the statistics reported by DBCC in repair mode might be inaccurate.

The output of sp_iqcheckdb is also copied to the Sybase IQ message file .iqmsg. If the DBCC_LOG_PROGRESS option is ON, sp_iqcheckdb sends progress messages to the IQ message file, allowing the user to follow the progress of the DBCC operation as it executes.

Output example

The following is an example of the output you see when you run sp_iqcheckdb 'allocation database' and there is leaked space. Leaked space is a block that is allocated according to the database free list (an internal allocation map), but DBCC finds that the block is not part of any database object. In this example, DBCC reports 32 leaked blocks.

                     Stat                      Value              Flags
=====================================|===========================|=====
DBCC Allocation Mode Report
=====================================|===========================|=====
** DBCC Status                       |Errors Detected            |*****
   DBCC Work units Dispatched        |163                        |
   DBCC Work units Completed         |163                        |
=====================================|===========================|=====
Allocation Summary                   |                           | 
=====================================|===========================|=====
   Blocks Total                      |8192                       | 
   Blocks in Current Version         |4954                       | 
   Blocks in All Versions            |4954                       | 
   Blocks in Use                     |4986                       | 
   % Blocks in Use                   |60                         | 
** Blocks Leaked                     |32                         |*****
                                     |                           |
=====================================|===========================|=====
Allocation Statistics                |                           | 
=====================================|===========================|=====
   Blocks Created in Current TXN     |382                        | 
   Blocks To Drop in Current TXN     |382                        | 
   Marked Logical Blocks             |8064                       | 
   Marked Physical Blocks            |4954                       | 
   Marked Pages                      |504                        | 
   Blocks in Freelist                |126553                     | 
   Imaginary Blocks                  |121567                     | 
   Highest PBN in Use                |5432                       | 
** 1st Unowned PBN                   |452                        |*****
   Total Free Blocks                 |3206                       | 
   Usable Free Blocks                |3125                       | 
   % Free Space Fragmented           |2                          |
   Max Blocks Per Page               |16                         | 
   1  Block Page Count               |97                         | 
   3  Block Page Count               |153                        | 
   4  Block Page Count               |14                         | 
   ...
   9  Block Hole Count               |2                          | 
   16 Block Hole Count               |194                        | 
                                     |                           | 
   Database Objects Checked          |1                          | 
   B-Array Count                     |1                          | 
   Blockmap Identity Count           |1                          | 
=====================================|===========================|=====
Connection Statistics                |                           | 
=====================================|===========================|=====
                                     |                           | 
                                     |                           |