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.)
If 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.
- Browse to the appropriate key for your version of Outlook.
- If the PST subkey does not exist, create it.
- Right click on PST key and choose New, DWORD.
- Type (or paste) PSTNullFreeOnClose as the Name.
- Double click on it and enter 1 as the Value.
For Outlook 2016/2019/365:
HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\PST
For Outlook 2013:
HKEY_CURRENT_USER\Software\Microsoft\Office\15.0\Outlook\PST
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
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 2016/2019/365 Outlook 2013
Outlook 2010 Outlook 2007
More Information
Outlook 2007 improvements in the February 2009 cumulative update
After installing Office 2007 SP2, Outlook takes a long time to close and Outlook.exe remains running in the background
This registry setting only nulls free space within a PST or OST file. It doesn't actually remove the free space. You either have to manually compact the file or let Outlook do it automatically when a pre-defined threshold is met.
Interrelated questions about which files are targetted: How does the regedti ensure which/ all files are targeted? In other words: Does the code above apply to all PST/OST files everywhere, or do you have to specify a directory and/or a file?
it works on the data file attached to your profile - it doesn't matter where it is stored on the hard drive. What the key does is trigger the compact process.
Diane,
Thanks for your reply. In our case the .ost's are not corrupted, just very large because our employees like to save a lot of mail. I was hoping to find a way to have Outlook automatically compact on close because the built in background compaction does not seem to be working on any of the workstations I have checked so far. I am guessing it is because our workstations are almost never idle long enough for the background process to start.
Yeah, it is because they aren't idle. If they use active screensavers, have them switch to one that is static. When they take a break, leave outlook open and lock the computer, don't sign off and on all day long.
Also tested this with Outlook 2010 connected to Exchange online accounts on two workstations so far and it did not work on either. Outlook takes longer to close but the .ost files never get smaller. Ran manual compact on both workstations and the difference in size of the .ost files afterwords was dramatic. Over 70% reduction in size. I wish there was a way to automatically compact .ost files in Outlook 2010 since we have a lot of workstations that I will have to manually compact the files.
They usually recommend deleting and rebuilding the ost instead of trying to repair it - that would work for compact too. It's not bad if the ost is fairly small as it will sync fast. But it can cause network issues if the ost is large.
This RegKey PSTNullFreeOnClose (set to 1) does not seem to work for OST (tested with Outlook 2010). Outlook seems to take more time closing (I see the icon in the status bar for far longer time, but no file size change). A manual compress works. Can anybody confirm that they've used PSTNullFreeOnClose successfully to compress the OST automatically when Outlook closes? Thank you! And, thank you Ms. Poremsky for your MS Office articles.
Is there a way to do this for OST files instead of PST?
it's supposed to compact ost files too.
yw - Cheers :)
The "Do it for Me" reg files - 2007 and 2010 are swapped around i.e 2007 is for 2010 and vice versa...
Oh, sorry about that. I'll get that fixed right now. Thanks for letting me know.