How do I manually defragment Active Directory?

John Savill

January 8, 2000

2 Min Read
ITPro Today logo in a gray background | ITPro Today

A. Windows 2000 servers running Directory Services (DSs) perform a directory online defragmentation every 12 hours by default as part of the garbage-collection process. This defragmentation only moves data around the database file (ntds.dit) and doesn’t reduce the file’s size.

To create a new, smaller ntds.dit file and to enable offline defragmentation, perform the following steps.

  1. Back up Active Directory (AD) (see the FAQ How do I back up Active Directory and the System State?).

  2. Reboot the server, select the OS option, and press F8 for advanced options.

  3. Select the Directory Services Restore Mode option, and press Enter. Press Enter again to start the OS.

  4. Win2K will start in safe mode, with no DS running.

  5. Use the local SAM’s administrator account and password to log on.

  6. You’ll see a dialog box that says you’re in safe mode. Click OK.

  7. From the Start menu, select Run and type

    cmd.exe
  8. In the command window, you’ll see the following text. (Enter the commands in bold.)

    C:> ntdsutil
    ntdsutil: files
    file maintenance:info
    ....
    file maintenance:compact to c:temp
  9. You’ll see the defragmentation process. If the process was successful, enter

    quit
    quit
  10. to return to the command prompt.

  11. Then, replace the old ntds.dit file with the new, compressed version. (Enter the commands in bold.)

    C:> copy c:temptds.dit %systemroot%tdstds.dit
  12. Restart the computer, and boot as normal.

Below is an example of the entire procedure.

D:> ntdsutil
ntdsutil: files
file maintenance: info

Drive Information:

C: FAT (Fixed Drive) free(1.2 Gb) total(1.9 Gb)
D: NTFS (Fixed Drive) free(152.4 Mb) total(1.9 Gb)

DS Path Information:

Database   : D:WINNTNTDStds.dit - 8.1 Mb
Backup dir : D:WINNTNTDSdsadata.bak
Working dir: D:WINNTNTDS
Log dir    : D:WINNTNTDS - 30.0 Mb total
res2.log - 10.0 Mb
res1.log - 10.0 Mb
edb.log - 10.0 Mb
file maintenance: compact to c:temp
Opening database [Current].
Using Temporary Path: C:
Executing Command: D:WINNTsystem32esentutl.exe /d "D:WINNTNTDStds.dit" /
/o /l"D:WINNTNTDS" /s"D:WINNTNTDS" /t"c:temptds.dit" /!10240 /p


Initiating DEFRAGMENTATION mode...
Database: D:WINNTNTDStds.dit
Log files: D:WINNTNTDS
System files: D:WINNTNTDS
Temp. Database: c:temptds.dit

Defragmentation Status (% complete )

0    10   20   30   40   50   60   70   80   90  100
|----|----|----|----|----|----|----|----|----|----|
...................................................

Note:
It is recommended that you immediately perform a full backup
of this database. If you restore a backup made before the
defragmentation, the database will be rolled back to the state
it was in at the time of that backup.

Operation completed successfully in 17.896 seconds.


Spawned Process Exit code 0x0(0)

If compaction was successful you either need to
copy "c:temptds.dit" to "D:WINNTNTDStds.dit"
or run:
D:WINNTsystem32tdsutil.exe files "set path DB "c:temp"" quit quit
file maintenance: quit
ntdsutil: quit

D:> copy c:temptds.dit %systemroot%tdstds.dit
Overwrite D:WINNTtdstds.dit? (Yes/No/All): y
1 file(s) copied.

About the Author

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like