Windows 2000 Offline Active Directory Defrag
This article explains the mechanism and step-by-step procedure for
performing an offline defragmentation of the Active Directory database
in Microsoft Windows 2000. While the operating system automatically
conducts garbage collection and online defragmentation at scheduled
intervals, this built-in process only redistributes free space
internally without reducing the physical file size of the database. To
reclaim unused disk space and shrink the ntds.dit file on a
Windows 2000 domain controller, administrators must manually perform an
offline compaction using Directory Services Restore Mode and the
ntdsutil command-line utility.
Why Offline Defragmentation Is Required
In Windows 2000, Active Directory utilizes the Extensible Storage
Engine (ESE, or JET blue) to store objects within
%SystemRoot%\NTDS\ntds.dit. The background online
defragmentation process runs automatically every 12 hours. However, it
cannot release physical storage back to the file system because the
database file is locked exclusively by the operating system. Performing
an offline defragmentation creates a brand-new, compacted copy of
ntds.dit containing only active objects and contiguous
storage allocations.
Step 1: Booting into Directory Services Restore Mode
Because the Active Directory service cannot be stopped independently in Windows 2000 while the operating system is running in standard mode, the domain controller must be taken offline:
- Restart the Windows 2000 Server domain controller.
- Press F8 during the initial boot sequence when the Windows 2000 startup menu appears.
- Select Directory Services Restore Mode (Windows 2000 domain controllers only) and press Enter.
- Log on using the local Administrator account and the Directory Services Restore Mode password designated during the DCPROMO configuration.
Step 2: Running the NTDSUTIL Command
Once logged in, open the Command Prompt (cmd.exe) to
access the database management utility:
- Enter
ntdsutiland press Enter. - At the
ntdsutil:prompt, typefilesand press Enter to open the file management menu. - At the
file maintenance:prompt, confirm the current path settings by typinginfoto verify the location of the existingntds.ditfile and log files.
Step 3: Compacting the Database
Windows 2000 requires an empty target folder with sufficient disk space to hold the compacted database file. The target drive must have enough free space to hold at least the projected size of the newly compacted database.
- Ensure a destination directory exists (for example,
C:\CompactDB). - At the
file maintenance:prompt, execute the following command:compact to C:\CompactDB - The ESE engine analyzes the database, reads all records, and writes
a defragmented copy of
ntds.ditto the specified directory. - Once completed, type
quittwice to exit thefile maintenanceprompt and then exitntdsutil.
Step 4: Replacing the Database File
The compacted file must replace the original database file before returning the server to production:
- Copy the newly created file (
C:\CompactDB\ntds.dit) to the original database directory (by default,%SystemRoot%\NTDS\ntds.dit), overwriting the old, fragmented file. - Delete the log files (
*.log) in the%SystemRoot%\NTDSfolder. Windows 2000 requires log file removal after a compact operation so the database engine can regenerate clean log files at the next startup. Do not delete the checkpoint file (edb.chk) if present, though standard procedure often permits deleting all.logfiles. - Remove the temporary folder (
C:\CompactDB).
Step 5: Normal System Restart
Restart the server normally without pressing F8. Windows 2000 will
boot in full Directory Services mode, load the newly compacted
ntds.dit file into memory, initialize fresh transaction
logs, and resume normal Active Directory operations with an optimized
database footprint.