Showing posts with label SQL Database Repair. Show all posts
Showing posts with label SQL Database Repair. Show all posts

Tuesday, February 14, 2017

10 Ways to Prevent SQL Server Database Corruption

In this post, I want to walk through the 10 ways to prevent the SQL database corruption. I am so much aware of the corruption situation. It is a nightmare for every DBA. It will turn into permanent data loss if you do not take the proper action to fix it. Always check the errorlog first to check the corruption point and after using DBCC CHECKDB command, you can find the exact reason of it.
You can also protect your database by following tips.
  1. Always maintain backup: backup is the key to the disaster plan strategy. A good DBA always takes care of the database backup and maintains it. Database backup should be working, and you can check it by restoring your database. It also helps to protect you from a database upgrade or other system problems.
 The organisation, which works on SQL Server 24/7, always take the backup of with the active backup agent. If you will try to take the backup of the running database, then there is a high chance of corruption in your database.
  1. Query optimization in SQL Server: Query optimization becomes very essential when your upgrade your SQL Server. You need to tune the performance of the individual query. It is important as the other aspects of SQL Server installation. If your server is working on a powerful hardware then, it can be affected by queries. A bad query also called “Runway Query” can be the cause of database corruption. 
  1. Proper shutdown and restart the services: I read on few forums where users were asking about the safe shutdown steps because, improper shutdown effects on the running services. There are the clean shutdown scenarios:
    • Stop the SQL Server by using service console.
    • Shutting down the SQL Server
    • Shutdown command in SQL Server Management Studio.
There are the improper shutdown scenarios:
    • Shutdown with NOWAIT
    • Cable issue
    • Killing the sqlserver.exe from task manager
    • Drive failure where SQL database resides.
  1. Hardware maintenance: Hardware fault is one of the common reason of database corruption. It would be related to Disk, controller, CPU or, memory modules. As SQL Server depends on the disk subsystem, so, the minor issue in the hardware can corrupt the database. If you ever found any issue in the hardware, then please call or engage your hardware vendor. In these type of cases, the vendor checks the drivers, firmware, BIOS version to check their performance with the current database version. They hold the hardware diagnostic tools to find the exact issue of the hardware.
  1. Database normalization: Database Normalization is one of the most stronger parts of the database design. This is the technique to organise the data. Without normalizing the database, the database will be slow, inefficient and inaccurate. It is also possible that you will not get the data you expect if you ignore the normalization. The primary way to organise the data is a table. The database table is like Excel spreadsheet, where you can manage the data in the row and columns. In the data warehouse, multiple updates happen periodically if, data will be normalized so, the load time will be less, and it will help reduce the response time and prevent the database from the corruption.
In database normalization, we focused on ACID property. We maintain the atomicity, consistency, isolation and durability of the database. It plays a primary role in transaction operations.
  1. Periodic check and repairs of DB: Keeping the database healthy is also DBA’s responsibility. Here is a list of few “must do” task which you may perform for a periodic check for your database:
    • Manage auto-growth correctly.
    • Avoid schedule shrink operations.
    • Turn-on the instant file initialization. It skips the zero writing step and immediately allocates the space for the data file.
    • Detect and remove the index fragmentation.
    • Turn on the page checksum.
    • Maintain a regular process to run DBCC CHECKDB.
    • Always keep the full database backup with this, differential and log backup for point-in-time recovery.
  1. Disk space management: Always pay attention to the disk space and manage it properly to avoid the corruption. I am just going to share a scenario, where user  created the table and got the following error message:
“Msg 1105, Level 17, State 2, Line 18
Could not allocate space for object ‘dbo.stutable’ in database ‘MySchool’ because the ‘PRIMARY’ filegroup is full. Create disk space by deleting unneeded file, dropping objects in the filegroup, adding additional files to the filegroup, or setting autogrowth on for existing files in the filegroup.”

After checking the local disk space, they found the 0 bytes free space.

In this case, you should check the auto growth setting for data and log files of the affected database. It is also possible that you find the setting turn-off, which means, either one or both files reached to their maximum size.

To face this kind of situation, some users already creates the placeholder file. These are the larger file, which keeps the store on the disk.

  1. Update and optimize SQL server: Every update or version of SQL Server comes up with few new features, changes in the existing features and, strong fixing for a bug in the database. You should update the SQL Server to take the advantages of more features. It also improves the scalability and stability.
  1. Scan the SQL Server for virus and malware:  Any virus or malware can be the reason of system crash and SQL Server performance degradation. Purchas the best anti-virus software for your system protection from any bug, viruses and malicious activity by Trojan. These viruses can also steal your personal information and downloads the other malware to the system.
  1. SQL Server platform issue: One reason could be SQL Server platform issue. Commonly, the third-party driver or firmware creates a problem in performance. To fix it, you need to determine the where the corruption is it.
There are the 10 most important ways to prevent your database from corruption. Whenever you stuck in the corruption, then take the help of SQL database expert or use a secure third party SQL database repair software to repair the corrupt SQL database.

Before I conclude to this post, I would like to request all the readers to take care of these 10 points in mind.

Conclusion
I dealt with many time with SQL database corruption, and sometimes, the reason was very silly. These silly mistakes do not acceptable from any professional. So always, focus on these points to prevent your database from corruption. These steps will help to prevent your database from corruption or failure.
»»  Read More...

Tuesday, November 8, 2016

Understand Microsoft SQL Server Error 8946 and Fix it

SQL database error 8946 is related to the invalid page header. Malware infection, unexpected system shutdown, hardware issue are the main reasons for this error message. I read about this error on blogs and forums, and the user has different experience with it. A user complained that when he tried to run DBCC CHECKDB command then got the following error message:

Msg 8946, Level 16, State 12, Line 1
Table error: Allocation page (1:13280496) has invalid PFS_PAGE page header values.
Type is 0. Check type, alloc unit ID and page ID on the page.

Before moving to the error message, let’s talk about the PFS page.

PFS (Page Free Space) Page is the second page (Page Number 1) in the data file which is followed by the file header (Page Number 0). PFA page doesn’t have bit-map, it has byte-map. PFS interval is 8088 pages or about to 64MB.

DBCC CHECKDB uses PFS pages to determine the allocation status of pages. A User can repair SQL server error 8946 by two ways:

  • Restore from the backup
  • Repair PFS pages

Restore from the backup

Updated backup can save the work. Yes, this is first method that a user should try to fix this problem.

  • Open SQL Server Management Studio.
  • Click on Database folder and select Restore Database option


  •  Under ‘Source for Restore’ section, select ‘From device’ option and press the ellipsis button.
  • Set File as backup media and click on Add button.

  • Select the .Bak file and press the OK button.
In database dialog box, select the database name which you want to restore. If database is already existing, it will replace data from backup otherwise create the new one. Select the restore point which you want to use.

By this approach, the database can restore from backup.

Repair PFS page

A user cannot delete PFS page because it has a fixed part in the database. PFS pages cannot be rebuilt because it is not possible to identify the which page is allocated and which is not. I read Paul Randal’s blog and he said; he experimented various algorithms to rebuild PFA page with the optimistic or pessimistic setting and re-run the various consistency checks, but all required a very long runtime. Read here

A third-party tool

One more solution to fix this error is an SQL database repair tool. Stellar Repair for MS SQL software has the capability to solve this error. Download and install the software. Select the corrupt MDF file, click the Repair button to start repairing process.

Conclusion
We discuss the solutions here to fix Microsoft SQL database error 8946. I hope users will fix it after reading these methods. Always main the backup of database because it is the best way to save important data. You can share your thoughts and ask questions related to this error and I will try to provide you the best answer. 
»»  Read More...