{"record":{"id":"3b05ac28ed67fab9","repo":"dgraph-io/dgraph","slug":"while-upgrading-persisted-query","errorCode":null,"errorMessage":"while upgrading persisted query","messagePattern":"while upgrading persisted query","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upgrade/change_v21.03.0.go","lineNumber":441,"sourceCode":"\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}\n\treturn nil\n}\n\n// OfflineUpgradeFrom2011To2103 upgrades a p directory restored from backup of 20.11 to the changes\n// in 21.03. It fixes the cors, schema and drops the deprecated types/predicates.\nfunc OfflineUpgradeFrom2011To2103(db *badger.DB) error {\n\tif err := fixPersistedQuery(db); err != nil {\n\t\treturn errors.Wrapf(err, \"while upgrading persisted query\")\n\t}\n\treturn errors.Wrapf(fixCors(db), \"while upgrading cors\")\n}\n","sourceCodeStart":423,"sourceCodeEnd":445,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/upgrade/change_v21.03.0.go#L423-L445","documentation":"OfflineUpgradeFrom2011To2103 wraps any fixPersistedQuery failure with this message. It means the persisted-query schema/type rewrite portion of the 20.11 -> 21.03 offline upgrade failed; the wrapped error chain contains the specific badger/transform cause.","triggerScenarios":"Calling OfflineUpgradeFrom2011To2103 (via dgraph upgrade offline) where fixPersistedQuery returns any error: failure building the schema update, marshaling, or writing schema/type badger entries.","commonSituations":"Version migration from Dgraph 20.11 backups to 21.03; corrupted restore output; badger write errors during migration.","solutions":["Print the full error chain (%+v) to find the wrapped cause from fixPersistedQuery and fix it.","Re-restore the backup and retry the upgrade from a clean state.","Ensure the p directory is not in use by a running dgraph instance during the offline upgrade.","Check disk space and filesystem health on the node before rerunning."],"exampleFix":"// before\nif err := upgrade.OfflineUpgradeFrom2011To2103(db); err != nil { log.Fatal(err) } // prints only top message\n// after\nif err := upgrade.OfflineUpgradeFrom2011To2103(db); err != nil { log.Fatalf(\"%+v\", err) } // full chain","handlingStrategy":"try-catch","validationCode":"// Validate from-version is 20.11.x before calling this upgrade path\nif !strings.HasPrefix(version, \"v20.11.\") {\n\tlog.Fatalf(\"OfflineUpgradeFrom2011To2103 expects a v20.11.x source, got %s\", version)\n}","typeGuard":"func isPersistedQueryUpgradeErr(err error) bool {\n\treturn err != nil && strings.Contains(err.Error(), \"while upgrading persisted query\")\n}","tryCatchPattern":"if err := upgrade.OfflineUpgradeFrom2011To2103(db); err != nil {\n\tlog.Fatalf(\"persisted query upgrade failed: %+v\", err)\n}","preventionTips":["Only call this upgrade on backups restored from v20.11.x","Backup the p directory before invoking","Log with %+v to surface the inner fixPersistedQuery cause","Run on a maintenance window with the server stopped"],"tags":["migration","offline-upgrade","persisted-query","badger"],"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"}