Simple database assistant with Claude
Downloading a good skill or installing an MCP server? That’s what I imagined I’d need to let Claude connect to a database, then ask it to run any kind of SQL queries I wouldn’t have to write myself.
But actually, the only thing I had to do was to prompt: Connect to postgresql://myuser@localhost:5433/mydb. Claude will simply perform a SELECT version(); or \conninfo and confirm it can access the database and execute
subsequent psql commands. Everything works thanks to my credentials being
in ~/.pgpass.
Here’s an example of Claude inspecting a database structure using only psql
commands:
❯ Inspect the `demo` schema and explain what it is. Display a schema.
[Claude inspects tables, columns, constraints...]
● What is the demo schema?
It's a self-contained sample e-commerce dataset — a sandbox with 5 fictional users, 8 products, 200 orders, and 1000 analytics events. It has no dependencies on any other schema in the database. It's clearly
meant for development, demos, or testing queries against a realistic-looking data model that uses PostgreSQL-specific types (jsonb, text[]).
Entity-Relationship Diagram
┌──────────────────────────────┐
│ users (5) │
├──────────────────────────────┤
│ PK id serial │
│ UQ username text NOT NULL │
│ email text NOT NULL │
│ created_at timestamptz │
│ metadata jsonb │
│ ┌─────────────────────┐ │
│ │ plan: free|premium │ │
│ │ country: FR|US|DE │ │
│ └─────────────────────┘ │
└──────────┬──────────┬────────┘
│ │
│ │
┌─────┘ └──────────────────────┐
│ FK user_id FK user_id│
▼ ▼
┌────────────────────────┐ ┌──────────────────────────────┐
│ orders (200) │ │ events (1000) │
├────────────────────────┤ ├──────────────────────────────┤
│ PK id serial │ │ PK id serial │
│ FK user_id → users │ │ FK user_id → users │
│ status text │ │ event_type text NOT NULL │
│ total numeric │ │ payload jsonb │
│ created_at timestamptz│ │ created_at timestamptz │
├────────────────────────┤ ├──────────────────────────────┤
│ status values: │ │ event_type values: │
│ pending | confirmed │ │ login | page_view | search │
│ shipped | delivered │ │ add_to_cart | checkout │
│ cancelled │ └──────────────────────────────┘
└───────────┬────────────┘
│
│ FK order_id
▼
┌──────────────────────────────┐
│ order_items (600) │
├──────────────────────────────┤
│ PK id serial │
│ FK order_id → orders │
│ FK product_id → products │
│ quantity int NOT NULL │
│ unit_price numeric │
└──────────────┬───────────────┘
│
│ FK product_id
▼
┌──────────────────────────────┐
│ products (8) │
├──────────────────────────────┤
│ PK id serial │
│ name text NOT NULL │
│ category text NOT NULL │
│ price numeric │
│ stock int (def 0) │
│ tags text[] │
│ created_at timestamptz │
├──────────────────────────────┤
│ categories: electronics │
│ furniture │
└──────────────────────────────┘
Indexes
Only primary keys and the username unique constraint are indexed — no secondary indexes on foreign keys or query columns. This is consistent with a lightweight demo/dev dataset not optimized for production
query patterns.
✻ Worked for 31s
By Thomas Martin
Follow me or comment