dgraph-io/dgraph · error
while updating persisted query's schema
Error message
while updating persisted query's schema
What it means
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.
Source
Thrown at upgrade/change_v21.03.0.go:415
}
// Update the tokenizer in the schema.
su := pb.SchemaUpdate{
Predicate: x.AttrInRootNamespace("dgraph.graphql.p_query"),
ValueType: pb.Posting_STRING,
Directive: pb.SchemaUpdate_INDEX,
Tokenizer: []string{"sha256"},
}
data, err := proto.Marshal(&su)
if err != nil {
return err
}
entry := &badger.Entry{}
entry.Key = x.SchemaKey(x.AttrInRootNamespace("dgraph.graphql.p_query"))
entry.Value = data
entry.UserMeta = posting.BitSchemaPosting
if err := update(entry); err != nil {
return errors.Wrap(err, "while updating persisted query's schema")
}
// Update the type.
tu := pb.TypeUpdate{
TypeName: x.AttrInRootNamespace("dgraph.graphql.persisted_query"),
Fields: []*pb.SchemaUpdate{&su},
}
data, err = proto.Marshal(&tu)
if err != nil {
return err
}
entry = &badger.Entry{}
entry.Key = x.TypeKey(x.AttrInRootNamespace("dgraph.graphql.persisted_query"))
entry.Value = data
entry.UserMeta = posting.BitSchemaPosting
if err := update(entry); err != nil {
return errors.Wrap(err, "while updating persisted query's type")
}View on GitHub (pinned to 759e242be6)
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.
Example fix
// before ./dgraph upgrade offline -w v21.03.2 -d ./p // after (stop server first to release badger lock) systemctl stop dgraph ./dgraph upgrade offline -w v21.03.2 -d ./p
Defensive patterns
Strategy: try-catch
Validate before calling
// Ensure the DB is open, writable, and has space before upgrade
if err := db.Update(func(txn *badger.Txn) error { return txn.Set([]byte("__probe__"), []byte("1")) }); err != nil {
log.Fatalf("badger not writable: %v", err)
} Type guard
func isPersistedQuerySchemaWriteErr(err error) bool {
return err != nil && strings.Contains(err.Error(), "while updating persisted query's schema")
} Try / catch
if err := upgrade.OfflineUpgradeFrom2011To2103(db); err != nil {
log.Fatalf("%+v", err) // exposes badger write failure under this message
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Running the offline upgrade on a restored 20.11 backup; badger database locked by another process; insufficient disk space; corrupted LSM/manifiest issues.
Related errors
- Error while updating GraphQL schema.
- while updating persisted query's type
- while upgrading persisted query
- Error while dropping depreciated preds/types.
- while upgrading cors
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/807ae2af1b41bf2a.
Report an issue: GitHub.