prod-db-postgres
暂无简介
- License 许可
- MIT
- 最近更新
- 2026-09-20
- Stars
- ★ 0
- Forks
- 0
02 资源文件 4
- 脚本scripts/config.example.env191 B
- 脚本scripts/guard.py3.2 KB
- 脚本scripts/query.sh6.4 KB
- 脚本scripts/test_guard.py1.3 KB
03 SKILL.md 正文
Production Postgres, read-only queries
One call = one throwaway session: SSO check → DB URL from SSM (never printed) →
find a running instance by tag → SSM port-forward on a free local port → psql
with the session forced read-only → tunnel torn down. Nothing stays open between
calls, so nothing can go stale.
scripts/query.sh 'SELECT count(*) FROM orders WHERE status = 1'
scripts/query.sh --format json 'SELECT id, name, enabled FROM routes ORDER BY id'
scripts/query.sh --format csv --limit 0 'SELECT ...' > out.csv
scripts/query.sh 'SELECT 1' 'SELECT 2' # several statements, one tunnel
scripts/query.sh '\dt public.*' '\d+ orders' # psql describe meta-commands
scripts/query.sh --help is the full reference. Double-quote SQL that contains
'string literals'.
Flags: --format table|json|csv (default table) · --limit N printed rows for
SELECT/WITH (default 200, 0 = no cap; applied by wrapping the statement in
SELECT * FROM (...) LIMIT N) · --timeout SECONDS server-side statement timeout
(default 60) · --profile AWS profile.
Exit codes: 1 preflight/tunnel · 2 psql error · 3 statement refused · 4 timed out.
Configuration
Set once, in the environment or in scripts/config.env (sourced if present, gitignored):
| Variable | What |
|---|---|
PRODDB_AWS_PROFILE |
AWS SSO profile with SSM and EC2 describe rights |
PRODDB_AWS_REGION |
region of the instance and the parameter |
PRODDB_SSM_DB_URL_PARAM |
SSM SecureString holding postgres://user:pass@host:port/db |
PRODDB_INSTANCE_TAG |
Name tag of an instance inside the VPC that can reach the DB |
Copy scripts/config.example.env to scripts/config.env and fill it in.
Ask the user before the first query of a session
This is the live production database. Confirm with the user before the first query, and again for anything that is not a cheap indexed lookup: an unbounded scan competes with the web and worker tiers for the same instance. Cheap follow-ups in an already-authorised session do not each need a fresh confirmation. When the harness blocks the command, hand the exact command to the user to run themselves.
Look, do not guess
\dt <pattern> and \d+ <table> cost nothing. Use them before writing SQL against
a table you have not seen. Keep a short schema cheat sheet in the project's
domain-knowledge.md, dated, and refresh it when it is wrong.
How read-only is enforced
scripts/guard.pyallow-lists the statement (SELECT/WITH/VALUES/SHOW/EXPLAIN/TABLE, one per call, describe meta-commands only), refusesINTO,COPY,LOCK,FOR UPDATEand data-modifying CTEs. Literals and comments are blanked first so a;inside quotes is not misread. Offline tests:python3 scripts/test_guard.py.PGOPTIONS="-c default_transaction_read_only=on": the server rejects any write. This is the layer that holds.statement_timeout(--timeout) and the printed-row cap.
Why it cannot just connect
The RDS instance is private to the VPC. The script port-forwards through a running
instance with AWS-StartPortForwardingSessionToRemoteHost; the credentials come
from the SSM parameter and stay in the script's environment. Instance replacement
by an autoscaling group is harmless (discovered by tag every call), and so is a
credential rotation (read every call).
Failure modes
| Symptom | Meaning |
|---|---|
SSO token expired or missing for profile X. Run: aws sso login --profile X |
Browser SSO; the user must run it |
no running <tag> instance found |
Wrong profile/region, or the ASG is mid-refresh; retry in a minute |
port-forward ... did not come up / SSM session died |
session-manager-plugin missing, or the instance's SSM agent is unhealthy |
REFUSED: ... (exit 3) |
Not read-only. Do not reword around the guard |
REFUSED by server: read-only session |
Something got past the guard; the server stopped it |
TIMEOUT: exceeded Ns (exit 4) |
Narrow the query (date range, indexed columns) before raising --timeout |
Requirements on macOS: aws CLI v2 with an SSO profile, session-manager-plugin
(brew install --cask session-manager-plugin), psql (brew install libpq),
python3, nc.
Extension point
Encrypted columns (Fernet, KMS envelope, whatever the app uses) come back as
ciphertext. Add a --decrypt col,col flag that pipes the JSON result through a
small script running under the application's own key loader. Keys stay in that
process; decrypted rows are production PII and go to a scratch directory, never a repo.
04 同仓库更多 Skills
yes-no
Answer the user's question with a yes or no, optionally followed by a short explanation when the model sees fit. Use when the user types "/yes-no", asks a yes/no question and wants a decisive answer, or says "just yes or no".
sonar-workflow
Fix SonarQube code quality issues for a pull request. Auto-fixes trivial issues (formatting, unused imports) and requests approval for complex issues (security, bugs). Integrates with commit-workflow and pr-workflow skills.
short-answer
Answer the user's question as concisely as possible, a direct, to-the-point response with no preamble, filler, or unnecessary elaboration. Use when the user types "/short-answer", asks for a brief/short/concise/TL;DR answer, or says "just the answer".
redash
Query a Redash instance over its REST API , list data sources and saved queries, read a saved query's SQL, run it, or run ad-hoc read-only SQL and get the rows back. Use when the user asks about Redash, a Redash query/dashboard/link, "run that query", "what does query 1234 return", or wants numbers out of an analytics data source rather than the application DB.
prod-db-mysql-bastion
暂无简介
pr-workflow
Use this skill when asked to create or update a pull request (PR). It ensures all PRs follow the repository's established templates and standards. Handles both new PR creation and updating existing PRs with new commits, title changes, or description updates.