How to Compact the Data File When you Close Outlook

Last reviewed on May 24, 2013

It’s possible to configure Outlook to automatically compact the pst every time you close Outlook. I don’t recommend doing it (or emptying the deleted folder on exit) as it can lengthen the time it takes Outlook to shutdown and if Outlook is forced to close during the compaction process the data file could become corrupt.

However, this can be useful to users who deal with sensitive data and need to ensure messages can’t be recovered as compacting removes all traces of deleted messages, making it impossible to recover the mail.

Understanding Deletion and Compaction

After you delete messages and other Outlook items then empty the Deleted Item folder, the deleted items are removed from the index so Outlook doesn’t display them but they are left in the data file. The space used by these deleted messages is often referred to as “white space”. Until Outlook recovers this space by compacting the data file, it may be possible to recover deleted messages using recovery software.

Outlook will automatically compact the data file when the “white space” reaches 20% of the data file’s size and the computer is idle. Because it runs as a background service, it can take days for Outlook to finish compacting the pst file. (If you leave Outlook open when the computer is running it will have more idle time to compact the data file.)

Compact data file dialogIf you deleted a lot of messages and don’t want to wait for Outlook to get around to it, you can recover the free space by running Compact Now. To do this, right-click on the top-level of the data file and choose Properties, then click the Advanced button and Compact Now. Keep in mind that it can take a long time to compact a large data file.

PSTNullFreeOnClose

If you want to force Outlook to return this free space every time that you close Outlook, you can add PSTNullFreeOnClose to the registry.

Press Windows key + R and type regedit in the Run dialog then press Enter to open the registry editor.

  1. Browse to the appropriate key for your version of Outlook.
  2. If the PST subkey does not exist, create it.
  3. Right click on PST key and choose New, DWORD.
  4. Type (or paste) PSTNullFreeOnClose as the Name.
  5. Double click on it and enter 1 as the Value.

For Outlook 2010:

HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Outlook\PST

Outlook 2007:
HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Outlook\PST

Outlook 2003:
HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Outlook\PST

Outlook 2002:
HKEY_CURRENT_USER\Software\Microsoft\Office\10.0\Outlook\PST

Outlook 2000:
HKEY_CURRENT_USER\Software\Microsoft\Office\9.0\Outlook\PST

DWORD: PSTNullFreeOnClose
Value Data: 1 = compact on close, 0 = don’t compact

PSTNullFreeOnClose registry key

This key was introduced in an update for Outlook 2000 and works in all versions of Outlook that are updated with the latest service pack.

This key compacts both pst and ost files. With the value set to 1, deleted data is removed when you close Outlook. When it’s set to 0 or deleted, the data file will not be compacted on close.

Note that the first time you close Outlook after making this change, it may take a long time for Outlook to close.

Doit It For Me

If you don’t want to edit the registry, we have reg files you can use.

Outlook 2010Outlook 2007Outlook 2003

Written by

Diane Poremsky
A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Please post long or more complicated questions at Outlookforums.

5 responses to “How to Compact the Data File When you Close Outlook”

  1. Mike Sun

    The "Do it for Me" reg files - 2007 and 2010 are swapped around i.e 2007 is for 2010 and vice versa...

  2. Mike Sun

    yw - Cheers :)

  3. Lorne Rogers

    Is there a way to do this for OST files instead of PST?

Leave a Reply

If the Post Coment button disappears, press your Tab key.