标签:
DBCC CheckDB command 的使用分为三步
1,verify AUTO_UPDATE_STATISTICS_ASYNC option 关闭
--verify the AUTO_UPDATE_STATISTICS_ASYNC option is set to OFF select db.name, db.is_auto_update_stats_async_on from sys.databases db
2 设置DB 处于single user 访问模式
--set single user can access database
alter database db_study
set single_user with ROLLBACK IMMEDIATE
Syntax
ALTER DATABASE database_name
SET <db_user_access_option>
[ WITH <termination> ]
<db_user_access_option> ::=
{ SINGLE_USER | RESTRICTED_USER | MULTI_USER }
<termination> ::=
{
ROLLBACK AFTER integer [ SECONDS ]
| ROLLBACK IMMEDIATE
| NO_WAIT
}
<db_user_access_option> ::=
Controls user access to the database.
Specifies that only one user at a time can access the database. If SINGLE_USER is specified and there are other users connected to the database the ALTER DATABASE statement will be blocked until all users disconnect from the specified database. To override this behavior, see the WITH <termination> clause.
The database remains in SINGLE_USER mode even if the user that set the option logs off. At that point, a different user, but only one, can connect to the database.
Before you set the database to SINGLE_USER, verify the AUTO_UPDATE_STATISTICS_ASYNC option is set to OFF. When set to ON, the background thread used to update statistics takes a connection against the database, and you will be unable to access the database in single-user mode. To view the status of this option, query the is_auto_update_stats_async_on column in the sys.databases catalog view. If the option is set to ON, perform the following tasks:
Set AUTO_UPDATE_STATISTICS_ASYNC to OFF.
Check for active asynchronous statistics jobs by querying the sys.dm_exec_background_job_queue dynamic management view.
If there are active jobs, either allow the jobs to complete or manually terminate them by using KILL STATS JOB.
RESTRICTED_USER allows for only members of the db_owner fixed database role and dbcreator and sysadmin fixed server roles to connect to the database, but does not limit their number. All connections to the database are disconnected in the timeframe specified by the termination clause of the ALTER DATABASE statement. After the database has transitioned to the RESTRICTED_USER state, connection attempts by unqualified users are refused.
All users that have the appropriate permissions to connect to the database are allowed.
The status of this option can be determined by examining the user_access column in the sys.databases catalog view or the UserAccess property of the DATABASEPROPERTYEX function.
WITH <termination> ::=
Specifies when to roll back incomplete transactions when the database is transitioned from one state to another. If the termination clause is omitted, the ALTER DATABASE statement waits indefinitely if there is any lock on the database. Only one termination clause can be specified, and it follows the SET clauses.
ROLLBACK AFTER integer [SECONDS] | ROLLBACK IMMEDIATE
Specifies whether to roll back after the specified number of seconds or immediately.
Specifies that if the requested database state or option change cannot complete immediately without waiting for transactions to commit or roll back on their own, the request will fail.
3,exec dbcc checkdb command
The Repair_rebuild option attempts to repair errors only when losing data is not possible.
--exec dbcc checkdb dbcc checkdb(‘db_study‘,repair_rebuild)
The Repair_Allow_Data_Loss option attempts to repair all errors, including those in which data will likely be lost(the option name was carefully chosen).
--exec dbcc checkdb command dbcc checkdb(‘db_study‘,repair_allow_data_loss)
Syntax
DBCC CHECKDB [ [ ( database_name | database_id | 0 [ , NOINDEX | , { REPAIR_ALLOW_DATA_LOSS | REPAIR_FAST | REPAIR_REBUILD } ] ) ] [ WITH { [ ALL_ERRORMSGS ] [ , EXTENDED_LOGICAL_CHECKS ] [ , NO_INFOMSGS ] [ , TABLOCK ] [ , ESTIMATEONLY ] [ , { PHYSICAL_ONLY | DATA_PURITY } ] } ] ]
MSDN URL:https://msdn.microsoft.com/zh-cn/library/ms176064.aspx
4,将db的access mode 切换到multiple user
-- switch to multiple user access mode alter database [SIS_DataWarehouseV2_SIS] set MULTI_USER with ROLLBACK IMMEDIATE
5, 查看 msdb.dbo.suspect_pages
url:https://msdn.microsoft.com/en-us/library/ms191301(v=sql.110).aspx
参考文档:
https://msdn.microsoft.com/en-us/library/bb522682.aspx
标签:
原文地址:http://www.cnblogs.com/ljhdo/p/5057323.html