{"record":{"id":"99b17424c193dbd3","repo":"dgraph-io/badger","slug":"no-manifest-found-required-for-read-only-db","errorCode":null,"errorMessage":"no manifest found, required for read-only db","messagePattern":"no manifest found, required for read-only db","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"manifest.go","lineNumber":140,"sourceCode":"\treturn helpOpenOrCreateManifestFile(opt.Dir, opt.ReadOnly, opt.ExternalMagicVersion,\n\t\tmanifestDeletionsRewriteThreshold, opt)\n}\n\nfunc helpOpenOrCreateManifestFile(dir string, readOnly bool, extMagic uint16,\n\tdeletionsThreshold int, opt Options) (*manifestFile, Manifest, error) {\n\n\tpath := filepath.Join(dir, ManifestFilename)\n\tvar flags y.Flags\n\tif readOnly {\n\t\tflags |= y.ReadOnly\n\t}\n\tfp, err := y.OpenExistingFile(path, flags) // We explicitly sync in addChanges, outside the lock.\n\tif err != nil {\n\t\tif !os.IsNotExist(err) {\n\t\t\treturn nil, Manifest{}, err\n\t\t}\n\t\tif readOnly {\n\t\t\treturn nil, Manifest{}, fmt.Errorf(\"no manifest found, required for read-only db\")\n\t\t}\n\t\tm := createManifest()\n\t\tfp, netCreations, err := helpRewrite(dir, &m, extMagic)\n\t\tif err != nil {\n\t\t\treturn nil, Manifest{}, err\n\t\t}\n\t\ty.AssertTrue(netCreations == 0)\n\t\tmf := &manifestFile{\n\t\t\tfp:                        fp,\n\t\t\tdirectory:                 dir,\n\t\t\texternalMagic:             extMagic,\n\t\t\tmanifest:                  m.clone(opt),\n\t\t\tdeletionsRewriteThreshold: deletionsThreshold,\n\t\t}\n\t\treturn mf, m, nil\n\t}\n\n\tmanifest, truncOffset, err := ReplayManifestFile(fp, extMagic, opt)","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/dgraph-io/badger/blob/2a001d466f6b71a917319a1db41f99860e16e269/manifest.go#L122-L158","documentation":"When opening a badger directory in read-only mode, the MANIFEST file must already exist; badger will not create one in read-only mode. If OpenExistingFile reports the manifest missing and readOnly is set, this error is returned instead of creating a fresh manifest.","triggerScenarios":"badger.Open with opts.ReadOnly=true on a directory with no MANIFEST file (empty/new directory, or the manifest was deleted/not copied).","commonSituations":"Pointing a read-only reader at a non-existent or empty directory; copying a DB but excluding MANIFEST; opening a directory before a writer ever initialized it; read-only replicas started before initial sync.","solutions":["Point ReadOnly opens at a directory that already contains a MANIFEST (an initialized DB)","First open the directory read-write once (or copy the full directory including MANIFEST) before read-only access","Verify the path is correct and the copy/backup completed fully","Use badger info to confirm the directory contents"],"exampleFix":"// before\nopts := badger.DefaultOptions(\"/path/to/empty-or-partial-dir\")\nopts.ReadOnly = true\n// fails: no manifest found, required for read-only db\n// after\n// open read-write once to initialize, then open read-only\ninitOpts := badger.DefaultOptions(\"/path/to/dir\")\ndb, err := badger.Open(initOpts) // creates MANIFEST\ndb.Close()\nopts := badger.DefaultOptions(\"/path/to/dir\")\nopts.ReadOnly = true\ndb, err = badger.Open(opts)","handlingStrategy":"validation","validationCode":"// Go: check the manifest exists before a read-only open\nif opts.ReadOnly {\n    if _, err := os.Stat(filepath.Join(opts.Dir, \"MANIFEST\")); os.IsNotExist(err) {\n        return fmt.Errorf(\"cannot open read-only: MANIFEST missing in %s\", opts.Dir)\n    }\n}","typeGuard":null,"tryCatchPattern":"// Go\ndb, err := badger.Open(opts)\nif err != nil {\n    if strings.Contains(err.Error(), \"no manifest found, required for read-only db\") {\n        return fmt.Errorf(\"directory %s is not an initialized badger DB; open read-write once first\", opts.Dir)\n    }\n    return err\n}","preventionTips":["Only open read-only directories that were previously initialized read-write","Include MANIFEST in every backup/copy of a badger directory","Check the path points to the DB root, not a parent or subdir","Initialize new DBs with a read-write open before read-only consumers start"],"tags":["manifest","read-only","open"],"backgroundTag":"missing-manifest-read-only","analyzedSha":"2a001d466f6b71a917319a1db41f99860e16e269","analyzedAt":"2026-09-05T13:00:02.264Z","contentChangedAt":"2026-09-05T13:00:02.264Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}