End of support for Windows Server 2003 is fast approaching. With this in mind, most IT administrators are currently performing a migration to newer versions of Windows Server which in many cases includes an Active Directory migration. One item most do not take into consideration is the state of the Active Directory database after the migration is completed. Like any other database Active Directory can also become fragmented. Database optimization is recommended after an Active Directory migration is completed and should be scheduled moving forward to insure a better on going performance.
There are two methods of Active Directory defragmentation available:
Online Defragmentation – Windows Server 2000 introduced a method that runs in certain intervals automatically to defragment the Active Directory database. It is part of active directory garbage collection process. When completed, it optimizes the data storage and reclaims the space for new active directory objects. This however will not reduce the size of the Active Directory database. The bonus of utilizing Online Defragmentation is that it not required to bring any service offline complete the task.
Offline Defragmentation – This method requires an IT administrator to stop the Active Directory service. In stopping said service, the process will create compact version of the existing Active directory database in different location. Once completed, the new defragmented compact database is copied to the original location. Estimates are that the database is shrunk to 1/6th of its original size after offline fragmentation.
The “ntdsutil” is needed to perform defragmentation and is the same tool used to check Active Directory errors. The following steps will detail the process.
- Plan the Active Directory shutdown impact properly and measure how it will affect the rest of the organization. Length of time to complete the defragmentation depends on the size of the Active Directory database and the how bad it is fragmented.
- Always perform a system state backup prior to the process.
Step 1: Stopping the Active Directory Service
- Login to the primary domain controller as Domain admin or Enterprise Admin
- Navigate to Server Manager > Tools > Services
- In Services.mmc right-click on Active Directory Domain Services and click Stop
- Services to be stopped are then listed. Click Yes to continue.
Step 2: Perfroming the Offline Active Directory Fragmentation
- Once services stops, run the Command Prompt in Administrator mode
- In the Command prompt window, type ntdsutil and press enter
- In prompt type activate instance NTDS and press enter
- Type files and press enter
- At the file maintenance we need specify the location where NTDS compact database will save. For this Step-By-Step, the folder C:\CompactDB was created. Type compact to C:\CompactDB and press enter
- The defragment process begins. The time to completion will depend on the size of the database
- Once completed type q to exit from the utility
- Close the Command Prompt console
- Copy the defragmented database from C:\CompactDB\ntds.dit to C:\Windows\NTDS\ntds.dit
- Delete the log files found in the directory
- Return to the Services.mmc
- Right-click on Active Directory Domain Services and click Start
The defragmentation of the Active Directory database is now complete.