How to Check Safari History on a Mac and Inspect Database
In this article
Checking Safari history on a Mac gives you a complete record of websites you have visited, including timestamps and visit frequencies. To inspect the underlying database directly, you will need to access Safari's History.db file, which stores all history data in a structured SQLite format that reveals details not visible in the standard History menu.
What You'll Need
- A Mac computer running macOS (any recent version)
- Safari browser (built into macOS)
- A SQLite database viewer (SQLiteViewer app, DB Browser for SQLite, or the command-line sqlite3 tool)
- Your Mac user account password (required to access protected folders)
Step-by-Step
- Open Safari by clicking its icon in the Dock or searching for it in Spotlight (press Cmd + Space and type Safari).
- Access the History menu by clicking History in the menu bar at the top of the screen. You can also press Cmd + Y to open the History sidebar directly.
- Browse your history in the sidebar that appears. You can scroll through dates, use the search field at the top to find specific websites, or click "Show All History" at the bottom to see the complete chronological list.
- Navigate to the history database file by opening Finder, then pressing Cmd + Shift + G to open the "Go to Folder" dialog. Type exactly:
~/Library/Safari/and press Enter. This takes you to the Safari data folder. - Locate the History.db file in the Safari folder. You should see a file named "History.db" - this is the SQLite database containing all your browsing history records.
- Make a backup copy before opening the database. Right-click the History.db file, select "Duplicate," and rename the copy to something like "History_backup.db" so you have a safe original to return to.
- Open the database with your SQLite viewer. If using DB Browser for SQLite, launch the app, click "Open Database," and navigate to the History.db file. If using the command line, open Terminal and type
sqlite3 ~/Library/Safari/History.db. - Explore the database tables once the database is open. The main tables you will want to examine are
history_visits(contains individual visit records with timestamps) andhistory_items(contains website URLs and titles). Click on each table to view its contents. - Run queries to extract specific information. For example, to see all visits from the past week with their URLs and timestamps, you could run:
SELECT history_items.url, history_items.title, history_visits.visit_time FROM history_visits JOIN history_items ON history_visits.history_item = history_items.id ORDER BY history_visits.visit_time DESC; - Export or copy data as needed. Most SQLite viewers allow you to export query results to CSV or JSON format for further analysis or backup.
Common Mistakes
One frequent mistake is trying to open the History.db file while Safari is still running, which can cause the database to be locked or show incomplete data. Always quit Safari completely before accessing the database file directly. Another common error is confusing the History.db file with History.db-shm or History.db-wal, which are temporary auxiliary files and do not contain the main history data. Users also sometimes attempt to modify the database directly without creating a backup, which can corrupt the file and cause Safari to display incorrect history or crash. Additionally, some users look in the wrong location - the history database is stored in the user-level Library folder, not the system-level Application Support folder.
Tips
Before diving into the database, try using Safari's built-in History search first - it is much faster for simple lookups and does not require any technical tools. If you need to recover accidentally deleted history, restore from your Time Machine backup or a recent system backup of the History.db file. For regular history inspection, consider exporting your history periodically to a separate file so you have a permanent record. When running SQL queries, remember that timestamps in the database are stored in a format that may need conversion - they are typically stored as Unix timestamps or in a format specific to SQLite that needs to be converted to human-readable dates. Finally, if you share your Mac with others and want to keep your history private, enable Private Browsing mode or use Safari's preferences to set a separate history retention period.
Troubleshooting
If you cannot find the Library folder in Finder, it may be hidden by default in newer versions of macOS. You can reveal it by opening Terminal and typing chflags nohidden ~/Library then pressing Enter, or by holding the Option key while clicking the Go menu in Finder to reveal the Library option. If the History.db file will not open and displays an error about the file being corrupted, try restoring from a backup or check if Safari is still running in the background - close all Safari processes from Activity Monitor if necessary. If your SQLite viewer shows empty tables, you may have accidentally opened the wrong file - verify you are looking at the correct History.db in your user Safari folder. For query errors, double-check your SQL syntax - table and column names are case-sensitive and must match exactly what exists in the database schema.
Frequently Asked Questions
Can I recover deleted Safari history from the database?
If you have a Time Machine backup or another backup that includes the History.db file from before the deletion, you can restore it and view the old history. Once history is permanently deleted from the database, it cannot be recovered through software.
Does Safari history include incognito browsing?
No. When you use Private Browsing mode in Safari, your history is not recorded anywhere on your Mac, and the database will not contain any data from those sessions.
How long does Safari keep history?
By default, Safari keeps history indefinitely until you manually clear it or set a retention period in Safari preferences. You can configure Safari to automatically remove history older than one year, one month, or one day in the Privacy settings.
Can I view history from another Apple device?
If you have iCloud History enabled and syncing is turned on, Safari history syncs across all your devices signed into the same Apple ID. However, the local History.db file on your Mac only contains history generated on that specific Mac.
Is it safe to delete the History.db file?
Deleting the History.db file will remove all your browsing history from that Mac. Safari will automatically create a new empty History.db file the next time you browse, but the old data will be lost permanently unless you have a backup.