dgraph-io/dgraph · error
while updating persisted query's type
Error message
while updating persisted query's type
What it means
This is the sibling failure in fixPersistedQuery: after updating the p_query schema, the function writes a new type entry for dgraph.graphql.persisted_query. A badger write failure on the TypeKey entry is wrapped with this message.
Source
Thrown at upgrade/change_v21.03.0.go:432
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")
}
return nil
}
// OfflineUpgradeFrom2011To2103 upgrades a p directory restored from backup of 20.11 to the changes
// in 21.03. It fixes the cors, schema and drops the deprecated types/predicates.
func OfflineUpgradeFrom2011To2103(db *badger.DB) error {
if err := fixPersistedQuery(db); err != nil {
return errors.Wrapf(err, "while upgrading persisted query")
}
return errors.Wrapf(fixCors(db), "while upgrading cors")
}
View on GitHub (pinned to 759e242be6)
Solutions
- Inspect the wrapped badger error and fix the underlying cause (disk space, permissions, lock).
- Verify the server is fully stopped before running the offline upgrade so the p directory is not locked.
- Re-restore from backup and rerun the upgrade if the type entry is corrupt.
- Keep a pre-upgrade copy of the p directory to allow a clean retry.
Example fix
// before df -h # disk full -> write fails # after freeing space dgraph upgrade offline -w v21.03.0 -d ./p
Defensive patterns
Strategy: try-catch
Validate before calling
// Sanity-check write access and space before running the upgrade
if fi, err := os.Statfs(pDir); err == nil && fi.Bavail*uint64(fi.Bsize) < 1<<30 {
log.Fatal("less than 1GB free; upgrade writes may fail")
} Type guard
func isPersistedQueryTypeWriteErr(err error) bool {
return err != nil && strings.Contains(err.Error(), "while updating persisted query's type")
} Try / catch
if err := upgrade.OfflineUpgradeFrom2011To2103(db); err != nil {
log.Fatalf("type update failed: %+v", err)
} Prevention
- Ensure >1GB free space on the p-directory volume
- Run upgrades with the server stopped to avoid lock contention
- Verify badger directory integrity with dgraph debug first
- Retry from a clean re-restore if entries were partially written
When it happens
Trigger: During OfflineUpgradeFrom2011To2103, badger.DB.Write fails for the entry keyed by TypeKey(dgraph.graphql.persisted_query) — e.g. disk full, DB closed, badger internal error.
Common situations: Offline migration of a 20.11 backup to 21.03; badger lock contention; storage exhaustion on the node performing the upgrade.
Related errors
- while upgrading persisted query
- Error while updating GraphQL schema.
- Error while dropping depreciated preds/types.
- while updating persisted query's schema
- while upgrading cors
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/1470d5b3b1462fa1.
Report an issue: GitHub.