postgres-operations

postgres-operations is a skill for Claude Code, Codex from sawrus/agent-guides. It costs 28 tokens per session (1,121 once invoked), scanned A, original, MIT.

A set of operational instructions for running and maintaining PostgreSQL, an open-source database. It covers health checks, cleanup, locks, recovery, archived change logs, and connection pools.

In plain words
What is it for?
Use it to inspect database size and replication delay, investigate blocked queries, manage vacuuming and bloat, recover with point-in-time restore, and tune connection handling.
Why use it?
It provides tested checks and runbooks for diagnosing database problems instead of guessing during an incident.

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/sawrus/agent-guides/postgres-operations
Any agent
npx skills add sawrus/agent-guides --skill postgres-operations
Clone the repo
git clone --depth 1 https://github.com/sawrus/agent-guides

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for postgres-operations

README.md
[![agentmods](https://agentmods.dev/badge/skills/sawrus/agent-guides/postgres-operations.svg)](https://agentmods.dev/skills/sawrus/agent-guides/postgres-operations)
Your own site
<a href="https://agentmods.dev/skills/sawrus/agent-guides/postgres-operations"><img src="https://agentmods.dev/badge/skills/sawrus/agent-guides/postgres-operations.svg" alt="Measured on agentmods" height="20"></a>
Per session 28 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,121 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.00028 $0.01121
Opus 5 $0.00014 $0.00561
Sonnet 5 $0.00006 $0.00224
Haiku 4.5 $0.00003 $0.00112

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

Security

Grade A, and why

postgres-operations 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 3d ago.

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.

areas/devops/database-ops/skills/postgres-operations/SKILL.md · 157 lines

How it starts

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

Skill: PostgreSQL Operations

Expertise: PostgreSQL health, vacuuming, lock analysis, PITR, WAL archiving, PgBouncer, K8s-hosted PostgreSQL.

When to load

When investigating a slow database, diagnosing lock waits, running PITR recovery, or managing a PostgreSQL instance.

Health Check Commands

-- Database size overview
SELECT
  datname,
  pg_size_pretty(pg_database_size(datname)) AS size,
  numbackends AS active_connections
FROM pg_stat_database
ORDER BY pg_database_size(datname) DESC;

-- Table sizes (top 20)
SELECT
  schemaname || '.' || tablename AS table,
  pg_size_pretty(pg_total_relation_size(schemaname || '.' || tablename)) AS total_size,
  pg_size_pretty(pg_relation_size(schemaname || '.' || tablename)) AS table_size,
  pg_size_pretty(pg_indexes_size(schemaname || '.' || tablename)) AS index_size
FROM pg_tables
ORDER BY pg_total_relation_size(schemaname || '.' || tablename) DESC
LIMIT 20;

-- Replication lag (primary)
SELECT
  client_addr,
  state,
  pg_size_pretty(pg_wal_lsn_diff(sent_lsn, replay_lsn)) AS replication_lag
FROM pg_stat_replication;

Lock Investigation

-- Active locks and blocking queries
SELECT
  blocking.pid AS blocking_pid,
  blocking.query AS blocking_query,
  blocked.pid AS blocked_pid,
  blocked.query AS blocked_query,
  blocked.wait_event_type,
  blocked.wait_event
FROM pg_stat_activity blocking
JOIN pg_stat_activity blocked
  ON blocked.wait_event_type = 'Lock'
  AND blocking.pid != blocked.pid
WHERE blocking.state = 'active';

-- Kill blocking query (confirm before running!)
SELECT pg_terminate_backend(<blocking_pid>);

-- Long-running queries (> 5 min)
SELECT pid, now() - pg_stat_activity.query_start AS duration, query, state
FROM pg_stat_activity
WHERE (now() - pg_stat_activity.query_start) > interval '5 minutes'
  AND state = 'active';

VACUUM and Bloat

-- Check autovacuum health
SELECT
  schemaname || '.' || relname AS table,
  last_autovacuum,
  last_autoanalyze,
  n_dead_tup,
  n_live_tup,
  round(n_dead_tup::numeric / NULLIF(n_live_tup + n_dead_tup, 0) * 100, 2) AS dead_pct
FROM pg_stat_user_tables
ORDER BY n_dead_tup DESC
LIMIT 20;

-- Manual VACUUM ANALYZE (non-blocking)
VACUUM ANALYZE VERBOSE orders;

-- VACUUM FULL (rewrites table — locks! use with maintenance window)
VACUUM FULL orders;

Read the full file on GitHub · 157 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. 3d ago First seen · 157 lines · 28 tokens per session scan A f9067c3b7258

Subscribe to this mod's changes

postgres-operations is a skill published in the GitHub repository sawrus/agent-guides (17 stars, last pushed 3d ago), licensed MIT. It adds 28 tokens to every session and 1,121 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-08-30.

Related

Other skills, from other repositories

deprecation-and-migration

Manages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when migrating a database schema in production, such as renaming or dropping a column without downtime (expand/contract). Use when deciding whether to maintain or sunset…

addyosmani/agent-skills · 69 tokens

db

Connect to any database — Cloud SQL, PostgreSQL, Snowflake, Databricks, Athena, Presto, or Oracle.

rajitsaha/100xprism · 28 tokens

data-query

Run analytics queries against any database using plain English — BigQuery (bq CLI), PostgreSQL, MySQL, SQLite, or any DB with a CLI/MCP/API. Use when you need to pull metrics, analyze data, or answer business questions without writing SQL.

rajitsaha/100xprism · 57 tokens

database-migration-guardian

Activate when writing, reviewing, or applying database migrations in PostgreSQL, MySQL, Prisma, or Drizzle to prevent table locks, zero-downtime failures, and data loss — trigger phrasings include "review this database migration", "how do I add a NOT NULL column without downtime", "write a safe PostgreSQL migration"…

ieeecsopen/mcp-cs · 117 tokens

db-architect

Activate when a developer needs to model relational schemas, parse SQL DDL statements, generate Mermaid Entity-Relationship Diagrams (ERD), analyze primary/foreign key relationships, or normalize database tables — trigger phrasings include "generate an ERD for my database", "convert this SQL schema to Mermaid"…

ieeecsopen/mcp-cs · 114 tokens

devops-vercel-render-deploy

Activate when deploying web applications, Next.js frontends, Node/Python backends, or PostgreSQL databases to cloud hosting platforms (Vercel, Render, Supabase, Railway) — trigger phrasings include "deploy my project to Vercel", "how do I host this Next.js app", "deploy backend to Render", "setup Supabase database"…

ieeecsopen/mcp-cs · 115 tokens