
PostgreSQL Query Testing
FreeRun PostgreSQL queries for testing and analysis.
Free · Opens the source repo
What PostgreSQL Query Testing does
The PostgreSQL Query Testing skill allows developers and database administrators to execute ad-hoc SQL queries directly against PostgreSQL databases for purposes such as testing, debugging, and performance analysis. This skill is particularly useful when you need to quickly verify database contents, assess query performance using EXPLAIN ANALYZE, or test SQL optimizations without needing to set up a full development environment. By utilizing this skill, users can streamline their workflow and gain immediate insights into their database operations.
To run queries, simply execute the provided script with the desired SQL command. The skill supports various options, including the ability to run EXPLAIN ANALYZE for performance insights, output results in JSON format, and even read queries from a file. Additionally, it provides flags to connect to different database environments, such as a development database or a notifications database, which may require an SSH tunnel for access. This flexibility allows for thorough testing across different scenarios and environments.
The skill prioritizes safety by defaulting to read-only connections, ensuring that accidental writes do not occur. Users can opt for writable connections only when explicitly permitted, adding a layer of security to database operations. This makes it an ideal tool for both seasoned developers and those new to database management who need a reliable way to interact with PostgreSQL without the risk of unintended modifications.
In summary, the PostgreSQL Query Testing skill is a valuable addition for anyone working with PostgreSQL databases, providing essential functionality for testing and performance analysis while maintaining a focus on safety and ease of use.
When to use it
Use this skill when you need to run direct SQL queries for debugging, performance checks, or testing optimizations.
When not to use it
This skill is not suitable for general-purpose database management tasks or for users who require a full database client interface.
What you can build with it
Quick Database Checks
Run simple SELECT queries to quickly verify the contents of your PostgreSQL database.
Performance Analysis
Use the --explain flag to analyze query performance and identify potential optimizations.
Testing SQL Scripts
Execute SQL scripts stored in files to test complex queries without manual entry.
How to install PostgreSQL Query Testing
View source1. Install with the skills CLI
npx skills add civitai/civitai/postgres-query --agent claude-code2. Or install it manually
Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.
Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs
Inside SKILL.md
Written by civitaiPostgreSQL Query Testing
Use this skill to run ad-hoc PostgreSQL queries for testing, debugging, and performance analysis.
Running Queries
Use the included query script:
node .claude/skills/postgres-query/query.mjs "SELECT * FROM \"User\" LIMIT 5"
Options
| Flag | Description |
|---|---|
--explain | Run EXPLAIN ANALYZE on the query |
--writable | Use primary database instead of read replica (requires user permission) |
--data-packet | Use the DataPacket replica (DATABASE_DATA_PACKET_URL) — read-only |
--notifications | Query the notifications-db (DataPacket) — read-only via SSH bastion (see setup below) |
--dev | Query the dev cnpg database (DEV_DATABASE_URL) via SSH bastion (see setup below) |
--timeout <s>, -t | Query timeout in seconds (default: 30) |
--file, -f | Read query from a file |
--json | Output results as JSON |
--quiet, -q | Minimal output, only results |
Examples
# Simple query
node .claude/skills/postgres-query/query.mjs "SELECT id, username FROM \"User\" LIMIT 5"
# Check query performance
node .claude/skills/postgres-query/query.mjs --explain "SELECT * FROM \"Model\" WHERE id = 1"
# Override default 30s timeout for longer queries
node .claude/skills/postgres-query/query.mjs --timeout 60 "SELECT ... (complex query)"
# Query the notifications-db
node .claude/skills/postgres-query/query.mjs --notifications "SELECT count(*) FROM \"Notification\""
# Query from file
node .claude/skills/postgres-query/query.mjs -f my-query.sql
# JSON output for processing
node .claude/skills/postgres-query/query.mjs --json "SELECT id, username FROM \"User\" LIMIT 3"
Connection Targets
| Flag | Connection string | Use when |
|---|---|---|
| (default) | DATABASE_REPLICA_URL (falls back to DATABASE_URL) | Most queries — read-only main replica |
--writable | DATABASE_URL | Writes against primary; needs user permission |
--data-packet | DATABASE_DATA_PACKET_URL | Querying the DataPacket replica (read-only) |
--notifications | NOTIFICATION_DB_REPLICA_URL | Querying notifications-db (read-only); requires SSH tunnel |
--dev | DEV_DATABASE_URL | Querying the dev cnpg database; requires SSH tunnel |
Querying the dev database (cnpg)
The dev database is not reachable directly — it needs an SSH tunnel to an internal
host. Ask an infra owner for the connection recipe; the specifics are not
documented here because this repository is public (see the Security section of
CLAUDE.md).
Once the tunnel is up, set DEV_DATABASE_URL in
.claude/skills/postgres-query/.env to point at your local forwarded port.
Running dev queries
# Read-only (default — writes are blocked client-side)
node .claude/skills/postgres-query/query.mjs --dev "SELECT count(*) FROM \"User\""
# Writable (the dev postgres role is a superuser; needs user permission)
node .claude/skills/postgres-query/query.mjs --dev --writable "UPDATE ..."
Querying the notifications-db
The notifications database is not reachable directly — it needs an SSH tunnel to an internal host, and access has to be granted first.
Ask an infra owner for access and the connection recipe. The bastion host, the
forward target, and where the credentials live are deliberately not documented here,
because this repository is public — see the Security section of CLAUDE.md.
Once you have the tunnel open, set NOTIFICATION_DB_REPLICA_URL in
.claude/skills/postgres-query/.env to point at your local forwarded port.
Running queries
# With the tunnel open in another terminal:
node .claude/skills/postgres-query/query.mjs --notifications \
"SELECT count(*) FROM \"Notification\""
node .claude/skills/postgres-query/query.mjs --notifications --explain \
"SELECT * FROM \"UserNotification\" WHERE \"userId\" = 12345 ORDER BY \"createdAt\" DESC LIMIT 50"
Available tables (read-only)
Notification— canonical notificationsUserNotification— per-user fanout (largest table)PendingNotification— processing queue (often empty)
The role notifications_readonly only has SELECT. Writes are also rejected at the pooler level (replica routing).
Safety Features
- Read-only by default: Uses
DATABASE_REPLICA_URLto prevent accidental writes - Write protection: Blocks INSERT/UPDATE/DELETE/DROP unless
--writableflag is used - Notifications is always read-only:
--notificationsblocks writes client-side AND the database role/pooler reject them - Explicit permission required: Before using
--writable, you MUST ask the user for permission
When to Use --writable
Only use the --writable flag when:
- The user explicitly requests write access
- You need to test write operations
- You're verifying transaction behavior
IMPORTANT: Always ask the user for permission before running with --writable.
Comparing Query Performance
To compare two query approaches:
# Run first approach
node .claude/skills/postgres-query/query.mjs --explain "SELECT ... (approach 1)"
# Run second approach
node .claude/skills/postgres-query/query.mjs --explain "SELECT ... (approach 2)"
# Compare actual results
node .claude/skills/postgres-query/query.mjs --json "SELECT ... (approach 1)" > /tmp/q1.json
node .claude/skills/postgres-query/query.mjs --json "SELECT ... (approach 2)" > /tmp/q2.json
Verifying Index Usage
Run with --explain and look for:
- Good: "Index Scan", "Bitmap Index Scan", "Index Only Scan"
- Bad: "Seq Scan" on large tables (indicates missing or unused index)
node .claude/skills/postgres-query/query.mjs --explain "SELECT * FROM \"Account\" WHERE provider = 'discord'"
Frequently asked questions about PostgreSQL Query Testing
Similar skills
ClickHouse Logs Queries
Efficiently manage Supabase logs with ClickHouse SQL.
EF Core D2 Database Diagram Generator
Visualize your EF Core models as D2 diagrams effortlessly.
Safe SQL Execution
Ensure secure SQL execution in Supabase applications.
Oracle to PostgreSQL Migration
Identify migration risks between Oracle and PostgreSQL.
SSMA Console
Streamline Oracle to SQL Server migrations with ease.
SQL Performance Optimization
Enhance SQL query efficiency across all databases.
