Solved

DBCC CHECKDB issue

Posted on 2011-09-06
13
1,234 Views
Last Modified: 2012-05-12
Hi,

I have server called Prod-1(SQL SERVER 2005) and this server contains around 78 databases. I am using below script to run database integrity check against all databases in the instance.

EXEC sp_Msforeachdb "DBCC checkdb ('?') with physical_only"

The Job schedule details are as follows (I have scheduled job through SQL Agent) :

Occurs every week on Monday, Tuesday, Wednesday, Thursday, Friday at 10:00:00 PM EST.

Using below script, I am checking HISTORY OF CHECKDB (LASTRUNCHECKDB DATE).

CREATE TABLE #temp (
       Id INT IDENTITY(1,1),
       ParentObject VARCHAR(255),
       [Object] VARCHAR(255),
       Field VARCHAR(255),
       [Value] VARCHAR(255)
)

INSERT INTO #temp
EXECUTE SP_MSFOREACHDB'DBCC DBINFO ( ''?'') WITH TABLERESULTS';

;WITH CHECKDB1 AS
(
    SELECT [Value],ROW_NUMBER() OVER (ORDER BY ID) AS rn1 FROM #temp WHERE Field IN ('dbi_dbname'))
    ,CHECKDB2 AS ( SELECT [Value], ROW_NUMBER() OVER (ORDER BY ID) AS rn2 FROM #temp WHERE Field IN ('dbi_dbccLastKnownGood')
)      
SELECT CHECKDB1.Value AS DatabaseName
        , CHECKDB2.Value AS LastRanDBCCCHECKDB
FROM CHECKDB1 JOIN CHECKDB2
ON rn1 =rn2

DROP TABLE #temp


As per output (PFA file - DBCC CHECKDB HISTORY), the job is not performing integrity check on all 78 databases. It was MISSING/SKIPPING some databases integrity check.

Alternatively i have modified job using below script by removing PHYSICAL_ONLY option, still it was skipping some databases.

EXEC sp_Msforeachdb "DBCC checkdb ('?')

I have searched in net, but i didn't find any solutions for my issue (why it was missing/skipping some databases integrity check).

Please share your experience/suggestions/solutions on my above issue.

Thanks in Advance.


DBCC-History.xls
0
Comment
Question by:sg05121983
  • 7
  • 5
13 Comments
 
LVL 19

Expert Comment

by:Rimvis
ID: 36493676
Hi sg05121983,

did you check SQL Server logs?
0
 
LVL 12

Expert Comment

by:sachitjain
ID: 36493892
Can u manually do DBCC CHECKDB (<DBName>) for databases that are being missed? It may give u some clue.
0
 

Author Comment

by:sg05121983
ID: 36494287
@Rimvis : In error log, there is no error related to integrity check.

@Sachitjain : Executed manually for some DB's, there is no error realated to DBCC CHECKDB/Integrity Check and command executed sucessfully.

 Any thoughts?
0
 
LVL 12

Expert Comment

by:sachitjain
ID: 36494416
No idea what's going wrong with sp_Msforeachdb. But following link suggests an alternative way that should work for you.
http://weblogs.sqlteam.com/tarad/archive/2004/06/16/1606.aspx
0
 

Author Comment

by:sg05121983
ID: 36500474
Hi Sachitjain,

I have tried the script in given link, the results are same that is it is still skipping some databases and LastRunDBCCdate is not showing dbcc checkdb execution date.
0
 
LVL 12

Expert Comment

by:sachitjain
ID: 36500707
Strange!!
Pls run following query and check whether missing dbs are actually being returned by it.

SELECT TOP 1 @dbid = dbid, @DBName = name
 FROM master.dbo.sysdatabases
 WHERE dbid > @dbid
 ORDER BY dbid

Where exactly are you looking for this LastRunDBCCDate? There is one more link that could help you to find out last clean run.
http://sqlserverpedia.com/wiki/Last_clean_DBCC_CHECKDB_date
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

Author Comment

by:sg05121983
ID: 36502675
Hi Sachitjain,

I have executed proc dbo.GetLastRanCleanDBCCCHECKDBForAllDatabases( in above link), i got the below output:

DBCC execution completed. If DBCC printed error messages, contact your system administrator.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
Msg 911, Level 16, State 1, Line 1
Could not locate entry in sysdatabases for database 'X20'. No entry found with that name. Make sure that the name is entered correctly.

The above mentioned DB (X20), DBCC checkDB executed sucessfully as per scheduled time. I mean this DB was not there in missing/skipping list.
0
 
LVL 12

Expert Comment

by:sachitjain
ID: 36508125
Is this db X20 coming in the list of dbs being fetched through following query

SELECT TOP 1 @dbid = dbid, @DBName = name
 FROM master.dbo.sysdatabases
 WHERE dbid > @dbid
 ORDER BY dbid

0
 

Author Comment

by:sg05121983
ID: 36510236
I got the below error:

Msg 137, Level 15, State 1, Line 1
Must declare the scalar variable "@dbid".
0
 

Author Comment

by:sg05121983
ID: 36510270
declare @dbid varchar(200)
declare @dbname varchar(200)

SELECT TOP 1 @dbid = dbid, @DBName = name
 FROM master.dbo.sysdatabases
 WHERE dbid > @dbid
 ORDER BY dbid

No records from above query
0
 
LVL 12

Assisted Solution

by:sachitjain
sachitjain earned 500 total points
ID: 36515221
Oh OK try this out

Select dbid, [name] from master.dbo.sysdatabases
If your missing dbs are not listed in the output list, follow these steps.
1.> Take manual backup of those dbs
2.> Restore them on same server instance with different name
3.> Drop existing missing dbs
4.> Rename newly restored versions with old names (that of missing and dropped in step3)

This would actually resurrect the internal configuration of your dbs if it is not correct and your dbs are not getting listed.
0
 

Accepted Solution

by:
sg05121983 earned 0 total points
ID: 36522227
Thanks Sachitjain for your help.
0
 

Author Closing Comment

by:sg05121983
ID: 36553421
--
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Filtered index 5 55
tempdb latch contention 12 47
TSQL DateADD update Question 4 25
Getting same value for every field in SQL 2 21
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now