Wednesday, 24 August 2016

How to Prevent SQL Database Corruption in An Efficient Manner

Overview

As many companies rely on SQL Server Database for the storage of their data, database administrators need to make sure that the database is made available whenever required without failure. In order to ensure that, he/she needs to make sure that the data integrity is maintained all the time and the database files is free from corruption issues. As any other file formats, SQL Server Database files can be corrupted, which may even lead to permanent loss of data. In the content, we will be focusing about the corruption issues and learn ways to prevent Corruption in SQL Server.

About SQL Database Corruption

The top most priority among all the concerns that DBAs needs to be worried are disaster prevention and recovery of SQL Server Database. The SQL Server Database is said to be corrupt state if a problem arises with the improper storage of the actual zeroes and ones required to store data at disk or I/O subsystem. Corruption can also be caused by errors or failures in the storage media or the irregular system shutdown. There can be several reasons behind the database corruption:

Causes of SQL Database Corruption

Following are the database corruption causes:

  • Almost all the causes of corruption in SQL Server Database is related to issues at the IO subsystem level i.e., problems related to drives, controllers and even drivers.
  • One thing to keep in mind is to use disk-check utility (CHKDSK) available in most of the systems to scan bad sectors, modifies entries or other storage issues that can lead to corruption.
  • SQL Server depends on disk system to store/retrieve data, which is why most of the disk related issues leads to corruption.
  • Another reason are usage of Anti-virus or Kernel drivers can lead to corruption that is why Experts recommend to exclude SQL Server database files at the time of anti-virus scans.
  • Keeping SQL Server Database files in compressed format to conserve disk storage increases the chance of making files corrupted.

It should be kept in mind that the SQL Server Database is going to be corrupted one day or another. It is just the matter of when it is going to happen. So it is better to prepare a plan for preventing SQL Server database from corruption.

How to Prevent Corruption in SQL Server database ?

Though it is not practically possible to prevent corruption in SQL Server Database, we need to know how to deal with them to ensure data availability and uptime of data even when corruption occurs. SQL Server even accepts the disk system errors and provides functionality to address corruption when it occurs. Accordingly, with the help of these functions, it is possible to protect against the consequences that corruption might cause. The best way to deal with database corruption in SQL Server is to be able to detect it at the earliest time possible and address it before it is too late.

In some of the cases, it has been found that corruption that has been encountered go unnoticed for long time if the pages or locations has not been queried that were affected by corruption. Let us create a scenario where a database containing sensitive data is in corrupt state. In this database, user writes data almost every day and the data is not queried regularly, as it done only after every 2 months. It is quite possible that the corruption in this database can go unattended for more than a month. If the organization uses rolling backups, it may hamper the ability to address the corruption problem since backups that could have been used to recover from this problem will have been lost. However, if the problem was noticed earlier in just a few days after its occurrence, the corruption issues are likely to be addressed and resolved soon.

Hence, the most important thing that we need to know while dealing with corruption issues in SQL Server Database is to have possibilities to resolve them, which is available only when the corruption is discovered at the early stage. Otherwise, it may become quite difficult to deal with such issues.

Conclusion

In most of the organizations, corruption cases do not only bring risks to data but also bring negative impact to the business flow and revenues. Database Administrators should be able to find ways preventing Corruption in SQL Server. Even if the database is in corrupt state, they should be able to detect the corruption at the earliest time to take required actions for the prevention of permanent data loss. Regular backups needs to be taken, as it provides one and only way to restore data in case of any disaster. The article has been aimed to focus on the corruption in SQL Server Database and approaches preventing corruption in SQL Server in an efficient manner. However, if despite applying all possible fixes one doesn't succeed in preventing SQL Server corruption then going with SQL database recovery software is best to overcome the data loss.

Monday, 21 March 2016

SQL Log File Corruption and Possible Recovery Methods

Structured Query Language (commonly known as SQL) is a programming language used for managing data held in relational database management system (RDMS) consisting of data definition language, data manipulation language and a data control language. The SQL database comprises of following three files:

  1. Primary Database files- Primary database file is the main database file (MDF) which points to another file in database and hence every database has one primary data file. The file is in the extension of .mdf
  2. Secondary Database files- When the data of a database exceeds then a secondary database file is created which stores the data that exceeds MDF limit. Hence, multiple secondary data files can be created for a single database. The file is in the extension of .ndf
  3. Log files- These files maintains a log of all the transactions done in SQL Server Database so that those information can be later used to recover the database. There must exist one log file for each database and it is possible that more than one log file can be created for a single database. The file is in .ldf file extension.

Log files (also known as transaction log) consist of actions executed on database for database management to guarantee ACID properties over crashes or hardware failure. It is a file listing changes to the database, stored in a stable storage format

Problem

The log files of the SQL server gets corrupted i.e. while the time we are performing some action upon SQL database, their exist some errors in between the process and due to which there is an interrupt in process

Causes of Log File Corruption in SQL Server

  • Viruses or other Malicious Software- In computer system, many viruses can infect and damage the log files and makes them inaccessible.
  • Terminating System Abnormally- If system/application is quit abnormally, then files are prone to be corrupted or damaged.
  • Input Output Configuration- The I/O subsystem is a vital component of database used to store system and user databases. Hence if the configuration is disturbed on enhanced that it may lead to corruption in log files.
  • Storage Size Issue- The biggest reason behind the corruption of log files is the storage size. In case the data exceeds the limit of LDF, corruption is likely to occur.

Errors which Occurs Due to Log File Corruption

  • Error Message 1: StartLogFiles: The error exists when the log files are unable to start because system could not find the file specified. So try to diagnose and correct the operating system error, and retry the operation.
  • Error Message 2: File activation failure. The error occurs due to error in file on location‘C:\ProgramFiles\MSSQLServer\MSSQL10_50.SQLEXPRESS\MSSQL\Log\ERRORLOG’.
  • Error Message 3: The error message displays that the transaction log has been deleted or lost due to a hardware failure of system or any other reason. The log files cannot be redeveloped because users perform open transactions on file.
  • Error Message 4: Corrupted server of SQL database leads to corruption in backup of log files.
  • Error Message 5: When database log is corrupted and user is attempting to attach the log file to new server then an error message displays with a message that ‘Could not open new database (Name of Database). CREATE DATABASE is aborted.
  • Error Message 6: When the log database is attempted to attach but it gives an error while performing the attachment. The error displays one of the two number i.e. 9004 or 9001 notifying that you have to create a backup or it is necessary to rebuild the log.

How to Recover Corrupted Log File in SQL Server?

In order to repair a corrupt LDF file, use the WITH TABLOCK option for DBCC CHECKDB. It will recover the data from a corrupted LDF file that has been corrupted or damaged due to some reason such as logical corruption.

Conclusion

Through the above solution, we can recover SQL log file but not sure that the above procedure will recover complete log file data. However, there exists SQL Server transaction log recovery tool through which you can restore database transaction log.