Skip to content
Back to skills

Postgres Best Practices

ASecurity

PostgreSQL best practices for database design, query optimization, and performance tuning

  • 43 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 9, 2026
databasesgosqldatabaseperformance

Security analysis

A100/100

Scanned September 9, 2026

npx -y skills add baekenough/oh-my-customcode --skill postgres-best-practices --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Postgres Best Practices?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Postgres Best Practices
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/baekenough-postgres-best-practices/badge)](https://www.skillsdirectory.com/skills/baekenough-postgres-best-practices)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: postgres-best-practices
description: PostgreSQL best practices for database design, query optimization, and performance tuning
scope: core
user-invocable: false
---

# PostgreSQL Best Practices

## Query Optimization

### EXPLAIN ANALYZE (CRITICAL)
- Use `EXPLAIN ANALYZE` to understand query plans
- Identify slow operations: Seq Scan, Nested Loop
- Check row estimates vs actual rows
- Monitor buffers: shared hit vs read

### Indexing (CRITICAL)
- B-tree: default, most use cases
- GIN: JSONB, arrays, full-text search
- GiST: geometry, range types
- BRIN: large sequential tables (time-series)
- Partial indexes: filtered queries
- Covering indexes (INCLUDE): avoid heap fetches

### Index Maintenance
- Create indexes concurrently: `CREATE INDEX CONCURRENTLY`
- Monitor usage: `pg_stat_user_indexes`
- Remove unused indexes
- Reindex bloated indexes

## Table Design

### Partitioning (HIGH)
- Range partitioning: time-series data
- List partitioning: categorical data
- Hash partitioning: even distribution
- Declarative partitioning (PG 10+)

### Data Types
- Use appropriate types (int vs bigint, varchar vs text)
- JSONB for semi-structured data
- Arrays for multi-value columns
- UUIDs for distributed IDs

## Performance Tuning

### Vacuum and Autovacuum
- Autovacuum: default enabled
- Monitor bloat: `pg_stat_user_tables`
- Tune autovacuum thresholds
- Manual VACUUM for large updates

### Connection Pooling
- Use pgBouncer or PgPool
- Transaction pooling for short transactions
- Session pooling for long transactions
- Max connections: tune based on workload

### Configuration
- `shared_buffers`: 25% of RAM
- `work_mem`: per operation, tune carefully
- `effective_cache_size`: 50-75% of RAM
- `random_page_cost`: 1.1 for SSD

## References
- [PostgreSQL Performance Optimization](https://wiki.postgresql.org/wiki/Performance_Optimization)

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.