db-query

Query PostgreSQL-compatible databases with enforced read-only production access and audit-file output.

1|Updated Sep 11, 2026
One-click install
npx skills add https://github.com/lldwb/lldwb-claude-skills --skill db-query-lldwb
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: db-query
Source: https://github.com/lldwb/lldwb-claude-skills/tree/main/skills/db-query
Command: npx skills add https://github.com/lldwb/lldwb-claude-skills --skill db-query-lldwb

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires psycopg2-binary, and includes scripts (resource) and references (resource) components.

What problem does it solve? Querying production databases directly is risky: accidental writes, unbounded full-table scans, and untraceable results. This Skill enforces a safety-first database query workflow where production is strictly read-only (script interception + read-only session + read-only account), test-environment writes require explicit user confirmation, and every query result is persisted to disk as evidence. ## Core Features & Use Cases - Safety-Enforced Querying: Single-statement execution, mandatory LIMIT, no select *, and side-effect detection (e.g., EXPLAIN ANALYZE on write statements, SELECT ... INTO, nextval) treated as writes and blocked on read-only environments. - Multi-Environment Config: Switch environments with --env; config loads from explicit path, project-level .claude/db-query.config.json, or skill-level default, supporting PostgreSQL-compatible databases like GaussDB. - Companion Tools: Convert query results into batch UPDATE fix SQL (gen-fix-sql.py), dry-run SQL files with rollback (run-sql-file.py), and sync table data across environments (sync-table.py). - Use Case: Verify a broken order's status in production, cross-check it against log-diagnose findings, generate a fix SQL script, test it in the test environment, and hand the validated script to the user for production execution. ## Quick Start Use the db-query skill to check the status and del_flag of order 12345 in the prod environment.

Frequently Asked Questions about db-query

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I safely query a production PostgreSQL database?

Run db-query.py with --env prod and a single SELECT statement listing explicit columns and a LIMIT. The script enforces read-only access through statement interception, a read-only session, and a read-only account, and saves results to timestamped txt/json files.

How to generate batch UPDATE fix SQL from query results?

Use gen-fix-sql.py with the query result file, target table, column to update, and a filter condition. It produces a backup table plus begin/update/commit statements without connecting to the database, ready for dry-run via run-sql-file.py.

Does psycopg2 work with GaussDB connections?

Yes, GaussDB speaks the PostgreSQL protocol so psycopg2 connects directly. Note GaussDB quirks: COUNT FILTER is unsupported (use SUM(CASE WHEN)), distributed tables need the distribution key in primary keys, and explicit COLLATE is required when creating tables.

Why was my SQL statement rejected by the query script?

Statements are rejected if they contain multiple semicolon-separated statements, write keywords on a read-only environment, or side-effect forms like EXPLAIN ANALYZE on writes, SELECT INTO, nextval, or FOR UPDATE. Test-environment writes also require --allow-write after user confirmation.

Can I sync table data from production to a test environment?

Yes, sync-table.py exports rows from the source with a forced read-only session, verifies column structure matches, then deletes and reinserts rows in the target within a transaction. The --where filter is required and target writes need --allow-write.