Where is chat.db on a Mac, and what is in it?

Short answer

The Messages history on a Mac is a SQLite database called chat.db in the Messages folder inside your user Library folder, at ~/Library/Messages/chat.db. macOS protects that folder, so you can only read it from an app that has Full Disk Access, and the file only has your history if Messages is signed in on that Mac.

TextExhibit start screen with four sources: This Mac’s Messages, iPhone via USB, an existing backup and sample data
Where TextExhibit can read messages from. Shown with the app’s built-in sample conversations; the names and numbers are made up.

The exact location

  • Folder: ~/Library/Messages (the Library folder in your home folder, which is hidden by default).
  • Database: chat.db, with chat.db-wal and chat.db-shm beside it while Messages is running.
  • Attachments: the Attachments folder in the same place, sorted into many numbered subfolders.

How to open the folder in Finder

  1. In Finder, choose Go, then hold the Option key and click Library.
  2. Open the Messages folder.
  3. If macOS says you do not have permission, that is the privacy protection; see why you cannot open chat.db.

What is inside

  • Every message, with sender, time, service (iMessage or SMS), and a link to any attachment.
  • Conversations and group members, stored in separate tables joined by ID numbers.
  • Dates are stored as a long number counting from 1 January 2001, not a normal date.
  • On recent macOS versions the text of some messages sits in a binary field rather than a plain text column, so a simple query can show blanks.

Is it your whole history?

Only if the Mac has the history. That needs Messages in iCloud, or Messages signed in on the Mac for a long time. A Mac that was set up last week with sync off has little in it. See Messages in iCloud on or off. TextExhibit reads this database for you, with Full Disk Access, and never changes it.

Read it safely

  • Quit Messages before copying the file, and copy the three files chat.db, chat.db-wal and chat.db-shm together so the copy is consistent.
  • Work on the copy, never the original.
  • Treat the copy as private: it contains every message and number you have.

What to keep in mind

  • Do not edit, move or delete chat.db. Messages can lose history or refuse to open.
  • Deleting a conversation in Messages removes it from this file.
  • The structure is Apple’s and can change with macOS releases.

Questions

Is chat.db the same on iPhone?

The iPhone has a similar database, but it is a different file stored in its own system area and in backups.

Can I copy chat.db to another Mac?

You can copy it, but the attachments and contacts will not follow unless you copy those too, and Messages itself should be closed first.

Why is chat.db small or empty?

Probably Messages in iCloud is off on this Mac, so it never got the older history.

Sources

Export the whole conversation

TextExhibit turns a conversation into one PDF with exact times, names and numbers, photos in place and page numbers, on your Mac. Free to preview; $24.99 once to export.