---
title: "Cloudflare D1 Index Recommendations Migration Fix Log"
slug: "cloudflare-d1-index-recommendations-migration-fix-log"
description: "Field notes on migrating to Cloudflare D1 Insights index recommendations, including CLI commands, API limits, hidden billing traps, and break-even thresholds."
author: "Hamdi Soudani"
category: "cloud-gpu-infra"
archetype: "migration-fix-log"
published_at: "2026-11-26T17:03:35.501+00:00"
updated_at: "2026-11-26T17:03:35.63334+00:00"
canonical_url: "https://pyvren.com/blog/cloudflare-d1-index-recommendations-migration-fix-log"
reading_time_minutes: 4
word_count: 724
quality_score: 93
tags: ["cloudflare-d1","index-recommendations","d1-insights","sqlite","database-observability"]
keywords: ["cloudflare d1 index recommendations","d1 insights create index","cloudflare d1 rows read charges","npx cf d1 insights recommendations","d1 index recommendations api"]
sources: ["https://developers.cloudflare.com/changelog/post/2026-11-25-d1-index-recommendations/","https://developers.cloudflare.com/d1/observability/metrics-analytics/index-recommendations/","https://developers.cloudflare.com/changelog/"]
---

# Cloudflare D1 Index Recommendations Migration Fix Log

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

## Key Facts

- **Recommendations per database:** Up to 10 recommendations, highest impact first ([source](https://developers.cloudflare.com/d1/observability/metrics-analytics/index-recommendations/))
- **CLI command to list recommendations:** npx cf d1 insights recommendations ([source](https://developers.cloudflare.com/changelog/post/2026-11-25-d1-index-recommendations/))
- **API endpoint for recommendations:** https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/d1/insights/recommendations ([source](https://developers.cloudflare.com/d1/observability/metrics-analytics/index-recommendations/))
- **Recommendation expiry:** 7 days without refresh ([source](https://developers.cloudflare.com/d1/observability/metrics-analytics/index-recommendations/))
- **API limit parameter range:** 1 to 100 recommendations per page, default 20 ([source](https://developers.cloudflare.com/d1/observability/metrics-analytics/index-recommendations/))
- **Database ID filter limit:** Up to 50 database IDs per request ([source](https://developers.cloudflare.com/d1/observability/metrics-analytics/index-recommendations/))
- **D1 rows-read pricing:** $0.10 per million rows read ([source](https://developers.cloudflare.com/d1/observability/metrics-analytics/index-recommendations/))
- **Workers compute pricing:** $5.21 per GB-s compute, $0.18 per GB network egress ([source](https://developers.cloudflare.com/workers/platform/pricing/))

## 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](https://developers.cloudflare.com/d1/observability/metrics-analytics/index-recommendations/) |
| API limit parameter | 1 to 100 per page, default 20 | [Index recommendations · Cloudflare D1 docs](https://developers.cloudflare.com/d1/observability/metrics-analytics/index-recommendations/) |
| Database ID filter | Up to 50 database IDs per request | [Index recommendations · Cloudflare D1 docs](https://developers.cloudflare.com/d1/observability/metrics-analytics/index-recommendations/) |
| Recommendation expiry | 7 days without refresh | [Index recommendations · Cloudflare D1 docs](https://developers.cloudflare.com/d1/observability/metrics-analytics/index-recommendations/) |
| Insights setting scope | Account-wide; applies to every database | [Index recommendations · Cloudflare D1 docs](https://developers.cloudflare.com/d1/observability/metrics-analytics/index-recommendations/) |
| CLI entry point | `npx cf d1 insights recommendations` | [D1 Insights index recommendations · Changelog](https://developers.cloudflare.com/changelog/post/2026-11-25-d1-index-recommendations/) |
| D1 rows-read pricing | $0.10 per million rows read | [Index recommendations · Cloudflare D1 docs](https://developers.cloudflare.com/d1/observability/metrics-analytics/index-recommendations/) |
| Workers compute pricing | $5.21 per GB-s compute, $0.18 per GB network egress | [Workers platform pricing](https://developers.cloudflare.com/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:

```bash
npx cf d1 insights recommendations
```

List recommendations for specific databases:

```bash
npx cf d1 insights recommendations --database-id <DATABASE_ID_1>,<DATABASE_ID_2>
```

Fetch recommendations via the REST API:

```bash
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`:

```bash
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:

```sql
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:

```hcl
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:

```jsonc
{
  "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](https://developers.cloudflare.com/d1/observability/metrics-analytics/index-recommendations/og.png?v=df486027f3a86d41)

### Primary Sources

- [D1 Insights index recommendations · Changelog](https://developers.cloudflare.com/changelog/post/2026-11-25-d1-index-recommendations/)
- [Index recommendations · Cloudflare D1 docs](https://developers.cloudflare.com/d1/observability/metrics-analytics/index-recommendations/)
- [Changelogs | Cloudflare Docs](https://developers.cloudflare.com/changelog/)

## 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.

## Primary Sources

- https://developers.cloudflare.com/changelog/post/2026-11-25-d1-index-recommendations/
- https://developers.cloudflare.com/d1/observability/metrics-analytics/index-recommendations/
- https://developers.cloudflare.com/changelog/
