postgres · sanjay3290 — Claude Code skill: what it does, how to install
Runs safe read-only SQL queries against PostgreSQL databases. Helpful for inspecting schemas, running SELECT queries, and analyzing data without write risks.
npx skills add sanjay3290/ai-skills --skill postgres -a claude-codeWhat postgres does
This skill runs scripts/query.py to inspect and query PostgreSQL instances safely. It supports table listing, schema inspection, and read-only queries using SELECT, SHOW, EXPLAIN, and WITH statements. All write operations are blocked: connections enforce PostgreSQL readonly=True mode, and multiple statements in a single query are rejected.
Prerequisites include Python 3.8+ and psycopg2-binary. Credentials live in connections.json or ~/.config/claude/postgres-connections.json. You must run chmod 600 connections.json because the file contains database passwords in plain text.
Built-in safeguards prevent query abuse. Each statement has a 30-second timeout and a limit of 10,000 rows to protect memory. When multiple databases are configured, the skill matches user prompts to the description string of each database.
What it helps with
- inspect database schemas and table structures
- run analytical SELECT queries across PostgreSQL databases
- check table contents without accidental data modifications
- auto-select the target database using description fields
Example prompts for the agent
- Show the schema and tables in the production database
- Fetch the latest 10 rows from the users table in production
- List all configured databases to see what data they hold
How to install postgres
1Skills CLI (Vercel)
npx skills add sanjay3290/ai-skills --skill postgres -a claude-code2Manually: put the files in place
~/.claude/skills/postgres/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/postgres/
1Skills CLI (Vercel)
npx skills add sanjay3290/ai-skills --skill postgres -a codex2Manually: put the files in place
.agents/skills/postgres/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add sanjay3290/ai-skills --skill postgres -a cursor2Manually: put the files in place
.cursor/skills/postgres/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install sanjay3290/ai-skills postgres2Manually: put the files in place
.github/skills/postgres/SKILL.md1Skills CLI (Vercel)
npx skills add sanjay3290/ai-skills --skill postgres -a gemini-cli2Platform CLI
gemini skills install https://github.com/sanjay3290/ai-skills --path skills/postgresManually: put the files in place
.devin/skills/postgres/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add sanjay3290/ai-skills --skill postgres -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about postgres
How to install postgres in Claude Code?
Run npx skills add sanjay3290/ai-skills --skill postgres -a claude-code.
Which operations are blocked for safety?
All write operations such as INSERT, UPDATE, DELETE, and DROP are blocked. The skill allows only SELECT, SHOW, EXPLAIN, and WITH queries while running in readonly=True mode.
What configuration is required before querying?
You need Python 3.8+, psycopg2-binary, and database parameters configured in connections.json. Restrict file permissions using chmod 600 connections.json to protect credentials.
Source text
SKILL.md · Apache-2.0
---
name: postgres
description: "Execute read-only SQL queries against multiple PostgreSQL databases. Use when: (1) querying PostgreSQL databases, (2) exploring database schemas/tables, (3) running SELECT queries for data analysis, (4) checking database contents. Supports multiple database connections with descriptions for intelligent auto-selection. Blocks all write operations (INSERT, UPDATE, DELETE, DROP, etc.) for safety."
license: Apache-2.0
metadata:
author: sanjay3290
version: "1.0"
---
# PostgreSQL Read-Only Query Skill
Execute safe, read-only queries against configured PostgreSQL databases.
## Requirements
- Python 3.8+
- psycopg2-binary: `pip install -r requirements.txt`
## Setup
Create `connections.json` in the skill directory or `~/.config/claude/postgres-connections.json`.
**Security**: Set file permissions to `600` since it contains credentials:
```bash
chmod 600 connections.json
```
```json
{
"databases": [
{
"name": "production",
"description": "Main app database - users, orders, transactions",
"host": "db.example.com",
"port": 5432,
"database": "app_prod",
"user": "readonly_user",
"password": "your-password",
"sslmode": "require"
}
]
}
```
### Config Fields
| Field | Required | Description |
|-------|----------|-------------|
| name | Yes | Identifier for the database (case-insensitive) |
| description | Yes | What data this database contains (used for auto-selection) |
| host | Yes | Database hostname |
| port | No | Port number (default: 5432) |
| database | Yes | Database name |
| user | Yes | Username |
| password | Yes | Password |
| sslmode | No | SSL mode: disable, allow, prefer (default), require, verify-ca, verify-full |
## Usage
### List configured databases
```bash
python3 scripts/query.py --list
```
### Query a database
```bash
python3 scripts/query.py --db production --query "SELECT * FROM users LIMIT 10"
```
### List tables
```bash
python3 scripts/query.py --db production --tables
```
### Show schema
```bash
python3 scripts/query.py --db production --schema
```
### Limit results
```bash
python3 scripts/query.py --db production --query "SELECT * FROM orders" --limit 100
```
## Database Selection
Match user intent to database `description`:
| User asks about | Look for description containing |
|-----------------|--------------------------------|
| users, accounts | users, accounts, customers |
| orders, sales | orders, transactions, sales |
| analytics, metrics | analytics, metrics, reports |
| logs, events | logs, events, audit |
If unclear, run `--list` and ask user which database.
## Safety Features
- **Read-only session**: Connection uses PostgreSQL `readonly=True` mode (primary protection)
- **Query validation**: Only SELECT, SHOW, EXPLAIN, WITH queries allowed
- **Single statement**: Multiple statements per query rejected
- **SSL support**: Configurable SSL mode for encrypted connections
- **Query timeout**: 30-second statement timeout enforced
- **Memory protection**: Max 10,000 rows per query to prevent OOM
- **Column width cap**: 100 char max per column for readable output
- **Credential sanitization**: Error messages don't leak passwords
## Troubleshooting
| Error | Solution |
|-------|----------|
| Config not found | Create `connections.json` in skill directory |
| Authentication failed | Check username/password in config |
| Connection timeout | Verify host/port, check firewall/VPN |
| SSL error | Try `"sslmode": "disable"` for local databases |
| Permission warning | Run `chmod 600 connections.json` |
## Exit Codes
- **0**: Success
- **1**: Error (config missing, auth failed, invalid query, database error)
## Workflow
1. Run `--list` to show available databases
2. Match user intent to database description
3. Run `--tables` or `--schema` to explore structure
4. Execute query with appropriate LIMIT
© sanjay3290 · Apache-2.0 · sanjay3290/ai-skills
Similar skills
All skills for Data and databases →postgres by other authors comes first.