dgraph-io/dgraph · error
error updating the schema for persistent query, %w
Error message
error updating the schema for persistent query, %w
What it means
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.
Source
Thrown at upgrade/change_v21.03.0.go:168
if err != nil {
return errors.Wrap(err, "while getting jwt auth token")
}
// Get persisted queries.
queryData := make(map[string][]pquery)
if err := getQueryResult(dg, queryPersistedQuery_v21_03_0, &queryData); err != nil {
return errors.Wrap(err, "error querying persisted queries")
}
// Update the schema with new indexer for persisted query.
updatedSchema := `
<dgraph.graphql.p_query>: string @index(sha256) .
type <dgraph.graphql.persisted_query> {
<dgraph.graphql.p_query>
}
`
if err := alterWithClient(dg, &api.Operation{Schema: updatedSchema}); err != nil {
return fmt.Errorf("error updating the schema for persistent query, %w", err)
}
// Reinsert these queries. Note that upsert won't work here as 'dgraph.graphql.p_query' is
// graphql reserved type.
header := http.Header{}
header.Set("X-Dgraph-AccessToken", jwt.AccessJwt)
header.Set("X-Dgraph-AuthToken", Upgrade.Conf.GetString(authToken))
graphqlUrl := Upgrade.Conf.GetString(alphaHttp) + "/graphql"
for _, pquery := range queryData["pquery"] {
updateSchemaParams := &GraphQLParams{
Query: pquery.Query,
Extensions: &schema.RequestExtensions{PersistedQuery: schema.PersistedQuery{
Sha256Hash: pquery.SHA,
}},
Headers: header,
}
resp, err := makeGqlRequest(updateSchemaParams, graphqlUrl)View on GitHub (pinned to 759e242be6)
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.
Defensive patterns
Strategy: try-catch
Validate before calling
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) ."}' Try / catch
if err := alterWithClient(dg, &api.Operation{Schema: updatedSchema}); err != nil {
// inspect cause: ACL vs read-only vs index-build failure, then retry
return fmt.Errorf("error updating the schema for persistent query, %w", err)
} Prevention
- Run with admin ACL credentials
- Ensure cluster is writable and has disk headroom for index builds
- Apply schema changes during low-traffic windows
When it happens
Trigger: alterWithClient(dg, &api.Operation{Schema: updatedSchema}) errors — ACL forbids alter, Alpha read-only, or the index build fails on existing data.
Common situations: ACL creds missing/insufficient; large existing p_query data slowing index build causing timeouts; cluster in drain/read-only mode during upgrade.
Related errors
- error deleting old acl predicates: %w
- error deleting old predicate %s
- error deleting old type %s
- error querying graphql schema
- illegal rune found "%c", expecting {
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/f4f9e2813ad60734.
Report an issue: GitHub.