Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Comprehensive Cloudflare platform skill covering Workers, D1, R2, KV, AI, Durable Objects, and security.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/hyperdrive/configuration.md
1# Configuration23See [README.md](./README.md) for overview.45## Create Config67**PostgreSQL:**8```bash9# Basic10npx wrangler hyperdrive create my-db \11--connection-string="postgres://user:pass@host:5432/db"1213# Custom cache14npx wrangler hyperdrive create my-db \15--connection-string="postgres://..." \16--max-age=120 --swr=301718# No cache19npx wrangler hyperdrive create my-db \20--connection-string="postgres://..." \21--caching-disabled=true22```2324**MySQL:**25```bash26npx wrangler hyperdrive create my-db \27--connection-string="mysql://user:pass@host:3306/db"28```2930## wrangler.jsonc3132```jsonc33{34"compatibility_date": "2025-01-01", // Use latest for new projects35"compatibility_flags": ["nodejs_compat"],36"hyperdrive": [37{38"binding": "HYPERDRIVE",39"id": "<HYPERDRIVE_ID>",40"localConnectionString": "postgres://user:pass@localhost:5432/dev"41}42]43}44```4546**Generate TypeScript types:** Run `npx wrangler types` to auto-generate `worker-configuration.d.ts` from your wrangler.jsonc.4748**Multiple configs:**49```jsonc50{51"hyperdrive": [52{"binding": "HYPERDRIVE_CACHED", "id": "<ID1>"},53{"binding": "HYPERDRIVE_NO_CACHE", "id": "<ID2>"}54]55}56```5758## Management5960```bash61npx wrangler hyperdrive list62npx wrangler hyperdrive get <ID>63npx wrangler hyperdrive update <ID> --max-age=18064npx wrangler hyperdrive delete <ID>65```6667## Config Options6869Hyperdrive create/update CLI flags:7071| Option | Default | Notes |72|--------|---------|-------|73| `--caching-disabled` | `false` | Disable caching |74| `--max-age` | `60` | Cache TTL (max 3600s) |75| `--swr` | `15` | Stale-while-revalidate |76| `--origin-connection-limit` | 20/100 | Free/paid |77| `--access-client-id` | - | Tunnel auth |78| `--access-client-secret` | - | Tunnel auth |79| `--sslmode` | `require` | PostgreSQL only |8081## Smart Placement Integration8283For Workers making **multiple queries** per request, enable Smart Placement to execute near your database:8485```jsonc86{87"compatibility_date": "2025-01-01",88"compatibility_flags": ["nodejs_compat"],89"placement": {90"mode": "smart"91},92"hyperdrive": [93{94"binding": "HYPERDRIVE",95"id": "<HYPERDRIVE_ID>"96}97]98}99```100101**Benefits:** Multi-query Workers run closer to DB, reducing round-trip latency. See [patterns.md](./patterns.md) for examples.102103## Private DB via Tunnel104105```106Worker → Hyperdrive → Access → Tunnel → Private Network → DB107```108109**Setup:**110```bash111# 1. Create tunnel112cloudflared tunnel create my-db-tunnel113114# 2. Configure hostname in Zero Trust dashboard115# Domain: db-tunnel.example.com116# Service: TCP -> localhost:5432117118# 3. Create service token (Zero Trust > Service Auth)119# Save Client ID/Secret120121# 4. Create Access app (db-tunnel.example.com)122# Policy: Service Auth token from step 3123124# 5. Create Hyperdrive125npx wrangler hyperdrive create my-private-db \126--host=db-tunnel.example.com \127--user=dbuser --password=dbpass --database=prod \128--access-client-id=<ID> --access-client-secret=<SECRET>129```130131**⚠️ Don't specify `--port` with Tunnel** - port configured in tunnel service settings.132133## Local Dev134135**Option 1: Local (RECOMMENDED):**136```bash137# Env var (takes precedence)138export CLOUDFLARE_HYPERDRIVE_LOCAL_CONNECTION_STRING_HYPERDRIVE="postgres://user:pass@localhost:5432/dev"139npx wrangler dev140141# wrangler.jsonc142{"hyperdrive": [{"binding": "HYPERDRIVE", "localConnectionString": "postgres://..."}]}143```144145**Remote DB locally:**146```bash147# PostgreSQL148export CLOUDFLARE_HYPERDRIVE_LOCAL_CONNECTION_STRING_HYPERDRIVE="postgres://user:pass@remote:5432/db?sslmode=require"149150# MySQL151export CLOUDFLARE_HYPERDRIVE_LOCAL_CONNECTION_STRING_HYPERDRIVE="mysql://user:pass@remote:3306/db?sslMode=REQUIRED"152```153154**Option 2: Remote execution:**155```bash156npx wrangler dev --remote # Uses deployed config, affects production157```158159See [api.md](./api.md), [patterns.md](./patterns.md), [gotchas.md](./gotchas.md).160