{"record":{"id":"f4f9e2813ad60734","repo":"dgraph-io/dgraph","slug":"error-updating-the-schema-for-persistent-query-w","errorCode":null,"errorMessage":"error updating the schema for persistent query, %w","messagePattern":"error updating the schema for persistent query, %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upgrade/change_v21.03.0.go","lineNumber":168,"sourceCode":"\tif err != nil {\n\t\treturn errors.Wrap(err, \"while getting jwt auth token\")\n\t}\n\n\t// Get persisted queries.\n\tqueryData := make(map[string][]pquery)\n\tif err := getQueryResult(dg, queryPersistedQuery_v21_03_0, &queryData); err != nil {\n\t\treturn errors.Wrap(err, \"error querying persisted queries\")\n\t}\n\n\t// Update the schema with new indexer for persisted query.\n\tupdatedSchema := `\n\t\t<dgraph.graphql.p_query>: string @index(sha256) .\n\t\ttype <dgraph.graphql.persisted_query> {\n\t\t\t<dgraph.graphql.p_query>\n\t\t}\n\t\t\t`\n\tif err := alterWithClient(dg, &api.Operation{Schema: updatedSchema}); err != nil {\n\t\treturn fmt.Errorf(\"error updating the schema for persistent query, %w\", err)\n\t}\n\n\t// Reinsert these queries. Note that upsert won't work here as 'dgraph.graphql.p_query' is\n\t// graphql reserved type.\n\theader := http.Header{}\n\theader.Set(\"X-Dgraph-AccessToken\", jwt.AccessJwt)\n\theader.Set(\"X-Dgraph-AuthToken\", Upgrade.Conf.GetString(authToken))\n\tgraphqlUrl := Upgrade.Conf.GetString(alphaHttp) + \"/graphql\"\n\tfor _, pquery := range queryData[\"pquery\"] {\n\t\tupdateSchemaParams := &GraphQLParams{\n\t\t\tQuery: pquery.Query,\n\t\t\tExtensions: &schema.RequestExtensions{PersistedQuery: schema.PersistedQuery{\n\t\t\t\tSha256Hash: pquery.SHA,\n\t\t\t}},\n\t\t\tHeaders: header,\n\t\t}\n\n\t\tresp, err := makeGqlRequest(updateSchemaParams, graphqlUrl)","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/upgrade/change_v21.03.0.go#L150-L186","documentation":"upgradePersitentQuery alters the schema to add the sha256 index on <dgraph.graphql.p_query> and the persisted_query type. Failure is wrapped with fmt.Errorf as 'error updating the schema for persistent query, %w'. The alter operation on the Dgraph cluster was rejected or failed.","triggerScenarios":"alterWithClient(dg, &api.Operation{Schema: updatedSchema}) errors — ACL forbids alter, Alpha read-only, or the index build fails on existing data.","commonSituations":"ACL creds missing/insufficient; large existing p_query data slowing index build causing timeouts; cluster in drain/read-only mode during upgrade.","solutions":["Run the upgrade with admin ACL credentials.","Ensure the cluster is writable (not in drain/read-only mode).","Check Alpha logs for index-build failures and resolve before retrying.","Apply the schema change manually via /alter and re-run the upgrade."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"curl -s http://localhost:8080/state | jq '.max_leases // empty'; curl -s http://localhost:8080/alter -XPOST -d '{\"schema\":\"<dgraph.graphql.p_query>: string @index(sha256) .\"}'","typeGuard":null,"tryCatchPattern":"if err := alterWithClient(dg, &api.Operation{Schema: updatedSchema}); err != nil {\n\t// inspect cause: ACL vs read-only vs index-build failure, then retry\n\treturn fmt.Errorf(\"error updating the schema for persistent query, %w\", err)\n}","preventionTips":["Run with admin ACL credentials","Ensure cluster is writable and has disk headroom for index builds","Apply schema changes during low-traffic windows"],"tags":["dgraph","upgrade","schema","alter","index"],"backgroundTag":"schema-alter-failed","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}