Apple - Safari history disappears despite settings

This is size limit imposed by Safari.

A sqlite database can obviously be larger than 80M; it is only limited by the amount of available storage space, but technically it has an upper file size limit of about 140TB

Other developers have noted that in (older versions of) Safari, the limit is capped at 50GB. It's reasonable to assume that this limit has been increased in subsequent releases of macOS/iOS/Safari.

It also stands to reason that this size limit is imposed by (Apple) Safari because, by default, it is configured to synchronize with iCloud to other Apple devices many of which are constrained by storage availability (iPhones and iPads, for example).

We also know that iCloud's basic (free) storage allotment is 5GB and this must account for much more than browsing history. Things like files, settings, device backups (where applicable) keychains, notes, etc. must be allocated space. Synchronization of these items is set by default by Apple.

It wouldn't make much sense to allow an unlimited history where History.dbcould outstrip the capacity of iCloud/iPad/iPhone.

Even though you're not using iCloud integration, the average user does and Apple will architect it's products around this premise and design their products accordingly.

Extracting Your History

You can pull your history items out of the History.db file with this (very) simple sqlite3 script

Create a "commands.txt" file and populate it with the following commands:

.mode csv
.once history.txt
select visit_time, title, url from history_visits inner join history_items on = history_visits.history_item;

Then issue the command

sqlite3 History.db < commands.txt

This will create a CSV file called history.txt containing the time, title and URL of the history items. This assumes you are in the ~/Library/Safari directory. Keep in mind that the date/time of your history item will be in epoch time (although the epoch is different in this case) and will need to be ultimately converted.