By default Windows runs an online Defragmentation of the Windows Active Directory database every 12 hours. However, Online defragmentation doesn’t recover the disk space or compact the database. It simply moves data around.
An Offline Defragmentation, on the other hand performs a defragmentation on the database, compacts it and recovers the space. Use the “ntdsutil” utility to run Offline Degramentation on Windows Active Directory. This requires unmounting the Active Directory which mean rebooting the server in “Directory Service Restore mode”.
NOTE: It is important that you take a backup of the Active Directory before performing this operation.
1. Reboot the Windows Server.
2. Press F8 to bring up the Windows Startup menu.
3. Select the ” Directory Services Restore Mode”. This will start Windows Server in Safe Mode and the Directory Service not running
4. Login as a local admin.
5. Now, from the command prompt (Start – Run – type “cmd” and press enter)
6. Run the command ntdsutil.exe
This will launch the ntdsutil
7. Enter “files” at the ntdsutil prompt.
This will launch the file maintenance mode
8. Enter “compact to c:\tmp\”
This will instruct ntdsutil to compact the database to c:\tmp\ folder. This could be any folder. Basically, “ntdsutil” will compact and create a new database leaving the original database file ntds.dit in “%systemroot\ntds\” folder.
9. Replace the original ntds.dit file with the new compacted one.
c:\tmp> copy ntds.dit %systemroot%\ntds\ntds.dit
That completes the process. Reboot the server as normal and check if all is OK. Should there be a problem, be prepared to restore your backup