Вы находитесь на странице: 1из 4

SQL Server Interview: How do we troubleshoot database in suspect mode.What are reasons for database going in suspect mode?

It is good to resotre from the available backup. If we donot have backup, follow the below steps: Step 1: Clear the suspect mode of the database using sp_resetstatus DatabaseName. This will clear the suspect flag and make the database available online. Step 2: Change the database status to Emergency using the following command. Emergency mode allows you to access the databases as normal but with no consistency guarantee. This option also allows us to export the table data so that we can minimize the damage. ALTER DATABASE DatabaseName SET EMERGENCY; Step 3: Restrict database to single user by changing the access mode as mentioned below ALTER DATABASE DatabaseName SET SINGLE_USER; Step 4: Run the CHECKDB command with REPAIR_ALLOW_DATA_LOSS option. This option should be tried as last option as it always behaves the way it is named. We are not sure of what data it removes. DBCC CHECKDB (DatabaseName, REPAIR_ALLOW_DATA_LOSS) WITH NO_INFOMSGS, ALL_ERRORMSGS; There are some best (simple) practices which prevents us from such failures. Below are some of them Backup your data frequently ( daily or once in two days) Have multiple backups. Move the backups to external drives or tapes frequently Validate that your backups are good by doing trial restores to alternate server Run CHECKDB regularly

Most common causes for suspect status are missing devices, invalid data files/drives, insufficient disk space, interruption during restore etc. We should see some indication in error log saying what might be cause.

Moving the database files from one drive to another on the same instance. We can user backup and restore or detach and attach to move the files. We can also use the below t-sql statements to move the files. USE master; GO -- Return the logical file name. SELECT name, physical_name AS CurrentLocation, state_desc FROM sys.master_files WHERE database_id = DB_ID(N'AdventureWorks2012') AND type_desc = N'LOG'; GO ALTER DATABASE AdventureWorks2012 SET OFFLINE; GO -- Physically move the file to a new location. -- In the following statement, modify the path specified in FILENAME to -- the new location of the file on your server. ALTER DATABASE AdventureWorks2012 MODIFY FILE ( NAME = AdventureWorks2012_Log, FILENAME = 'C:\NewLoc\AdventureWorks2008R2_Log.ldf'); GO ALTER DATABASE AdventureWorks2012 SET ONLINE; GO --Verify the new location. SELECT name, physical_name AS CurrentLocation, state_desc FROM sys.master_files WHERE database_id = DB_ID(N'AdventureWorks2012') AND type_desc = N'LOG';

How to find last backup taken of a database? Right click on the database goto properties in the general tab we find the last backup taken date and time. Or Right click the database goto Reports->Backup and Restore events How to find the last restore date of a database? Use MSDB Select *from RestoreHistory RestoreHistory- This tables maintains the information about the restore history which is in MSDB database. Or Right click the database goto Reports->Backup and Restore events. Troubleshooting Full Transaction Log(Error 9002) When the transaction log becomes full, SQL Server Database Engine issues a 9002 error. The log can fill when the database is online or in recovery. If the log fills while the database is online, the database remains online but can only be read, not updated. If the log fills during recovery, the Database Engine marks the database as RESOURCE PENDING. In either case, user action is required to make log space available. How can we move the files from one file group to other? Once a data file is created as part of the filegorup, we cannot move the files directly to another filegroup. If we want to move to another filegorup, we must first empty it by relocating any data present in that file to other files in the same filegroup using the command: DBCC shrinkfile(Test_DB,EmptyFile); Once emptied, we can delete the file and recreate it on the other filegroup.

Вам также может понравиться