postgresql

Guidance for using PostgreSQL, an open-source relational database that stores structured information in related tables. It covers table design, queries, constraints, indexes, and performance.

In plain words
What is it for?
Use it to design database schemas, write SQL queries, add constraints and indexes, model relationships, and investigate slow database operations.
Why use it?
It helps keep application data accurate and organized while making common searches and updates efficient. It also addresses relationships, fixed value sets, and cleanup rules when records are deleted.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/plazmodium/odin-workflow/postgresql
Any agent
npx skills add Plazmodium/odin-workflow --skill postgresql
Clone the repo
git clone --depth 1 https://github.com/Plazmodium/odin-workflow

Made for: Claude Code, Codex.

Per session 18 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 922 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00018 $0.00922
Opus 5 $0.00009 $0.00461
Sonnet 5 $0.00004 $0.00184
Haiku 4.5 $0.00002 $0.00092

Measured yesterday against content hash a438ec11b8c2, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

postgresql scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

agents/skills/database/postgresql/SKILL.md · 121 lines

How it starts

The opening of the file, as written. The whole thing — 121 lines — stays where its author put it; the contents beside it link to each section on GitHub.

PostgreSQL

Overview

PostgreSQL is an advanced open-source relational database. This skill covers schema design, query patterns, indexing, and performance for application developers.

Schema Design

Tables

-- Always use explicit types and constraints
CREATE TABLE users (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    email TEXT NOT NULL UNIQUE,
    password_hash TEXT NOT NULL,
    name TEXT NOT NULL,
    created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
    updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);

-- Use enums for fixed value sets
CREATE TYPE user_role AS ENUM ('admin', 'member', 'viewer');
ALTER TABLE users ADD COLUMN role user_role NOT NULL DEFAULT 'member';

-- Junction table for many-to-many
CREATE TABLE user_organizations (
    user_id UUID REFERENCES users(id) ON DELETE CASCADE,
    org_id UUID REFERENCES organizations(id) ON DELETE CASCADE,
    role user_role NOT NULL DEFAULT 'member',
    joined_at TIMESTAMPTZ NOT NULL DEFAULT now(),
    PRIMARY KEY (user_id, org_id)
);

Indexes

-- B-tree (default) for equality and range queries
CREATE INDEX idx_users_email ON users(email);

-- Partial index for common filtered queries
CREATE INDEX idx_active_users ON users(created_at) WHERE is_active = true;

-- GIN for JSONB and full-text search
CREATE INDEX idx_metadata ON products USING GIN(metadata);
CREATE INDEX idx_search ON articles USING GIN(to_tsvector('english', title || ' ' || body));

-- Composite for multi-column queries (leftmost prefix rule)
CREATE INDEX idx_org_role ON user_organizations(org_id, role);

Query Patterns

Common Patterns

-- Upsert (INSERT ... ON CONFLICT)
INSERT INTO users (email, name) VALUES ($1, $2)
ON CONFLICT (email) DO UPDATE SET name = EXCLUDED.name, updated_at = now()
RETURNING *;

-- Pagination with cursor (better than OFFSET for large tables)
SELECT * FROM users
WHERE created_at < $1  -- cursor: last item's created_at
ORDER BY created_at DESC
LIMIT 20;

-- CTE for complex queries
WITH active_users AS (
    SELECT * FROM users WHERE last_login > now() - interval '30 days'
)
SELECT org_id, count(*) as active_count
FROM user_organizations uo
JOIN active_users au ON uo.user_id = au.id
GROUP BY org_id;

Read the full file on GitHub · 121 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 121 lines · 18 tokens per session scan A a438ec11b8c2

Subscribe to this mod's changes

postgresql is a skill published in the GitHub repository Plazmodium/odin-workflow (0 stars, last pushed 3mo ago), licensed MIT. It adds 18 tokens to every session and 922 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-01.