{"record":{"id":"2f37d91081d74000","repo":"1Panel-dev/1Panel","slug":"init-db-dir-failed-err-v","errorCode":null,"errorMessage":"init db dir failed, err: %v","messagePattern":"init db dir failed, err: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"agent/utils/common/sqlite.go","lineNumber":18,"sourceCode":"package common\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\t\"os\"\n\t\"path\"\n\t\"time\"\n\n\t\"github.com/1Panel-dev/1Panel/agent/global\"\n\t\"github.com/glebarez/sqlite\"\n\t\"gorm.io/gorm\"\n\t\"gorm.io/gorm/logger\"\n)\n\nfunc LoadDBConnByPath(fullPath, dbName string) *gorm.DB {\n\tif _, err := createDirWhenNotExist(true, path.Dir(fullPath)); err != nil {\n\t\tpanic(fmt.Errorf(\"init db dir failed, err: %v\", err))\n\t}\n\tif _, err := os.Stat(fullPath); err != nil {\n\t\tf, err := os.Create(fullPath)\n\t\tif err != nil {\n\t\t\tpanic(fmt.Errorf(\"init %s db file failed, err: %v\", dbName, err))\n\t\t}\n\t\t_ = f.Close()\n\t}\n\n\tdb, err := GetDBWithPath(fullPath)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\treturn db\n}\n\nfunc LoadDBConnByPathWithErr(fullPath, dbName string) (*gorm.DB, error) {\n\tif _, err := createDirWhenNotExist(true, path.Dir(fullPath)); err != nil {","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/1Panel-dev/1Panel/blob/5ac7c808815b0691009cd390414f03471312262f/agent/utils/common/sqlite.go#L1-L36","documentation":"Panic in LoadDBConnByPath when createDirWhenNotExist cannot create the parent directory of the SQLite database file (path.Dir(fullPath)). It is a filesystem-level failure: permission denied, read-only mount, or a path component that is a file.","triggerScenarios":"agent/utils/common/sqlite.go LoadDBConnByPath(fullPath) is called (agent startup or feature init) with a db path like /opt/1panel/db/foo.db whose parent /opt/1panel/db cannot be created — dir owned by root while agent runs as another user, or /opt/1panel is read-only.","commonSituations":"Wrong user/permissions after a manual install or restore; container with a read-only volume mounted at the db path; SELinux/AppArmor denying writes; disk or inode exhaustion.","solutions":["mkdir -p <dir of the db path> and chown it to the user running the agent (e.g. chown -R 1panel:1panel /opt/1panel/db)","Check the volume is mounted rw (mount | grep <path>) and not full (df -h; df -i)","Fix any mistyped DB path in the app config that collides with an existing file"],"exampleFix":"# before: agent cannot create db dir\nsudo -u 1panel mkdir /opt/1panel/db  # Permission denied\n# after\nmkdir -p /opt/1panel/db && chown 1panel:1panel /opt/1panel/db","handlingStrategy":"validation","validationCode":"sudo -u <agent-user> test -w /opt/1panel/db && echo writable || mkdir -p /opt/1panel/db && chown <agent-user> /opt/1panel/db","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pre-create db parent dirs with correct ownership in install/upgrade scripts","Monitor disk space and read-only mounts for the data volume"],"tags":["sqlite","filesystem","permissions","go","panic"],"backgroundTag":null,"analyzedSha":"5ac7c808815b0691009cd390414f03471312262f","analyzedAt":"2026-08-15T14:02:06.953Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}