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.
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 element | Limit or cost | Source |
|---|---|---|
| Recommendations per database | Up to 10, sorted by estimated impact | Index recommendations · Cloudflare D1 docs |
| API limit parameter | 1 to 100 per page, default 20 | Index recommendations · Cloudflare D1 docs |
| Database ID filter | Up to 50 database IDs per request | Index recommendations · Cloudflare D1 docs |
| Recommendation expiry | 7 days without refresh | Index recommendations · Cloudflare D1 docs |
| Insights setting scope | Account-wide; applies to every database | Index recommendations · Cloudflare D1 docs |
| CLI entry point | npx cf d1 insights recommendations | D1 Insights index recommendations · Changelog |
| D1 rows-read pricing | $0.10 per million rows read | Index recommendations · Cloudflare D1 docs |
| Workers compute pricing | $5.21 per GB-s compute, $0.18 per GB network egress | Workers 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:
npx cf d1 insights recommendationsList recommendations for specific databases:
npx cf d1 insights recommendations --database-id <DATABASE_ID_1>,<DATABASE_ID_2>Fetch recommendations via the REST API:
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:
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:
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:
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:
{
"d1_databases": [
{
"binding": "DB",
"database_name": "events-db",
"database_id": "<DATABASE_ID>"
}
]
}Migration Checklist & Break-Even Thresholds
- Enable Insights in the Cloudflare dashboard, CLI, or API. The setting applies account-wide.
- Review the Recommendations card on the Metrics tab of each D1 database. Up to 10 recommendations appear, highest impact first.
- Test each
CREATE INDEXstatement on a staging copy before applying to production. D1 does not validate suggestions against your schema. - 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.
- Monitor write latency after index creation. Every write now maintains additional indexes.
- Set a 7-day refresh watch. Recommendations expire after 7 days without a background analysis refresh.
- Rollback plan:
DROP INDEXthe 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.

Primary Sources
Reader Q&A
Frequently Asked Questions
Can I request an on-demand index analysis for a D1 database?
Does turning off Insights affect D1 billing or query metrics?
Are suggested CREATE INDEX statements validated against my schema before delivery?
At what write latency should I skip index recommendations?
Bibliography & Verification
Primary Sources & References
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.
Keep Reading
Related Dispatches
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.