How-To

How to Read a chat.db File (Your iMessage Database)

Reviewed by Jacob Reed, founder of Verity ·

An open silver laptop on an oak desk beside a phone lying face down, a mug of tea and a closed notebook

Short answer

chat.db is the database the Messages app keeps on a Mac, in ~/Library/Messages. Quit Messages, copy chat.db (with chat.db-wal and chat.db-shm if they are there) to a new folder, and open the copy read-only in the free DB Browser for SQLite. One query turns it into a list of messages with dates and senders. Or drop the files into Verity, pick the conversation, and get it in date order without any SQL.

A chat.db file holds every iMessage and text the Mac has synced, but it is a database, not a document. Double-clicking it does nothing useful, and opening it in a text editor shows gibberish. Here is how to read it without changing it.

How do you open a chat.db file?

1.Quit Messages

On the Mac, quit the Messages app so it isn't writing to the file while you copy it.

2.Open the Messages folder

In Finder choose Go > Go to Folder (Shift-Command-G), type ~/Library/Messages and press Return. chat.db is in that folder.

3.Copy the database files

Make a new folder on the Desktop and copy chat.db into it, together with chat.db-wal and chat.db-shm if they are there. Copy, don't move, and never open or edit the originals.

4.Open the copy read-only

Install DB Browser for SQLite (free, for Mac and Windows). Choose Open Database Read Only and pick the copied chat.db.

5.Run the query

In the Execute SQL tab, paste the query from this page, replace the phone number with the other person's number or email address, and run it. Each row is one message with its date, time and sender.

The query for step 5:

SELECT
  datetime(m.date / 1000000000 + 978307200, 'unixepoch', 'localtime') AS sent,
  CASE m.is_from_me WHEN 1 THEN 'Me' ELSE h.id END AS sender,
  m.text
FROM message m
JOIN chat_message_join cmj ON cmj.message_id = m.ROWID
JOIN chat c ON c.ROWID = cmj.chat_id
LEFT JOIN handle h ON h.ROWID = m.handle_id
WHERE c.chat_identifier = '+15551234567'
ORDER BY m.date;

Phone numbers are stored with the country code, like +15551234567. To see which conversations the file holds, run SELECT chat_identifier, display_name FROM chat; first.

Why are some messages blank?

On recent versions of macOS and iOS, many messages have nothing in the text column. The words are stored in another column, attributedBody, in a binary format that plain SQL can't read. If your query shows rows with a date and a sender but no words, that is why. Messages that are only a photo or a sticker are blank too. Verity decodes the attributedBody column, so those messages come through with their words.

Why are the dates so strange?

Apple counts time from January 1, 2001, not 1970, and recent versions count it in nanoseconds. That is what the / 1000000000 + 978307200 part of the query undoes. If every date comes out as 2001, the file is old enough to store plain seconds: remove / 1000000000 and run it again.

Why copy chat.db-wal too?

The newest messages are often written to chat.db-wal first and moved into chat.db later. Opened together, the three files show everything. If you copied chat.db alone and the last few days are missing, copy all three again after quitting Messages. Verity reads chat.db-wal too: pick it together with chat.db.

Where is chat.db on an iPhone?

You can't open it on the phone itself. The iPhone keeps the same database under the name sms.db, and every unencrypted computer backup contains a copy. On Windows, our guide to exporting iPhone messages on Windows shows where it is. On a Mac the backups are in ~/Library/Application Support/MobileSync/Backup, and the file is in the folder named 3d. sms.db reads the same way as chat.db.

Why does Terminal say "Operation not permitted"?

macOS protects the Messages folder. Finder can open it, but Terminal and most other apps need Full Disk Access first (System Settings > Privacy & Security > Full Disk Access). Copying the file in Finder, as in the steps above, avoids the problem.

Is a chat.db printout good enough for court?

It is a better record than screenshots: every message, in order, with the time to the second. Whether and how it is used is up to your lawyer and the court, and some courts want the phone itself or a certified extraction. Keep the original Mac untouched and work only from copies. See exporting iMessage for court for the other ways to get the same messages out.

How can Verity help?

Drop chat.db (with chat.db-wal, if it's there) or sms.db into Verity and pick the person. You get every message in your conversation with them in date order, iMessages and texts with the same number joined, plus a free preview of the patterns in it. The file is read in your browser and is not uploaded, which matters for a file that holds every conversation on the computer. It is supporting documentation, not a legal finding.

This is general information, not legal advice. Verity is not affiliated with Apple. Open only a database from your own computer or phone.

Have your chat.db?

Pick the conversation, read every message on screen in date order, and get a free preview in minutes. The file is read in your browser and is not uploaded.

Analyze your export →