Database consistency checker (dbcc) checks the logical and physical consistency of a database and provides statistics, planning, and repair functionality.
Certain dbcc commands apply only to shared-disk clusters. See the separately listed dbcc syntax for clusters.
dbcc addtempdb (dbid |database_name)
dbcc checkalloc [(database_name[, fix | nofix])]
dbcc checkcatalog [(database_name[, fix])
dbcc checkdb [(database_name[, skip_ncindex])]
dbcc checkindex ({table_name | table_id}, index_id [, bottom_up[, partition_name | partition_id]])
dbcc checkstorage [(database_name)]
dbcc checktable (table_name | table_id [, skip_ncindex | fix_spacebits | "check spacebits" | bottom_up | NULL[, partition_name | partition_id)
dbcc checkverify (dbname[, tblname[, ignore_exclusions]])
dbcc complete_xact (xid, {["commit", “1pc”] | "rollback"})
dbcc dbrepair (database_name, dropdb, flushthreshold)
dbcc engine ({offline, [enginenum] | "online"})
dbcc fix_text ({table_name | table_id})
dbcc forget_xact (xid)
dbcc indexalloc (table_name | table_id, index_id [, optimized | fast | NULL [, fix | nofix | NULL [, partition_name | partition_id]]])
dbcc monitor (increment, <group name>)
dbcc monitor (decrement, <group name>)
dbcc monitor (reset, <group name>)
dbcc pravailabletempdbs
dbcc rebuild_text (table_name | table_id | "all"[, column[, text_page [, data_partition_name | data_partition_id]]])
dbcc reindex ({table_name | table_id})
dbcc serverlimits
dbcc stackused
dbcc tablealloc (table_name | table_id [, full | optimized | fast | NULL [, fix | nofix | NULL [, data_partition_name | data_partition_id]]])
dbcc textalloc (table_name | table_id [, full | optimized | fast | NULL [, fix | nofix | NULL [, data_partition_name | data_partition_id]]])
dbcc {traceon | traceoff} (flag [, flag ...])
dbcc tune ({ascinserts, {0 | 1} , table_name | cleanup, {0 | 1} | cpuaffinity, start_cpu {, on| off} | des_greedyalloc, dbid, object_name, " {on | off}" | deviochar vdevno, "batch_size" | des_bind, dbid, object_name des_unbind, dbid, object_name doneinproc {0 | 1}})
dbcc upgrade_object [ ( dbid | dbname [,[database.[owner].]compiled_object_name' | 'check' | 'default' | 'procedure' | 'rule' | 'trigger' | 'view' [, 'force' ] ] )
dbcc zapdefraginfo
dbcc nodetraceon(trace_flag_number) dbcc nodetraceoff(trace_flag_number)
dbcc set_scope_in_cluster("cluster"|"instance"|"scope")
dbcc quorum
checkalloc reports on the amount of space allocated and used.
checkcatalog also reports on any segments that have been defined. If no database name is given, checkcatalog checks the current database.
Data pages are not allocated in an extent reserved for OAM pages as per the layout.
The OAM pages are allocated only in the first extent of an allocation unit.
No one can use the database being dropped when this dbcc statement is issued (including the user issuing the statement).
Changing to a multibyte character set makes the internal management of text data more complicated. Since a text value can be large enough to cover several pages, the SAP ASE server must be able to handle characters that span page boundaries. To do so, the server requires additional information on each of the text pages. The system administrator or table owner must run dbcc fix_text on each table that has text data to calculate the new values needed. See the System Administration Guide.
indexalloc produces the same three types of reports as tablealloc: full, optimized, and fast. If no type is indicated, or if you use null, the SAP ASE server uses optimized. The fix | nofix option functions the same with indexalloc as with tablealloc.
You can specify fix or nofix only if you include a value for the type of report (full, optimized, fast, or null).
group name can be one of the following:
‘all’ – determine usage count for the all group, which comprises most of the monitor counters, by selecting the @@monitors_active global variable.
spinlock_s – usage counts for spinlock_s reported by the dbcc resource command.
appl – usage counts for appl reported by the dbcc resource command.
When dbcc finds corrupt indexes, it drops and re-creates the appropriate indexes. If the indexes for a table are already correct, or if the table has no indexes, dbcc reindex does not rebuild the index, but prints an informational message instead.
dbcc reindex aborts if a table is suspected of containing corrupt data. When that happens, an error message instructs the user to run dbcc checktable. dbcc reindex does not allow reindexing of system tables. System indexes are checked and rebuilt, if necessary, as an automatic part of recovery after the SAP ASE server is restarted following a sort order change.
Three types of reports can be generated with tablealloc: full, optimized, and fast. If no type is indicated, or if you use null, the SAP ASE server uses optimized.
You can specify fix or nofix only if you include a value for the type of report (full, optimized, fast, or null).
Parameters |
Description |
---|---|
dbid |
Specifies the database ID. If you do not specify dbid, all compiled objects in the current database are upgraded. |
dbname |
Specifies the database name. If you do not specify dbname, all compiled objects in the current database are upgraded. |
compiled_object_name |
Is the name of a specific compiled object you want to upgrade. If you use the fully qualified name, dbname and database must match, and you must enclose the fully qualified name in quotes. If the database contains more than one compiled object of the same name, use the fully qualified name. Otherwise, all objects with the same name are parsed, and if no errors are found, upgraded. |
check |
Upgrades all check constraints and rules. Referential constraints are not compiled objects and do not require upgrading. |
default |
Upgrades all declarative defaults and the defaults created with the create default command. |
procedure |
Upgrades all stored procedures. |
rule |
Upgrades all rules and check constraints. |
trigger |
Upgrades all triggers. |
view |
Upgrades all views. |
force |
Specifies that you want to upgrade the specified object even if it contains a select * clause. Do not use force unless you have confirmed that the select * statement is not returning unexpected results. The force option does not upgrade objects that contain reserved words, contain truncated or missing source text, refer to nonexistent temporary tables, or do not match the quoted identifier setting. You must fix these objects before they can be upgraded. |
The keywords check, default, procedure, rule, trigger, and view specify the classes of compiled objects to be upgraded. When you specify a class, all objects in that class, in the specified database, are upgraded, provided that dbcc upgrade_object finds no errors or potential problem areas.
For upgrade_object, upgrades all check constraints and rules. Referential constraints are not compiled objects and do not require upgrading.
The keywords check, default, procedure, rule, trigger, and view specify the classes of compiled objects to be upgraded. When you specify a class, all objects in that class, in the specified database, are upgraded, provided that dbcc upgrade_object finds no errors or potential problem areas.
In a running server, if the rows with defragmentation information for a specific object are accidentally lost from sysattributes, use zapdefraginfo to reset the extent version information for the specific object so that a later reorg defrag will not fail to consider all the extents of the object.
dbcc checkalloc (pubs2)
dbcc checkstorage (pubs2)
dbcc checktable (salesdetail)
Checking salesdetail The total number of pages in partition 1 is 3. The total number of pages in partition 2 is 1. The total number of pages in partition 3 is 1. The total number of pages in partition 4 is 1. The total number of data pages in this table is 10. Table has 116 data rows. DBCC execution completed. If DBCC printed error messages, contact a user with system administrator (SA) role.
dbcc complete_xact (distributedxact1, "rollback")
dbcc fix_text (blurbs)
dbcc checkverify(my_db, tab)
dbcc checkverify (my_db, tab, 0)
dbcc checkverify (my_db, tab, 1)
dbcc forget_xact (distributedxact1)
dbcc indexalloc ("pubs..titleauthor", 2, full)
dbcc pravailabletempdbs
Available temporary databases are: Dbid: 2 Dbid: 4 Dbid: 5 Dbid: 6 Dbid: 7 DBCC execution completed. If DBCC printed error messages, contact a user with system administrator (SA) role.
dbcc rebuild_text (blurbs)
dbcc checktable (titles, NULL, "smallsales")
dbcc reindex (titles)
One or more indexes are corrupt. They will be rebuilt.
dbcc stackused
dbcc upgrade_object(listdb, 'procedure')
dbcc upgrade_object(listdb, list_proc)
dbcc serverlimits
Limits independent of page size: ================================ Server-wide, Database-specific limits and sizes Max engines per server : 128 Max number of logins per server : 2147516416 Max number of users per database : 2146484223 Max number of groups per database : 1032193 Max number of user-defined roles per server : 1024 Max number of user-defined roles per (user) session : 127 Min database page size : 2048 Max database page size : 16384 ... Database page-specific limits APL page header size : 32 DOL page header size : 44 Max reserved page gap : 255 Max fill factor : 100 Table, Index related limits Max number of columns in a table/view : 1024 Max number of indexes on a table : 250 Max number of user-keys in a single index on an unpartitioned table : 31 Max number of user-keys in a single local index on a partitioned table : 31 ... General SQL related Max size of character literals, sproc parameters : 16384 Max size of local @variables in T-SQL : 16384 Max number of arguments to stored procedures : 2048 Max number of arguments to dynamic SQL : 2048 Max number of aggregates in a COMPUTE clause : 254 ... Maximum lengths of different Identifiers Max length of server name : 30 Max length of host name : 30 Max length of login name : 30 Max length of user name : 30 ... Limits as a function of the page size: ====================================== Item dependent on page size : 2048 4096 8192 16384 -------------------------------------------------------------------------- Server-wide, Database-specific limits and sizes Min number of virtual pages in master device : 11780 22532 45060 90116 Default number of virtual pages in master device : 23556 45060 90116 180228 Min number of logical pages in master device : 11776 11264 11264 11264 Min number of logical pages in tempdb : 2048 1536 1536 1536 Table-specific row-size limits Max possible size of a log-record row on APL log page : 2014 4062 8158 16350 Physical Max size of an APL data row, incl row-overheads : 1962 4010 8106 16298 Physical Max size of a DOL data row, incl row-overheads : 1964 4012 8108 16300 Max user-visible size of an APL data row : 1960 4008 8104 16296 Max user-visible size of a DOL data row : 1958 4006 8102 16294 Max user-visible size of a fixed-length column in an APL table : 1960 4008 8104 16296 Max user-visible size of a fixed-length column in a DOL table : 1958 4006 8102 16294 ...
dbcc tablealloc (publishers, null, nofix)
dbcc tablealloc (titles, null, null, smallsales)
sp_transactions
xactkey type coordinator starttime state connection dbid spid loid failover srvnname namelen xactname ------------------------------ ------- ----------- --------- ------------- ---------- ---- ---- ---- -------- --------- -------- ------------- 0xbc0500000b00000030c316480100 External XA Feb 2 2004 1:07PM Done-Detached Detached 1 0 2099 Resident Tx NULL 88 28_u7dAc31Wc380000000000000000000000000000000001HFpfSxkDM000FU_00003M00 00Y_:SYBBEV0A_LRM (1 row affected) (return status = 0)
dbcc complete_xact ("28_u7dAc31Wc380000000000000000000000000000000001HFpfSxkDM000FU_00003M0000Y_:SYBBEV0A_LRM", "commit"))
Msg 3947, Level 16, State 1: Server 'PISSARRO_1251_P', Line 1: A heuristic completion related operation failed. Please see errorlog for more details. DBCC execution completed. If DBCC printed error messages, contact a user with system administrator (SA) role.
dbcc complete_xact ("28_u7dAc31Wc380000000000000000000000000000000001HFpfSxkDM000FU_00003M0000Y_:SYBBEV0A_LRM", "commit", "1pc")
DBCC execution completed. If DBCC printed error messages, contact a user with system administrator (SA) role.
dbcc forget_xact ("28_u7dAc31Wc380000000000000000000000000000000001HFpfSxkDM0 00FU_00003M0000Y_:SYBBEV0A_LRM") DBCC execution completed. If DBCC printed error messages, contact a user with system administrator (SA) role.
If you run sp_transactions again, the previous transaction does not appear:
sp_transactions
xactkey type coordinator starttime state connection dbid spid loid failover srvnname namelen xactname -------- ----- ------------ ---------- ------ ----------- ----- ----- ------ --------- --------- -------- -------- (0 row affected)
dbcc nodetraceoff(3604)
DBCC execution completed. If DBCC printed error messages, contact a user with system administrator (SA) role.
dbcc set_scope_in_cluster('cluster')
dbcc set_scope_in_cluster('instance')
dbcc set_scope_in_cluster('scope')
dbcc checkstorage reports a soft fault if any data page that is not the first data page is empty for nonhashed tables. However, dbcc checkstorage does not report this soft fault for the hashed region of a virtually-hashed table. Any data page in the hashed region of a virtually-hashed table can be empty.
You can run dbcc while the database is active, except for the dbrepair (database_name, dropdb) option and dbcc checkalloc with the fix option.
dbcc locks database objects as it checks them. For information on minimizing performance problems while using dbcc, see the dbcc discussion in the System Administration Guide.
When dbcc commands are executing, users cannot access an archive database. If you attempt to access an archive database while dbcc commands are being performed, you receive a message saying that the database is in single-user mode.
Most dbcc commands work with in-memory and relaxed durability databases.
Create a table
dbcc tune(des_bin, 4, new_table)
begin tran lock table new_table in exclusive mode go
Msg 8242, Level 16, State 1: Server 'server01', Line 2: The table ‘new_table’ in database 'big_db' is bound to metadata cache memory. Unbind the table and retry the query later.
You can use variants of the dbcc commands on an archive database that is online or offline. However, you can use dbcc with a fix option only on an online archive database.
dbcc tablealloc ("pubs2.pogo.testtable")
You cannot run dbcc reindex within a user-defined transaction.
dbcc fix_text can generate a large number of log records, which may fill up the transaction log. dbcc fix_text is designed so that updates are performed in a series of small transactions: in case of a log space failure, only a small amount of work is lost. If you run out of log space, clear your log and restart dbcc fix_text using the same table that was being upgraded when the original dbcc fix_text failed.
Load a dump from a production system of the earlier version of the SAP ASE server into a test system of the current version SAP ASE server, or
In a warm standby application, initialize a standby database of the current version of the SAP ASE server with a database dump from an active database of the earlier version of the SAP ASE server.
If you attempt to use select, readtext, or writetext on text values after changing to a multibyte character set, and you have not run dbcc fix_text, the command fails, and an error message instructs you to run dbcc fix_text on the table. However, you can delete text rows after changing character sets without running dbcc fix_text.
dbcc output is sent as messages or errors, rather than as result rows. Client programs and scripts should check the appropriate error handlers.
If a table is partitioned, dbcc checktable returns information about each partition.
text and image data that has been upgraded to SAP ASE version 12.x or later is not automatically upgraded from its original storage format. To improve query performance and enable prefetch for this data, use the rebuild_text keyword against the upgraded text and image columns.
The amount of stack memory used in the past is only an indication of possible future needs. The SAP ASE server may require more stack memory than it used in the past. Periodically run dbcc stackused to find your current stack memory usage.
dbcc upgrade_object check is used to detect syscomments text corruption caused by SAP ASE defects that occurred before you upgraded the SAP ASE server. This syscomments text corruption is serious because it causes the upgrade process to fail.
If any error is reported by dbcc upgrade_object check, you must drop and re-create the compiled_object.
(Cluster Edition only) dbcc traceon and dbcc traceoff apply trace flags for the entire cluster, while dbcc nodetraceoff and dbcc nodetraceon apply trace flags locally.
See also sp_configure, sp_helpdb in Reference Manual: Procedures.
ANSI SQL – Compliance level: Transact-SQL extension.
The permission checks for dbcc commands differ based on your granular permissions settings. This table shows the permission requirement for each dbcc command.
DBCC Command Name |
Permission Requirement |
|
---|---|---|
Granular Permissions Disabled |
Granular Permissions Enabled |
|
addtempdb |
|
|
checkalloc |
|
|
checkcatalog |
|
|
checkdb |
|
|
checkindex |
|
|
checkstorage |
|
|
checktable |
|
|
checkverify |
|
|
cis showcaps |
|
|
cis remcon |
|
|
complete_xact |
|
|
dbrepair dropdb |
|
|
engine |
|
|
fix_text |
|
|
forget_xact |
|
|
indexalloc |
|
|
monitor |
|
|
pravailabletempdbs |
|
|
quorum |
|
|
rebuild_text |
|
|
reindex |
|
|
serverlimits |
|
|
set_scope_in_cluster |
|
|
stackused |
|
|
tablealloc |
|
|
textalloc |
|
|
trace flags – 3604, 3605 |
|
|
all other trace flags |
|
|
tune ascinserts |
|
|
tune all other parameters |
|
|
upgrade_object |
|
|
Values in event and extrainfo columns of sysaudits are:
Information | Values |
---|---|
Event | 81 |
Audit option | dbcc |
Command or access audited | dbcc |
Information in extrainfo |
|