Corruption in SQL databases

No one wants to experience corruption anywhere on their system, especially in their SQL databases that are used for business critical applications.  Unfortunately, it does happen at times, though.

One of the most common causes of corruption of the database files that I see, is improper shutdown.  To many people, “rebooting” means to power the computer off, and then back on.  This is a tremendously good way to corrupt a database.  Many times, the reason for restarting the computer is that the user thinks that the database is hung.  In fact, a large percentage of the time the database is not hung, but is instead extremely busy.  This could be due to a poor query, or a scheduled job.  Whatever the cause, what is really happening in these cases is that the database is so busy trying to process, that it can not keep up with other ongoing requests.  Then, in the middle of all of that reading and writing, the power is shut off, and the database server has no chance to exit gracefully.

Of course there are times that a server does truly freeze, and there is no choice but to power off.  That should only be done if there is no response of any kind, and that sufficient time is allowed for a response.  That is another key:  Allowing enough time for a response.

Too many times, a user will actually try to do a proper shutdown, but when the shutdown is not done in a short amount of time, say 30 seconds, they assume that the server is “hung” and power off.  If it is the case where the database server is extremely busy, what usually is in fact happening, is that the database server is trying to get to a point where it can quit.  In other words, it is busy writing information that gives it a checkpoint, and losing power at this point is one of the best ways to corrupt a database file.

If there is any response at all, and you start a shutdown, try to determine if there is activity going on.  Does the system still respond to mouse movements? Do characters show when you hit keyboard keys?  Is the disk activity light flashing at all (even if just barely), and not just on solid?  All of these are indications that the system is still running, and simply overloaded with work.  In that case, give it more time to finish, and you may avoid any corruption in your database files.

Leave a Reply