Monday, September 10, 2012

How to perform an offline Active Directory database defrag on a Windows 2008 domain controller

Like its predecessors, Windows Server 2008 keeps the Active Directory healthy by periodically performing an automated defragmentation. Although this defragmentation works, it does not compact the database.

Before you attempt an offline defragmentation, I strongly recommend making a full, system state backup of the domain controller.

Once you have created a backup of your domain controller, the next thing that you should do is to make note of the existing Active Directory database’s size. By default, the Active Directory database is located at C:\Windows\NTDS, although the DCPROMO process does allow you to choose a different location. The name of the actual database file is NTDS.DIT. A freshly installed Active Directory database on a Windows Server 2008 domain controller is about 12 MB in size, but the database can grow to be several GB in size, depending on the amount of data that is stored in the Active Directory.

Once you have noted the database’s size, you will have to create a directory that you can use as a temporary repository for a copy of the Active Directory database. When you perform an offline defragmentation, Windows does not alter the original Active Directory database. Instead it creates a defragmented copy database. I recommend creating a folder named TEMP beneath the C:\Windows\NTDS folder.

The next step in the process is to stop the Active Directory Domain Service. Unlike previous versions of Windows, Windows Server 2008 offers the ability to start and stop the Active Directory just as you would any other service. Depending on how your server is configured, there may be dependency services that Windows will also have to shut down.



When the Active Directory Domain Service finishes shutting down, open a Command Prompt window, and enter the command:

NTDSUTIL


The command prompt will now display an NTDSUTIL prompt.
Now enter the following command:
Activate Instance NTDS



At this point, NTDSUTIL will display a message stating that activate instance has been set to “NTDS”.
Now enter:
Files
Now enter:
Info



Now, to do the offline Defrag, enter the command:

Compact to c:\Windows\NTDS\temp



The whole process looks like this:

When the process completes, enter the Q command at the NTDSUTIL prompt to close NTDSUTIL. Next, verify that Windows has created a copy of the Active Directory database in the C:\Windows\NTDS\Temp folder. This copy is the defragmented version of the database. To use it, you must either delete or rename the original database (the one in C:\Windows\NTDS), and then copy the defragmented database from C:\Windows\NTDS\Temp to C:\Windows\NTDS. You must also either rename or delete the log files located in the C:\Windows\NTDS folder.


Now, REBOOT the server.  Done.




No comments: