/ratchet-backend:postgres-node-performance-tuningfrom ratchet-backend
Use when writing or reviewing a SQL query or data-access function, adding a query with a new filter or sort, reading a query plan, fixing a slow query, or changing a view or materialized view. Write, measure, and improve PostgreSQL queries in Node.js services - query shape, indexes, EXPLAIN plans, round trips, transactions, and pooling.
Ships in ratchet-backend. 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.
Read when SKILL.md points to them.
Read every applicable AGENTS.md first. Repository-local policy overrides these defaults.
These rules are for queries that run in production. A query in a test or a fixture, or in a
seed for a disposable database, needs no index, plan, or operation-name comment, and a test may
run its own BEGIN and ROLLBACK or hold a second client to stage a race. The pool budget
still counts test workers.
Measure the query plan and the workload shape before changing code.
Use the simplest query. Start with filters in WHERE, keyed EXISTS, joins or
subqueries, ORDER BY, and LIMIT. A complex shape stays only with EXPLAIN ANALYZE plans showing
it beats that simple query, not merely the previous version; see
simplest query first.
SELECT *, alias.*, or RETURNING *. A new column then
cannot change a result shape or widen a row by accident.to_jsonb(v)), and only
when the caller uses the whole object. Reading one of its columns, or joining it only
to filter or sort, is a defect; a materialized view is stored like a table and is read like
one. Join the base table with the predicates it needs (such as deleted_at IS NULL), and
compute a derived field with a shared SQL-fragment helper that takes the row's alias, not a copied expression, a view
column, or a database function. Look up each entity once per statement and take every field
from that one join. To read an aggregate or UNION view by key, use a correlated scalar
subquery or the base tables: a join or plain LATERAL to it, or a MATERIALIZED CTE, builds
it in full, so confirm with EXPLAIN. A
materialized view's query changes by drop and create, never CREATE OR REPLACE. A view that
enforces access is the exception: read through it. See
views and entity reads and
reading views by key.LATERAL predicate: COALESCE(a.x, a.y) = COALESCE(b.x, b.y), a cast, a function, CASE, or arithmetic on both sides. Unless the inner
table has an index on that same expression, and the plan shows it as an Index Cond, every
outer row scans the inner table. Compare bare columns; for a target that is one of several
foreign keys, write one guarded UNION ALL branch per column; see
expressions on both sides./* invoices.listByAccount */, so
a slow-query log or pg_stat_activity row names its call site./* ${label} */) takes the names out of the SQL, so a search for a name from
the slow-query log, or a static check keyed on it, no longer finds the statement. To remove
duplication, share the column list or a fragment and keep one literal statement per operation.node-postgres-transactions owns how, including a
client borrowed inside a caller's transaction.INSERT on a path that can be retried (a job, a webhook, a client retry) is idempotent with
ON CONFLICT. A get-or-create on a lookup table reads first and inserts only on a miss: nearly
every call finds the row, and an identity or sequence default is evaluated before the conflict
check, so every conflicting insert burns a sequence value.SELECT what the write's own WHERE or EXISTS can guard. The pre-check
is a second round trip, and its answer can be stale by the time the write runs.max_connections.
How long each caller holds a connection sets a pool's steady capacity: ten 5 ms queries in a
2 s job hold one for 50 ms, so 8 connections serve about 320 such jobs running at once, but only
8 jobs that hold one for their whole run. A burst above that capacity still queues for a
checkout.
unnest, or run one keyset statement per batch; keep a temp table inside one
short transaction.max_connections. Shorten the holds."C" collation, and a vector search with the
vector index's k-nearest walk and a tunable k; see
search indexes.A consuming repository owns schema ownership, operational thresholds, pooling configuration, and rollout.
What SKILL.md sets; muted values are Claude Code's defaults
18 skills in this plugin
/bounded-iterationUse when writing or reviewing a sweep, scheduled job, reconciler, cleanup, dispatcher, backfill, or export - any loop that reads rows. Covers bounding the rows each run reads, sweeps that re-select their own writes, and effects that repeat on every run./error-handlingUse when writing or reviewing code that throws, catches, or matches an error, turns a failure into a response, or reports errors to a tracker such as Sentry, including a review of a diff that does. Covers one defined list of error codes, matching on type or code instead of message, details as attributes on the error, and reporting only errors someone can act on./Other plugins' skills for the same job
npx claudepluginhub jongleberry/ratchet-stack --plugin ratchet-backend