How to compact the Active Directory Database
In this mini-post, I want to show you how to perform an offline defragmentation of the Active Directory database. To perform the maintenance of the AD DS database offline, we will use the NtdsUtil.exe command line tool. At the end of the defragmentation, we will obtain a compact AD DS database. Requirements: The minimum required to complete the following tasks is Membership in the Local Administrators group. Important: Before performing the tasks described in this post, you must perform a system state backup using Windows Server Backup. To compact the Active Directory database, use the following procedure: The commands used in this procedure require that you run them from an elevated Command Prompt. Open a command prompt as Administrator and run the following commands.
Stop the Active Directory Domain Service. #
To perform offline defragmentation, you must stop the Active Directory Domain Service (NTDS). Run the following command as an administrator and answer “Y” to accept stopping additional services.
net stop ntds
Run the NtdsUtil.exe commands #
by running the following commands, you will compact the database and check the integrity of the database.
Activate instance NTDS
Files
Compact to c:\
Integrity
Quit
Quit
If the defragmentation completes successfully, copy the new database file to the c:\Windows\ NTDS directory and then delete the log files.
copy c:\ntds.dit c:\windows\NTDS\ntds.dit
del c:\Windows\NTDS\*.log
Start the Active Directory Domain Service. #
Once the tasks have finished, we will start the Active Directory Domain Service (NTDS) again. Run the following command as administrator.
net start ntds
If you want to know more about AD DS database compaction, check out this link.