Use when needing to query a PostgreSQL database in DEV or PROD, check if records exist, count rows, inspect data, or run read-only SQL queries from within the cluster. Use when user says "consulta la BD", "query", "busca en la tabla", "check database", "db query", or "existe este registro".
Execute read-only SQL queries against PostgreSQL databases via PgBouncer from within application pods. No psql available — use the pg module via node -e.
Read project-specific values from the project's CLAUDE.md (## Infrastructure section):
require('/app/node_modules/pg') — module is not in the global node path.development.config.js for DEV, production.config.js for PROD (both files exist in every pod).kubectl --context=<ctx> get pods -n <namespace> | grep <app-label>node -eSee scripts/query.js for the reusable helper (copy to pod with kubectl cp).
See references/query-examples.md for command templates.
| Mistake | Prevention |
|---|---|
| Not reading CLAUDE.md | Namespace, context, DB name vary per project. |
Parameterized queries ($1::uuid[]) | PgBouncer rejects them. Use inline SQL. |
require('pg') fails | Use require('/app/node_modules/pg'). |
| Wrong config file | production.config.js in a DEV pod points to PROD db. Use development.config.js for DEV. |
| Write queries without confirmation | Always ask before INSERT/UPDATE/DELETE. |