{"record":{"id":"3465dfcef8ef411c","repo":"MHSanaei/3x-ui","slug":"sqlite-integrity-check-failed-s","errorCode":null,"errorMessage":"sqlite integrity check failed: %s","messagePattern":"sqlite integrity check failed: (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/database/db.go","lineNumber":2279,"sourceCode":"func ValidateSQLiteDB(dbPath string) error {\n\tif _, err := os.Stat(dbPath); err != nil {\n\t\treturn err\n\t}\n\tgdb, err := gorm.Open(sqlite.Open(dbPath), &gorm.Config{Logger: logger.Discard})\n\tif err != nil {\n\t\treturn err\n\t}\n\tsqlDB, err := gdb.DB()\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer sqlDB.Close()\n\tvar res string\n\tif err := gdb.Raw(\"PRAGMA integrity_check;\").Scan(&res).Error; err != nil {\n\t\treturn err\n\t}\n\tif res != \"ok\" {\n\t\treturn errors.New(\"sqlite integrity check failed: \" + res)\n\t}\n\treturn nil\n}\n","sourceCodeStart":2261,"sourceCodeEnd":2283,"githubUrl":"https://github.com/MHSanaei/3x-ui/blob/ad32144c42455696ea9f14e12168beac3e25f5d2/internal/database/db.go#L2261-L2283","documentation":"The SQLite integrity check (PRAGMA integrity_check) returned something other than 'ok', meaning pages, indexes, or freelist structures in the .db file are damaged. The raw PRAGMA result string is appended (commonly a list like 'wrong # of entries in page N'), identifying which pages are corrupt. Typical root causes are power loss, a killed process mid-write without WAL, or a corrupted filesystem.","triggerScenarios":"Panel killed -9 during heavy traffic stats writes; disk full during a write; copying the .db file while a write is in flight; the check runs as part of a health/verify path in db.go around line 2279.","commonSituations":"VPS abrupt reboots; running the DB on network storage (NFS) that does not honor SQLite locking; restore from a truncated backup.","solutions":["Stop x-ui, copy /etc/x-ui/x-ui.db aside, then try: sqlite3 x-ui.db '.recover' | sqlite3 fixed.db and swap the recovered file in","If .recover fails, restore from the most recent BackupSQLite snapshot or .bak file next to the DB","Enable WAL journal mode and adequate busy_timeout to reduce torn-write risk going forward","If the damage is limited to traffic-stats indexes, deleting derived tables and letting jobs repopulate them may suffice — inspect the PRAGMA output first"],"exampleFix":"# before\n# (panel reports integrity check failure on boot/health run)\n\n# after\nsystemctl stop x-ui\ncp /etc/x-ui/x-ui.db /etc/x-ui/x-ui.db.corrupt\nsqlite3 /etc/x-ui/x-ui.db.corrupt '.recover' | sqlite3 /etc/x-ui/x-ui.db\nsystemctl start x-ui","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := checkIntegrity(dbPath); err != nil {\n    log.Printf(\"integrity: %v — attempting .recover from last backup\", err)\n    if rerr := restoreFromBackup(dbPath); rerr != nil {\n        log.Fatalf(\"unrecoverable: %v / %v\", err, rerr)\n    }\n}","preventionTips":["Keep WAL journal mode and regular BackupSQLite snapshots enabled","Avoid killing the panel mid-write; use graceful stop","Never place the SQLite file on NFS or unjournaled filesystems","Test restores so the recovery path is known before corruption hits"],"tags":["database","sqlite","corruption","recovery"],"backgroundTag":null,"analyzedSha":"ad32144c42455696ea9f14e12168beac3e25f5d2","analyzedAt":"2026-08-15T11:13:23.905Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}