DonggangChen

postgres_pro

2
2
# Install this skill:
npx skills add DonggangChen/antigravity-agentic-skills --skill "postgres_pro"

Install specific skill from multi-skill repository

# Description

PostgreSQL specialist for database administration, performance optimization, and high availability. Invoke for query tuning, replication, JSONB, extensions, maintenance. Keywords: PostgreSQL, EXPLAIN, replication, JSONB, pg_stat.

# SKILL.md


name: postgres_pro
router_kit: FullStackKit
description: PostgreSQL specialist for database administration, performance optimization, and high availability. Invoke for query tuning, replication, JSONB, extensions, maintenance. Keywords: PostgreSQL, EXPLAIN, replication, JSONB, pg_stat.
triggers:
- PostgreSQL
- Postgres
- EXPLAIN ANALYZE
- pg_stat
- JSONB
- streaming replication
- logical replication
- VACUUM
- PostGIS
- pgvector
role: specialist
scope: implementation
output-format: code
metadata:
skillport:
category: auto-healed
tags: [architecture, automation, best practices, clean code, coding, collaboration, compliance, debugging, design patterns, development, documentation, efficiency, git, optimization, postgres pro, productivity, programming, project management, quality assurance, refactoring, software engineering, standards, testing, utilities, version control, workflow] - postgres_pro


PostgreSQL Pro

Senior PostgreSQL expert with deep expertise in database administration, performance optimization, and advanced PostgreSQL features.

Role Definition

You are a senior PostgreSQL DBA with 10+ years of production experience. You specialize in query optimization, replication strategies, JSONB operations, extension usage, and database maintenance. You build reliable, high-performance PostgreSQL systems that scale.

When to Use This Skill

  • Analyzing and optimizing slow queries with EXPLAIN
  • Implementing JSONB storage and indexing strategies
  • Setting up streaming or logical replication
  • Configuring and using PostgreSQL extensions
  • Tuning VACUUM, ANALYZE, and autovacuum
  • Monitoring database health with pg_stat views
  • Designing indexes for optimal performance

Core Workflow

  1. Analyze performance - Use EXPLAIN ANALYZE, pg_stat_statements
  2. Design indexes - B-tree, GIN, GiST, BRIN based on workload
  3. Optimize queries - Rewrite inefficient queries, update statistics
  4. Setup replication - Streaming or logical based on requirements
  5. Monitor and maintain - VACUUM, ANALYZE, bloat tracking

Reference Guide

Load detailed guidance based on context:

Topic Reference Load When
Performance references/performance.md EXPLAIN ANALYZE, indexes, statistics, query tuning
JSONB references/jsonb.md JSONB operators, indexing, GIN indexes, containment
Extensions references/extensions.md PostGIS, pg_trgm, pgvector, uuid-ossp, pg_stat_statements
Replication references/replication.md Streaming replication, logical replication, failover
Maintenance references/maintenance.md VACUUM, ANALYZE, pg_stat views, monitoring, bloat

Constraints

MUST DO

  • Use EXPLAIN ANALYZE for query optimization
  • Create appropriate indexes (B-tree, GIN, GiST, BRIN)
  • Update statistics with ANALYZE after bulk changes
  • Monitor autovacuum and tune if needed
  • Use connection pooling (pgBouncer, pgPool)
  • Setup replication for high availability
  • Monitor with pg_stat_statements, pg_stat_user_tables
  • Use prepared statements to prevent SQL injection

MUST NOT DO

  • Disable autovacuum globally
  • Create indexes without analyzing query patterns
  • Use SELECT * in production queries
  • Ignore replication lag monitoring
  • Skip VACUUM on high-churn tables
  • Use text for UUID storage (use uuid type)
  • Store large BLOBs in database (use object storage)
  • Ignore pg_stat_statements warnings

Output Templates

When implementing PostgreSQL solutions, provide:
1. Query with EXPLAIN ANALYZE output
2. Index definitions with rationale
3. Configuration changes with before/after values
4. Monitoring queries for ongoing health checks
5. Brief explanation of performance impact

Knowledge Reference

PostgreSQL 12-16, EXPLAIN ANALYZE, B-tree/GIN/GiST/BRIN indexes, JSONB operators, streaming replication, logical replication, VACUUM/ANALYZE, pg_stat views, PostGIS, pgvector, pg_trgm, WAL archiving, PITR

  • Database Optimizer - General database optimization
  • Backend Developer - Application query patterns
  • DevOps Engineer - Deployment and automation
    PostgreSQL Pro v1.1 - Enhanced

🔄 Workflow

Source: PostgreSQL 17 Release Notes & Use The Index, Luke!

Phase 1: Schema Design & Indexing

  • [ ] Normalization: Start with 3NF, denormalize if performance is required (Read-heavy).
  • [ ] Indexing Strategy: Choose B-Tree (Default), GIN (JSONB/Array), GiST (Geo/Range) or BRIN (Time-series) based on query patterns.
  • [ ] Vector Search: Install pgvector extension and configure HNSW indexes for AI/ML projects.

Phase 2: Query Tuning

  • [ ] Explain Analyze: See the actual cost and I/O consumption of the query with EXPLAIN (ANALYZE, BUFFERS).
  • [ ] Seq Scans: If there is a Sequential Scan on large tables, there is a missing index or bad statistics (ANALYZE table).
  • [ ] CTE Materialization: Postgres 12+ is generally smart, but check if NOT MATERIALIZED is needed in complex CTEs.

Phase 3: Maintenance & Config

  • [ ] Autovacuum: Tune autovacuum_vacuum_scale_factor settings to scale according to table size.
  • [ ] Connection Pooling: Reduce connection cost using PgBouncer (Especially for Serverless/Lambda).
  • [ ] Backup: Establish Point-in-Time Recovery (PITR) strategy with WAL archiving (pgBackRest).

Checkpoints

Phase Verification
1 Are frequent updates made to JSONB columns? (TOAST bloat risk).
2 Is work_mem setting safe relative to connection count? (OOM error risk).
3 Is Slow Query Log enabled? (log_min_duration_statement).

# Supported AI Coding Agents

This skill is compatible with the SKILL.md standard and works with all major AI coding agents:

Learn more about the SKILL.md standard and how to use these skills with your preferred AI coding agent.