pscale inspect
Run bounded, read-only diagnostic queries against a PlanetScale database branch using ephemeral credentials. Checks adapt to MySQL/Vitess or PostgreSQL and complement the server-side production-traffic analysis in pscale insights.
Start with a combined report
# Machine-readable report of every applicable check
pscale inspect all <database> <branch> --org <org> --format json
# PostgreSQL: target the application database instead of the default "postgres"
pscale inspect all <database> <branch> --org <org> \
--dbname <postgres-database> --format json
# Vitess: target one exact shard; no command fans out across every shard
pscale inspect all <database> <branch> --org <org> \
--keyspace '<keyspace>/<shard>' --format json
# Run against a replica when primary-only evidence is unnecessary
pscale inspect all <database> <branch> --org <org> --replica --format json
Always pass --org explicitly in agent workflows so the organization target is unambiguous. The default ephemeral role is reader; keep it unless the connection itself fails for a justified permission reason. On PostgreSQL, --dbname defaults to postgres, the temporary connection uses sslmode=verify-full by default, and the reader role may lack CONNECT on another database. Use --role admin only after confirming that this is the actual failure and that elevated access is acceptable.
Check catalog
table-sizes Tables by total size, largest first
index-sizes Indexes by size, largest first
unused-indexes Indexes with little or no use
redundant-indexes Indexes made redundant by another index
invalid-indexes Invalid PostgreSQL indexes
seq-scans Tables receiving full-table scans
long-running-queries Queries running longer than five minutes
locks Blocking locks and blocked sessions
outliers Queries by cumulative time (PostgreSQL pg_stat_statements)
calls Most-called queries (PostgreSQL pg_stat_statements)
bloat PostgreSQL bloat or MySQL fragmentation
vacuum-stats PostgreSQL autovacuum/autoanalyze health
replication-slots PostgreSQL slot status, retained WAL, and lag
subscriptions PostgreSQL logical-replication table progress
all Every applicable check in one report
Run one check with the same positional arguments and target flags:
pscale inspect locks <database> <branch> --org <org> --format json
pscale inspect seq-scans <database> <branch> --org <org> --replica --format json
pscale inspect table-sizes <database> <branch> --org <org> --keyspace '<keyspace>/<shard>' --format csv
Single checks support human, JSON, and CSV output. inspect all supports human and JSON; CSV is rejected because the checks have different result schemas.
Engine and target semantics
- Vitess/MySQL: checks query
information_schema, mysql, and sys. On sharded databases, one run reflects one shard's MySQL instance. Use pscale sql <database> <branch> --query "SHOW VITESS_SHARDS" to enumerate targets, then pass --keyspace <keyspace>/<shard>; append @replica when an exact tablet type is needed.
- PostgreSQL: checks query
pg_catalog and pg_stat views for one PostgreSQL database selected by --dbname. outliers and calls require pg_stat_statements.
- Checks unavailable for the detected engine return a skipped explanation and, when available, a copy-pasteable
pscale insights next step.
- Each check is bounded and has a 30-second query timeout. In
inspect all, one failed check is recorded as skipped instead of aborting the remaining report.
Investigation workflow
- Confirm organization, database, branch, engine, and exact database/keyspace/shard target.
- Run
inspect all ... --format json with the default reader role.
- Separate successful results, empty results, skipped checks, and failed/timed-out checks.
- Follow the report's
next_steps with pscale insights queries|errors|anomalies|recommendations for traffic-aware evidence.
- Treat index, vacuum, lock, and query findings as diagnostic evidence—not automatic authorization to kill sessions or change schema.
- For any write or destructive remediation, switch to the relevant skill/workflow and obtain explicit user approval.
Related skills
- pscale-insights — server-side query statistics, errors, anomalies, and schema recommendations
- pscale-sql — deliberate one-off SQL with role and destructive-query safeguards
- pscale-branch — connection inspection and explicitly approved connection/query termination
References
See references/commands.md for the verified command synopsis, flags, and engine applicability.
1---2name: pscale-inspect3description: Run read-only PlanetScale database diagnostics with pscale inspect for table/index size, scans, locks, long-running queries, bloat, autovacuum, replication, and related health checks. Use for point-in-time MySQL/Vitess or PostgreSQL diagnostics, exact shard targeting, replica inspection, or when a user asks for pscale inspect. Triggers on pscale inspect, database diagnostics, table sizes, index sizes, unused indexes, redundant indexes, sequential scans, long-running queries, blocking locks, bloat, vacuum stats, replication slots, subscriptions.4---56# pscale inspect78Run bounded, read-only diagnostic queries against a PlanetScale database branch using ephemeral credentials. Checks adapt to MySQL/Vitess or PostgreSQL and complement the server-side production-traffic analysis in `pscale insights`.910## Start with a combined report1112```bash13# Machine-readable report of every applicable check14pscale inspect all <database> <branch> --org <org> --format json1516# PostgreSQL: target the application database instead of the default "postgres"17pscale inspect all <database> <branch> --org <org> \18 --dbname <postgres-database> --format json1920# Vitess: target one exact shard; no command fans out across every shard21pscale inspect all <database> <branch> --org <org> \22 --keyspace '<keyspace>/<shard>' --format json2324# Run against a replica when primary-only evidence is unnecessary25pscale inspect all <database> <branch> --org <org> --replica --format json26```2728Always pass `--org` explicitly in agent workflows so the organization target is unambiguous. The default ephemeral role is `reader`; keep it unless the connection itself fails for a justified permission reason. On PostgreSQL, `--dbname` defaults to `postgres`, the temporary connection uses `sslmode=verify-full` by default, and the reader role may lack `CONNECT` on another database. Use `--role admin` only after confirming that this is the actual failure and that elevated access is acceptable.2930## Check catalog3132```text33table-sizes Tables by total size, largest first34index-sizes Indexes by size, largest first35unused-indexes Indexes with little or no use36redundant-indexes Indexes made redundant by another index37invalid-indexes Invalid PostgreSQL indexes38seq-scans Tables receiving full-table scans39long-running-queries Queries running longer than five minutes40locks Blocking locks and blocked sessions41outliers Queries by cumulative time (PostgreSQL pg_stat_statements)42calls Most-called queries (PostgreSQL pg_stat_statements)43bloat PostgreSQL bloat or MySQL fragmentation44vacuum-stats PostgreSQL autovacuum/autoanalyze health45replication-slots PostgreSQL slot status, retained WAL, and lag46subscriptions PostgreSQL logical-replication table progress47all Every applicable check in one report48```4950Run one check with the same positional arguments and target flags:5152```bash53pscale inspect locks <database> <branch> --org <org> --format json54pscale inspect seq-scans <database> <branch> --org <org> --replica --format json55pscale inspect table-sizes <database> <branch> --org <org> --keyspace '<keyspace>/<shard>' --format csv56```5758Single checks support human, JSON, and CSV output. `inspect all` supports human and JSON; CSV is rejected because the checks have different result schemas.5960## Engine and target semantics6162- **Vitess/MySQL:** checks query `information_schema`, `mysql`, and `sys`. On sharded databases, one run reflects one shard's MySQL instance. Use `pscale sql <database> <branch> --query "SHOW VITESS_SHARDS"` to enumerate targets, then pass `--keyspace <keyspace>/<shard>`; append `@replica` when an exact tablet type is needed.63- **PostgreSQL:** checks query `pg_catalog` and `pg_stat` views for one PostgreSQL database selected by `--dbname`. `outliers` and `calls` require `pg_stat_statements`.64- Checks unavailable for the detected engine return a skipped explanation and, when available, a copy-pasteable `pscale insights` next step.65- Each check is bounded and has a 30-second query timeout. In `inspect all`, one failed check is recorded as skipped instead of aborting the remaining report.6667## Investigation workflow68691. Confirm organization, database, branch, engine, and exact database/keyspace/shard target.702. Run `inspect all ... --format json` with the default reader role.713. Separate successful results, empty results, skipped checks, and failed/timed-out checks.724. Follow the report's `next_steps` with `pscale insights queries|errors|anomalies|recommendations` for traffic-aware evidence.735. Treat index, vacuum, lock, and query findings as diagnostic evidence—not automatic authorization to kill sessions or change schema.746. For any write or destructive remediation, switch to the relevant skill/workflow and obtain explicit user approval.7576## Related skills7778- **pscale-insights** — server-side query statistics, errors, anomalies, and schema recommendations79- **pscale-sql** — deliberate one-off SQL with role and destructive-query safeguards80- **pscale-branch** — connection inspection and explicitly approved connection/query termination8182## References8384See [references/commands.md](references/commands.md) for the verified command synopsis, flags, and engine applicability.