Why You Need to Care About SQL Server Fragmentation

by Jan 29, 2021

DBAs have many responsibilities as the keepers of enterprise data resources. Keeping systems available for their users is one of the big ones. Ensuring that their databases are secured and preventing unauthorized access to sensitive data is another part of the job that is critically important. It’s safe to say that after security, database performance is the top priority of a company’s database team.

Many factors can contribute to degraded database performance. A SQL Server database could be destined to perpetually provide slow responses due to insufficient hardware provisioning. Poorly optimized SQL statements and queries can bog a system down. You might blame network latency for the recent increase in calls from disgruntled users. All of these issues may be at fault.

One potential culprit that may be overlooked is the problem of SQL Server fragmentation. It’s the type of thing that can creep up on you gradually. By the time you realize it’s an issue, your well-performing database might be gasping for breath as it tries to keep up with expectations. It’s not a pretty picture but is one that can be avoided by adopting a proactive mindset.

What is SQL Server Fragmentation?

Fragmentation poses a problem in various areas of the IT world. Physical disk fragmentation, where portions of a file are distributed across a storage device, slows down Windows machines. This type of physical fragmentation is usually kept in check with SQL Servers by using multi-drive storage subsystems. 

SQL Server fragmentation affects a database’s internal tables and indexes. The inserts, delete, and updates that are a part of the system’s normal daily functionality are the root cause of this fragmentation. Over time, gaps and void space are created and wind up being processed along with valid data. This puts a strain on resources and slows down activities like database backups. Internal fragmentation also negatively impacts performance. 

The real effects of SQL Server fragmentation can be seen in a variety of issues that drag down database performance.

  • CPU efficiency is degraded as it takes longer to physically move data and internal registers are spending cycles handling void data.
  • Void data takes up space in memory resulting in more disk activity and less valid data with which to work.
  • Storage I/O channels and devices are stressed by the wasted space caused by fragmentation, leading to longer backups and additional media requirements.
  • SQL query response can suffer as the result of searching through extraneous void data.

None of these potential outcomes of internal fragmentation are welcomed by the database team nor the user community. DBAs can address this problem in three different ways.

Fixing the Fragmentation Problem

While there are multiple approaches to dealing with SQL Server fragmentation, they are not all equally effective. Choosing the right method can alleviate most of the problems associated with internal fragmentation so the DBA team can concentrate on other pursuits.

  • Waiting until database performance is significantly affected before taking any action is a common method for dealing with fragmentation. It should be obvious that this is not the preferred course of action and should be avoided whenever possible. You should take measures to ensure that fragmentation never reaches that level.

  • Running maintenance scripts is better than only dealing with fragmentation when it becomes an overbearing problem. But a standalone maintenance script has its own set of issues that reduce its effectiveness. A general-purpose defragmentation script will not have the internal logic necessary to perform its activity selectively. It may need to be tailored for each database and, in a large environment running these scripts, can be a nightmare to manage.

  • Using IDERA’s SQL Defrag Manager enables a database team to manage SQL Server defragmentation across the environment. The tool automates the identification of fragmentation hot spots based on customizable policies. Defragmentation can be run on a schedule, on demand, or when thresholds are met. Email alerts and comprehensive reports keep the team updated on fragmentation issues across all enterprise SQL Server instances. 

Automating the defragmentation process ensures that it is performed at the right time. Defragmenting too often can tie up resources while running it too infrequently leads to performance issues. Using policies to drive the process results in more efficient and constructive defragmentation.

An IDERA whitepaper that provides a deep examination of SQL Server fragmentation is recommended reading for all SQL Server DBAs. It provides a detailed overview of how SQL Defrag Manager will address the quiet but impactful problem of internal SQL Server fragmentation.