You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Chrome浏览器SQLite历史库报错sqlite3.OperationalError: database is locked求解决方案

Hey there! Let's tackle that sqlite3.OperationalError: database is locked issue with Chrome's history database. I've run into this exact problem a few times myself, so here are the most reliable fixes I've tested and used:

Common Solutions for Chrome's Locked History DB
  • Shut down all Chrome processes completely
    Chrome loves lingering in the background even after you close the main window—think incognito tabs, pinned apps, or sync processes. Open your task manager (Windows: Ctrl+Shift+Esc, macOS: Cmd+Opt+Esc), find every instance of Chrome, and end them all. Wait 10 seconds, then try accessing the database again.

  • Work on a copy of the database file
    Chrome stores its history DB at:

    • Windows: %LOCALAPPDATA%\Google\Chrome\User Data\Default\History
    • macOS: ~/Library/Application Support/Google/Chrome/Default/History

    Instead of modifying or reading the live file directly, make a full copy to another folder (like your desktop) and point your code to this copy. This eliminates conflicts with Chrome's active file locks entirely.

  • Check for other processes hogging the file
    Third-party tools like backup software, antivirus scanners, or even other scripts you’ve run might be holding a lock on the History file. Use lsof (macOS/Linux) or Process Explorer (Windows) to identify which processes have the file open, then close those apps temporarily.

  • Adjust your SQLite connection settings
    If you’re only reading the history (the most common use case), open the database in read-only mode to avoid triggering write locks. In Python, that looks like:

    # Explicit read-only connection
    conn = sqlite3.connect('file:path/to/History?mode=ro', uri=True)
    

    You can also increase the timeout to give SQLite more time to wait for the lock to release:

    conn = sqlite3.connect('path/to/History', timeout=30)  # Waits 30 seconds instead of default 5
    
  • Repair a potentially corrupted database
    If the lock persists even after closing Chrome, the DB might be corrupted. Use the SQLite command-line tool to check and fix it:

    # First check integrity
    sqlite3 path/to/History "PRAGMA integrity_check;"
    # If errors are found, recover the database
    sqlite3 path/to/History ".recover" | sqlite3 path/to/History_fixed
    

    Then use the History_fixed file for your code.

One last tip: Chrome often rewrites the History file when it’s running, so the copy method is always the safest bet for read-only access—you won’t have to worry about sudden locks mid-operation.

内容的提问来源于stack exchange,提问作者zeroFighter

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 08:42:07