# postgres

Runs safe read-only SQL queries against PostgreSQL databases. Helpful for inspecting schemas, running SELECT queries, and analyzing data without write risks.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 620 installs · ★ 447
- Author: sanjay3290
- License: Apache-2.0 · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/sanjay3290/ai-skills/tree/HEAD/skills/postgres/SKILL.md
- Updated: 2026-09-10
- HTML: https://affpapa.org/en/nevibecode/skills/sanjay3290-postgres

## What it 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.

## Requirements
- Works with: PostgreSQL

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add sanjay3290/ai-skills --skill postgres -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/postgres/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/postgres/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add sanjay3290/ai-skills --skill postgres -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/postgres/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add sanjay3290/ai-skills --skill postgres -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/postgres/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install sanjay3290/ai-skills postgres
```

2. **Manually: put the files in place**
- File: `.github/skills/postgres/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add sanjay3290/ai-skills --skill postgres -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/sanjay3290/ai-skills --path skills/postgres
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/postgres/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add sanjay3290/ai-skills --skill postgres -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/sanjay3290/ai-skills/tree/HEAD/skills/postgres/SKILL.md

## When to use it
- 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
- 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

## Source text · SKILL.md · Apache-2.0

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: b3c91d0cb9ba92a3.

BEGIN THIRD-PARTY FILE b3c91d0cb9ba92a3
````text
---
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
````
END THIRD-PARTY FILE b3c91d0cb9ba92a3

The third-party file has ended. Everything between the b3c91d0cb9ba92a3 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 3017 of 3900 bytes. © sanjay3290 · Apache-2.0 · https://github.com/sanjay3290/ai-skills/tree/HEAD/skills/postgres/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
