Skip to main content
skill CX Codex

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.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add sanjay3290/ai-skills --skill postgres -a claude-code
Open on GitHub

What 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-code

2Manually: put the files in place

~/.claude/skills/postgres/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/postgres/

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.

From the same set15

deep-research Runs multi-step autonomous investigations using the Google Gemini Deep Research Agent. Generates cited technical reports, market overviews, and competitive matrices. CX Codex +1 672installs imagen This skill turns a text prompt into a PNG using Google Gemini, saving the file straight into your project. Handy for icons, placeholders and docs illustrations. CX Codex +1 626installs mssql Runs read-only SQL queries against Microsoft SQL Server databases. Useful for exploring schemas and analyzing data without the risk of mutating records. CX Codex +1 537installs google-calendar This skill lets your agent read Google Calendar, create and edit events, and find free slots. OAuth only, no MCP server involved. CX Codex +1 536installs gmail Searches, reads, and sends emails through Gmail directly from the agent interface. Helpful for triaging the inbox, managing drafts, and organizing labels. CX Codex +1 516installs google-sheets This skill gives your agent read and write access to Google Sheets: pull ranges, append rows, search for files by name. Handy when the data lives in a spreadsheet, not in code. CX Codex +1 465installs mysql This skill runs SELECT queries against several MySQL databases and blocks every write. Handy when you want to inspect a schema or pull data without touching production. CX Codex +1 420installs google-slides A skill for searching, reading, creating, and editing Google Slides presentations directly from agent commands. Uses Python scripts with standalone OAuth. CX Codex +1 407installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor