{
  "id": "database/sqlite-cannot-attach-database",
  "signature": "sqlite3.OperationalError: unable to open database: /path/to/attached.db",
  "signature_zh": "sqlite3.OperationalError: 无法打开数据库：/path/to/attached.db",
  "regex": "unable to open database: .*attached\\.db",
  "domain": "database",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "The ATTACH DATABASE command fails because the target database file does not exist, is not readable, or the directory is not writable (for creating a new database), or the file is locked by another process.",
  "root_cause_type": "generic",
  "root_cause_zh": "ATTACH DATABASE 命令失败，因为目标数据库文件不存在、不可读、目录不可写（用于创建新数据库），或文件被另一个进程锁定。",
  "versions": [
    {
      "version": "SQLite 3.36",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "SQLite 3.40",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "SQLite 3.45",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "SQLite 3.46",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Set the file permissions to 777 recursively on the directory",
      "why_fails": "Overly permissive permissions can cause security issues and may not solve the problem if the file is locked by another process",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "Use ATTACH DATABASE with a different alias expecting it to create the file",
      "why_fails": "ATTACH DATABASE can create a new database file only if the directory is writable; if the error is due to a locked file, a new alias won't help",
      "fail_rate": 0.4,
      "condition": "",
      "sources": []
    },
    {
      "action": "Restart the application to release locks",
      "why_fails": "If the lock is held by another process (e.g., a separate application instance), restarting your app won't release that lock",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Check if the file exists: `ls -la /path/to/attached.db`. If not, create an empty database file: `touch /path/to/attached.db` and ensure correct permissions: `chmod 644 /path/to/attached.db`. Then retry the ATTACH command: `ATTACH DATABASE '/path/to/attached.db' AS attached_db;`",
      "success_rate": 0.85,
      "how": "Check if the file exists: `ls -la /path/to/attached.db`. If not, create an empty database file: `touch /path/to/attached.db` and ensure correct permissions: `chmod 644 /path/to/attached.db`. Then retry the ATTACH command: `ATTACH DATABASE '/path/to/attached.db' AS attached_db;`",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a tool like `lsof /path/to/attached.db` to check if another process has the file locked. If so, kill or wait for the process to release the lock, or use a different database file path.",
      "success_rate": 0.8,
      "how": "Use a tool like `lsof /path/to/attached.db` to check if another process has the file locked. If so, kill or wait for the process to release the lock, or use a different database file path.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Ensure the parent directory is writable: `chmod 755 /path/to` and that the file is not in a read-only filesystem. If using NFS, check for NFS lock issues and consider using a local file path.",
      "success_rate": 0.75,
      "how": "Ensure the parent directory is writable: `chmod 755 /path/to` and that the file is not in a read-only filesystem. If using NFS, check for NFS lock issues and consider using a local file path.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "检查文件是否存在：`ls -la /path/to/attached.db`。如果不存在，创建一个空数据库文件：`touch /path/to/attached.db` 并确保正确的权限：`chmod 644 /path/to/attached.db`。然后重试 ATTACH 命令：`ATTACH DATABASE '/path/to/attached.db' AS attached_db;`",
    "使用 `lsof /path/to/attached.db` 等工具检查是否有其他进程锁定了该文件。如果是，杀死或等待该进程释放锁，或使用不同的数据库文件路径。",
    "确保父目录可写：`chmod 755 /path/to` 并且文件不在只读文件系统中。如果使用 NFS，检查 NFS 锁问题并考虑使用本地文件路径。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://www.sqlite.org/lang_attach.html",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.85,
  "resolvable": "true",
  "first_seen": "2024-01-08",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}