For the last few months, Safari would forget bits of my browsing history every time I closed it. After around 24 hours only one or two items would be left listed for the previous day of browsing. There was no logic to what was being remembered or how quickly history items would disappear.
I upgraded from OS X 10.10 (Yosemite) to 10.11 (El Capitan); I disabled all my Safari extensions; I cleared out the cache, cookies, and the few items left in History; I turned off syncing Safari to iCloud in System Preferences; I closed every application and background process I found running; I checked to make sure that “remove history items” wasn’t set to “after one day”1 and I even changed it to “manually” to see if there was a bug. Nothing worked.
If you’re here it probably means googling hasn’t been helpful: most search results are for people who want to disable history tracking. I feel your pain, but hopefully you’re in luck.
My problem stemmed from a corrupted database in
~/Library/Safari/. There are five files in that folder related to storing your history. You should close Safari and then delete all of them:
With any luck, you should now be able to open Safari, load a website, and then close Safari without it losing your history.