Showing posts with label suspect mode. Show all posts
Showing posts with label suspect mode. Show all posts

Thursday, January 15, 2015

suspect pages errors

USE msdb

GO

SELECT * FROM dbo.suspect_pages


Event_type column gives different values

Errors Recorded in suspect_pages Table
The suspect_pages table contains one row per page that failed with an 824 error, up to a limit of 1,000 rows. The following table shows errors logged in the event_type column of the suspect_pages table.
Error descriptionevent_type value
823 error caused by an operating system CRC error or 824 error other than a bad checksum or a torn page (for example, a bad page ID) 1
Bad checksum2
Torn page3
Restored (The page was restored after it was marked bad)4
Repaired (DBCC, AlwaysOn, or mirroring repaired the page)5
Deallocated by DBCC7
The suspect_pages table also records transient errors. Sources of transient errors include an I/O error (for example, a cable was disconnected) or a page that temporarily fails a repeated checksum test.

  • How the Database Engine Updates the suspect_pages Table
    The Database Engine takes the following actions on the suspect_pages table:
    • If the table is not full, it is updated for every 824 error, to indicate that an error has occurred, and the error counter is incremented. If a page has an error after it is fixed by being repaired, restored, or deallocated, its number_of_errors count is incremented and its last_update column is updated
    • After a listed page is fixed by a restore or a repair operation, the operation updates the suspect_pages row to indicate that the page is repaired (event_type = 5) or restored (event_type = 4).
    • If a DBCC check is run, the check marks any error-free pages as repaired (event_type = 5) or deallocated (event_type = 7).

  • ---To clean up the suspect_pages table run the following

    delete s

    from msdb.dbo.suspect_pages s

    where event_type in (4,5,7)

    Tuesday, January 6, 2015

    Reasons for database to go to SUSPECT mode

    Possibility 1 : Someone deleted or misplaced a log/data file when SQL server was offline so the database could not start as it is missing a file.
    Solution : Put the missing file back on the location. SQL error log will give the  exact  location of the missing file.

    Possibility 2 : SQL server could not access to put an exclusive lock on the data/log file while the database was starting up . This could be caused when the data SQL server is shared with some other tool ( e.g. antivirus)
    Solution: Find  the file handler that placed an exclusive lock on the data/log file and kill it. Then run the following query.

    RESTORE DATABASE WITH RECOVERY

    Possibility 3 : Due to a corrupted transaction. This could likely be that the SQL server went down in the middle of the transaction and while coming back it could not complete ( COMMIT/ROLLBACK) the transaction.

    Solution: Switch to emergency mode and run the dbcc checkdb command

    Possibility 4: Some OS/hardware failure

    Monday, October 20, 2014

    suspect mode: database

    ---once the database goes to suspect mode
    --follow the steps to recover the database

    --1. reset the database from suspect mode
    --sp_resetstatus turns off the suspect flag on a database.
    --This procedure updates the mode and status columns of the named database in sys.databases.
    --Also note that only logins having sysadmin priveleges can perform this :


    use master
    GO
    exec sp_resetstatus 'db1';
    --2.set the database to emergency mode
    --Once the database is set to EMERGENCY mode it becomes a READ_ONLY copy
    --only members of sysadmin fixed server roles have privileges to access it.
    --The basic purpose for this is to facilitate troubleshooting

    alter database db1 set emergency;

    --3.run the consistency test
    dbcc checkdb(db1)

    --4. Roll the databse to single user mode
    use master
    GO
    ALTER DATABASE db1 SET SINGLE_USER
    WITH ROLLBACK IMMEDIATE


    --5. this query will attempt to repir all the reported loss. This query can cause some data loss
    dbcc checkdb('db1',REPAIR_ALLOW_DATA_LOSS)

    --6.finally bring the database ONLINE and set to multiuser mode
    ALTER DATABASE db1 SET MULTI_USER
    WITH ROLLBACK IMMEDIATE


    Monday, October 6, 2014

    restore msdb database

    USE master
    GO
    --just to verify if the below command succeeds the restore should succeed too
    RESTORE VERIFYONLY
    FROM DISK = N'V:\SANSQL01Backups\Daily\msdb\msdb_backup_2014_10_05_194001_4668459.bak'
    --restore the database
    RESTORE DATABASE [msdb]
    FROM DISK = N'V:\SANSQL01Backups\Daily\msdb\msdb_backup_2014_10_05_194001_4668459.bak'
    WITH REPLACE
    GO
    --msdb database was curripted and when to suspect mode. So fixed it by restoring a copy of a backup

    Wednesday, June 11, 2014

    Recovery database from suspect mode

    The database was in suspect mode, inaccessible Ran the following query Then restored from the latest full back up

    EXEC sp_resetstatus client_367
    ALTER DATABASE client_367 SET EMERGENCY
    use client_367
    DBCC checkdb
    ALTER DATABASE client_367 SET SINGLE_USER WITH ROLLBACK IMMEDIATE
    DBCC CheckDB ('client_367', REPAIR_ALLOW_DATA_LOSS)
    ALTER DATABASE client_367 SET MULTI_USER