Shipping an AI app or agent? Security review in 1 working day: $149 / ₹13,900. Request a review →
AI Review Ready
Home / Error fixes / Failed to start: readonly database
Fix · ChatGPT desktop · Codex · Windows

ChatGPT failed to start: attempt to write a readonly database

Fix (reported by users, not official): a crash, forced restart or unclean exit left an unfinished write next to %USERPROFILE%\.codex\.codex-global-state.sqlite. Quit the app, back up the database together with its -journal file, open the database read/write once with SQLite so it can roll the journal back, then start the app. Don't delete the journal by hand, and don't bother reinstalling.

At a glance
ErrorChatGPT failed to start. attempt to write a readonly database
Log lineDesktop bootstrap failed to start the main app errorCode=ERR_SQLITE_ERROR errorMessage="attempt to write a readonly database" phase=bootstrap-import-main
WhereChatGPT desktop app with Codex on Windows (Store package 26.1120.6357.0 and 26.1123.13983.0); one report on macOS
Cause (user analysis)A hot rollback journal, .codex-global-state.sqlite-journal, that the app can't roll back because it opens the database read-only at startup
FixBack up both files, open the database read/write once (SQLite rolls the journal back), restart. Worked for 5 users
Reports10 people on GitHub, 25 Nov to 4 Dec 2026 (#63931, #64491, #64926, #65213, #65232). No OpenAI reply on these issues
Checked5 Dec 2026, against the sources listed below

Fix it

These steps come from users who recovered on Windows (issue #63931: four separate users; also #65213). OpenAI hasn't confirmed them.

  1. Quit the app completely, including from the system tray.
  2. Check that this is your case. Paste %USERPROFILE%\.codex into File Explorer's address bar (the folder name starts with a dot, which is why some users couldn't find it). You should see both .codex-global-state.sqlite and .codex-global-state.sqlite-journal, usually with the same modified time, around a crash or restart. No -journal file? Then this fix doesn't apply.
  3. Back up the files together. In PowerShell:
    New-Item -ItemType Directory "$env:USERPROFILE\codex-db-backup" -Force
    Copy-Item "$env:USERPROFILE\.codex\.codex-global-state.sqlite*" "$env:USERPROFILE\codex-db-backup\"
    This copies the database, the journal and any -wal / -shm files.
  4. Open the database read/write once. Either way below worked for users. Both open the existing file, let SQLite roll back the journal, and print ok.

    With the official SQLite command-line tool (from sqlite.org/download.html), in Command Prompt, as one user did:

    sqlite3.exe "%USERPROFILE%\.codex\.codex-global-state.sqlite" "PRAGMA integrity_check;"

    That user's warning: check the path first, because SQLite creates a new empty database if the file isn't there.

    Or with Python 3, in PowerShell, as another user did:

    py -3 -c "import os, sqlite3; from pathlib import Path; p = Path(os.environ['USERPROFILE']) / '.codex' / '.codex-global-state.sqlite'; c = sqlite3.connect(p.as_uri() + '?mode=rw', uri=True); print(c.execute('PRAGMA integrity_check').fetchall()); c.close()"
  5. Start the app. Users report the app opened normally afterwards, with their chats ("my existing Work conversations became visible again"). The -journal file is gone once SQLite has rolled it back.

Why it happens

SQLite keeps a rollback journal while it writes. SQLite's docs: "A hot journal is created when a process is in the middle of a database update and a program or operating system crash or power failure prevents the update from completing." Before reading the database, SQLite rolls a hot journal back. It can't do that on a read-only connection: that is error SQLITE_READONLY_ROLLBACK (776), "a database cannot be opened because it has a hot journal that needs to be rolled back but cannot because the database is readonly".

Two users reproduced exactly that on copies of their files: opened read-only, the copy failed with "attempt to write a readonly database (code 776, SQLITE_READONLY_ROLLBACK)"; opened read/write, SQLite rolled the journal back and integrity_check returned ok (#63931). Their reading is that the app opens this file read-only early in startup. One of them found no crash at all on their machine: the previous launch had failed for another reason, so an ordinary unclean exit was enough.

What doesn't help

  • Reinstalling, Microsoft Store Repair or Reset, restarting Windows. Reported in #63931, #64491 and #64926. The .codex folder is in your user profile, outside the app package, so these don't touch it.
  • Changing file permissions. Users found the attributes and permissions were already fine; "readonly" refers to how the app opened the database.
  • Deleting the -journal file. Users warn against it: the journal holds what SQLite needs to put the database back in a consistent state.

A different startup error

failed to initialize sqlite state runtime ... timed out waiting for state db backfill ... after 30s is another problem. In #65252 a user traced it to stale lock files and a leftover "ChatGPT Classic" process after a crash, and recovered by ending that process and removing the crash-time lock files after a backup.

Running Claude Code, Codex or Cursor on real repos, or shipping an AI agent? A Quick Review ($149 / ₹13,900, 1 working day) checks one repo, config or setup for leaked keys, risky agent permissions and MCP servers. Request a Quick Review

FAQ

How do I fix 'ChatGPT failed to start. attempt to write a readonly database'?

Users fixed it by quitting the app, backing up .codex-global-state.sqlite and its -journal file from %USERPROFILE%\.codex, opening the database read/write once with SQLite (PRAGMA integrity_check), and restarting the app. OpenAI hasn't published a fix.

Will I lose my chats?

Users who followed these steps report their conversations came back. Back up both files first anyway.

Why doesn't reinstalling fix it?

The database lives in the .codex folder in your user profile, which reinstalling and Store Repair don't touch.

Can I just delete the -journal file?

Users warn against it. The journal holds the data SQLite needs to roll back the unfinished write and keep the database consistent.

What causes it?

An unfinished write to the app's state database, left by a crash, forced restart or unclean exit. Opened read-only, SQLite can't roll it back (SQLITE_READONLY_ROLLBACK).

Related errors

Sources

Read 5 Dec 2026. These tools change often: if a step no longer matches, the linked page wins.

Related free tools