/planetscale:planetscale-query-insights-and-tagsfrom planetscale
Inspects PlanetScale query behavior via Insights API to identify slow, high-load, or risky queries and recommends SQLCommenter-style query tags for attribution and safe Traffic Control.
Ships in planetscale. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Use PlanetScale Insights to understand query behavior, then recommend SQLCommenter-compatible tags that make future diagnosis and Traffic Control possible. Do not change database settings or repository code without approval.
For the selected database and branch, inspect:
sort=cpuTime or
sort=percentCpuTime on the Insights API).index_usages and
routing_index_usages; get the trend from the dashboard Vindexes tab or
by comparing API windows. Treat missing or declining relevant-vindex
usage as an indexing or routing investigation input, not as proof that a
new index is required.Query Insights is public API: read-only GET endpoints under
organizations/{org}/databases/{db}/branches/{branch}, authorized by a
service token or OAuth token with read_databases/read_database.
/insights — aggregated statistics per query pattern over the requested
window. Set the window with from/to (ISO 8601) or period (for
example 1h, 24h); search SQL patterns with q; sort server-side with
sort and dir — sort keys include count, errorCount, rowsRead,
totalTime, cpuTime, ioTime, percentTime, percentCpuTime,
p50Latency, p99Latency, maxLatency, egressBytes, and the
trafficControlWarnings/trafficControlThrottled family. Filter with
tablet_type (primary, replica, rdonly) and type (SELECT,
INSERT, UPDATE, DELETE); trim responses with fields; paginate
with page/per_page./insights/{fingerprint} — individual collected executions for a
pattern (timestamps, duration, rows, username, client address, error
message). Available regardless of raw query collection; raw collection
adds literal parameter values to these records.
/insights/{fingerprint}/summary returns the single-pattern aggregate;
/insights/queries/{id} fetches one execution./insights/errors — error fingerprints with counts and messages (q
searches the error message; sort by count, lastRun, totalTime, or
timePerQuery). /insights/errors/{fingerprint} lists the failing
executions behind one error fingerprint./insights/anomalies and /insights/anomalies/{id} — anomaly windows
with per-query correlation coefficients identifying which patterns moved
with the anomaly./insights/tags — tag keys with observed values (values_limit,
literal_values_only, and fingerprint/keyspace filters);
/insights/tags/{tag} for a single key. /insights/tags/summaries
groups the full statistics schema by one or more tag keys via the tags
parameter — use it to attribute load to routes, jobs, or features
without client-side aggregation./insights/{fingerprint}/traffic/budgets — the Traffic Control budgets
and rules that affect a fingerprint (Postgres).Aggregates cover the requested window. Duration fields use names like
sum_total_duration_millis, with explicit share-of-window percent fields
(sum_total_duration_percent); both totals and percentages are reliable
for the window requested.
The response schema is shared across engines, but some fields are
engine-specific: CPU/IO durations and block-cache statistics
(sum_cpu_duration_millis, blocks_read, block_cache_hit_ratio, …) are
populated for Postgres; shard queries, keyspaces, tablet_type, and
routing-index (vindex) usage are populated for Vitess.
For each expensive or anomalous query, determine:
/insights/tags shows which
keys and values are present, and /insights/tags/summaries?tags=...
attributes load per tag value. In the Vitess dashboard, filter the query
table with tag:key:value and drill into query details to see tags on
individual executions. Built-in query metadata and SQLCommenter tags are
both valid attribution sources.Check whether raw query / complete query collection is enabled. On
Postgres the effective state is the pginsights.raw_queries cluster
parameter (per branch, dashboard Extensions tab, default false); the
database API object's insights_raw_queries field is a separate surface.
When the two differ, report the cluster parameter as the effective state
and do not describe the difference as an inconsistency. On Vitess there
is no cluster parameter; the database API's insights_raw_queries field
is the effective state.
Report it as a capability state, not a risk posture. Raw query collection
records literal parameter values per execution, which pattern-level Insights
data does not provide. It is the mechanism for isolating which specific
invocation of a pattern is pathological. Execution-level records are
retrievable from /insights/{fingerprint} with or without raw collection;
raw collection adds the literal parameter values to those records.
When it is disabled, the finding is a capability gap: identify the query patterns in this assessment where pattern-level data is insufficient (unexplained latency variance within a fingerprint, tenant- or parameter-dependent behavior) and state that raw collection would resolve them. State the operational property once, as fact: literal values become visible to the observability pipeline. Where the customer's data-handling requirements constrain this, scoped enablement (incident windows, defined retention) and leaving collection disabled are both valid outcomes — record the rationale rather than a default judgment in either direction.
Tags and raw collection are complementary instruments: tags attribute a pattern to a code path; raw collection identifies the specific invocation. Assessments should evaluate both.
Recommend this baseline tag set:
application: stable app name.service: service or process name.environment: production, staging, development.route: normalized route template, for example /accounts/:id/orders, not /accounts/123/orders.controller: framework controller name where applicable.action: framework action name where applicable.job: background job class or worker name.queue: background queue.feature: bounded feature name for traffic classes like export, report, search, billing, checkout.release_sha: short git SHA or deploy identifier.source: app, worker, script, agent, mcp, bi, integration.tenant_tier: free, pro, enterprise, internal, only if bounded.Do not recommend these tags by default:
user_idrequest_idtenant_idemailsession_idIf the customer needs tenant-level isolation, recommend a bounded abstraction first, such as tenant tier, cell, shard, or customer class. Tenant ID is only acceptable with explicit approval after cardinality and privacy review.
Flag a tag as unsafe when:
Recommend normalizing at the application boundary.
For each top query pattern, produce:
Recommend SQLCommenter instrumentation when query attribution is weak.
Recommend replacing high-cardinality tags with bounded values.
For Postgres only, recommend warn mode budgets for expensive but important routes, jobs, analytics, exports, or third-party integrations.
For Vitess, recommend turning open schema recommendations into branch/deploy-request work. For Postgres, recommend turning them into reviewed migrations against a non-production branch.
Recommend a repository PR when the expensive query is caused by N+1, missing pagination, accidental eager load, unbounded export, broad search, or polling.
Do not:
Without explicit approval.
Return:
End with:
“No Insights, tag, repository, or Traffic Control changes have been applied.”
What SKILL.md sets; muted values are Claude Code's defaults
claude plugin install planetscale@claude-plugins-official19 skills in this plugin
/planetscale-safe-orchestratorMaster skill that runs the full PlanetScale safe best-practices assessment — inventory, engine review, Insights, Traffic Control, webhooks, schema recommendations, codebase instrumentation, and agent operating model — then produces a unified recommendations report. Never applies changes without explicit approval. Use when the user asks to run the full assessment, all skills, or PlanetScale best-practices review./planetscale-readonly-inventoryCollect read-only evidence about PlanetScale org, database, branches, webhooks, backups, roles, Insights, recommendations, and traffic configuration./planetscale-vitess-safety-reviewOther plugins' skills for the same job