{"record":{"id":"807ae2af1b41bf2a","repo":"dgraph-io/dgraph","slug":"while-updating-persisted-query-s-schema","errorCode":null,"errorMessage":"while updating persisted query's schema","messagePattern":"while updating persisted query's schema","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upgrade/change_v21.03.0.go","lineNumber":415,"sourceCode":"\t}\n\n\t// Update the tokenizer in the schema.\n\tsu := pb.SchemaUpdate{\n\t\tPredicate: x.AttrInRootNamespace(\"dgraph.graphql.p_query\"),\n\t\tValueType: pb.Posting_STRING,\n\t\tDirective: pb.SchemaUpdate_INDEX,\n\t\tTokenizer: []string{\"sha256\"},\n\t}\n\tdata, err := proto.Marshal(&su)\n\tif err != nil {\n\t\treturn err\n\t}\n\tentry := &badger.Entry{}\n\tentry.Key = x.SchemaKey(x.AttrInRootNamespace(\"dgraph.graphql.p_query\"))\n\tentry.Value = data\n\tentry.UserMeta = posting.BitSchemaPosting\n\tif err := update(entry); err != nil {\n\t\treturn errors.Wrap(err, \"while updating persisted query's schema\")\n\t}\n\n\t// Update the type.\n\ttu := pb.TypeUpdate{\n\t\tTypeName: x.AttrInRootNamespace(\"dgraph.graphql.persisted_query\"),\n\t\tFields:   []*pb.SchemaUpdate{&su},\n\t}\n\tdata, err = proto.Marshal(&tu)\n\tif err != nil {\n\t\treturn err\n\t}\n\tentry = &badger.Entry{}\n\tentry.Key = x.TypeKey(x.AttrInRootNamespace(\"dgraph.graphql.persisted_query\"))\n\tentry.Value = data\n\tentry.UserMeta = posting.BitSchemaPosting\n\tif err := update(entry); err != nil {\n\t\treturn errors.Wrap(err, \"while updating persisted query's type\")\n\t}","sourceCodeStart":397,"sourceCodeEnd":433,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/upgrade/change_v21.03.0.go#L397-L433","documentation":"fixPersistedQuery rewrites the schema entry for dgraph.graphql.p_query (changing the tokenizer/indexing of the persisted query hash field) by putting a new schema badger entry. This error wraps a badger Write failure when writing that schema entry via the update() helper.","triggerScenarios":"During OfflineUpgradeFrom2011To2103, the badger.DB.Write of the entry keyed by SchemaKey(dgraph.graphql.p_query) fails — DB closed, transaction conflict, disk full, or badger error.","commonSituations":"Running the offline upgrade on a restored 20.11 backup; badger database locked by another process; insufficient disk space; corrupted LSM/manifiest issues.","solutions":["Check the wrapped badger error (%+v) for the root cause and address it (disk space, lock file, permissions).","Ensure no other dgraph/badger process has the p directory open; run the upgrade offline only when the server is stopped.","Re-restore the backup and rerun the upgrade if entries are corrupt.","Backup the p directory before rerunning so a partial upgrade can be retried cleanly."],"exampleFix":"// before\n./dgraph upgrade offline -w v21.03.2 -d ./p\n// after (stop server first to release badger lock)\nsystemctl stop dgraph\n./dgraph upgrade offline -w v21.03.2 -d ./p","handlingStrategy":"try-catch","validationCode":"// Ensure the DB is open, writable, and has space before upgrade\nif err := db.Update(func(txn *badger.Txn) error { return txn.Set([]byte(\"__probe__\"), []byte(\"1\")) }); err != nil {\n\tlog.Fatalf(\"badger not writable: %v\", err)\n}","typeGuard":"func isPersistedQuerySchemaWriteErr(err error) bool {\n\treturn err != nil && strings.Contains(err.Error(), \"while updating persisted query's schema\")\n}","tryCatchPattern":"if err := upgrade.OfflineUpgradeFrom2011To2103(db); err != nil {\n\tlog.Fatalf(\"%+v\", err) // exposes badger write failure under this message\n}","preventionTips":["Free disk space (badger writes fail hard when full)","Close/stop the server so the badger LOCK is not held elsewhere","Snapshot the p directory before the upgrade","Monitor badger vlog/commit logs for earlier I/O errors"],"tags":["badger","migration","schema","persisted-query"],"backgroundTag":"offline-schema-upgrade-failed","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}