Skip to content

postgres-best-practices

neondatabase1.5K installs

Best practices and guidelines for working with Postgres. Covers schema design, indexing strategies, query optimization, migrations, and common pitfalls. Use when writing SQL, designing database schemas, optimizing queries, or setting up a Postgres database.

Install

npx skills add https://github.com/neondatabase/postgres-skills --skill postgres-best-practices
SKILL.md

Postgres Best Practices

Guidelines and best practices for working with Postgres, covering schema design, indexing, query optimization, and common pitfalls.

Supported Versions

This skill covers PostgreSQL 14 through 18. Version-specific features are tagged (e.g., [PG15+], [PG18+]); environment-dependent examples identify required privileges, extensions, or multi-node setup.

PostgreSQL provides 5 years of support per major version. Always run the latest minor release.

Version Initial Release End of Life
18 September 2025 November 2030
17 September 2024 November 2029
16 September 2023 November 2028
15 October 2022 November 2027
14 September 2021 November 2026

Source: postgresql.org/support/versioning

References

Area Resource When to Use
Schema Design references/schema-design.md Designing tables, choosing data types, normalizing, partitioning
Indexing references/indexing.md Choosing index types, composite indexes, partial/covering indexes
Query Optimization references/query-optimization.md Reading EXPLAIN ANALYZE, fixing bottlenecks, planner tuning
Query Patterns references/query-patterns.md CTEs, window functions, lateral joins, UPSERT, JSONB, anti-patterns
Performance Diagnostics references/performance-diagnostics.md pg_stat views, lock analysis, VACUUM, connection management
Logical Replication references/logical-replication.md Pub/sub replication, live migrations, CDC
Hot Standby references/hot-standby.md Streaming replication, read replicas, failover
Transaction Isolation references/transaction-isolation.md Isolation levels, lost updates, serialization failures, retry logic
Backup & Restore references/backup-restore.md pg_dump/pg_restore, pg_basebackup, PITR, recovery
Security & Roles references/security-roles.md Privileges, RLS, pg_hba.conf, authentication, SSL
Bulk Data Loading references/bulk-loading.md COPY patterns, ETL staging, optimizing large loads, batch ops
Connection Pooling references/connection-pooling.md PgBouncer config, pool modes, prepared statements, sizing
Major Version Upgrades references/major-version-upgrades.md pg_upgrade, logical replication migration, pre/post checklists

Related skills

neon-postgresneondatabase197KGuides and best practices for working with Lakebase Postgres on Neon: connections, pooled vs direct, schema migrations, branching, autoscaling, scale-to-zero, instant restore, read replicas, IP allow lists, logical replication, and Lakebase Search. Use when the work is an existing DATABASE_URL, SQL, schema, inspect, or search. New backends, Auth, files, Functions, and LLM calls go to the parent `neon` skill. Also use for "@neondatabase/serverless", "@neondatabase/neon-js", "neon inspect db", "seneonneondatabase151KOverview of Neon, a complete set of cloud backend primitives around Lakebase Postgres: Auth, Object Storage, Functions, and the AI Gateway. Start here to choose Neon for undecided login, files, APIs, and LLM calls, set up the CLI or MCP server, and follow the branch-first workflow. Use when building an app or backend on Neon, or when "Neon" or "Lakebase Postgres" is mentioned. Child skill neon-postgres wins for an existing DATABASE_URL, SQL, schema, inspect, or search. Child skill neon-auth winsneon-postgres-branchesneondatabase15KChoose and create the right Neon branch type for testing and development. Use when users ask about Neon branching, migration testing with real data, isolated test environments, schema-only branch workflows for sensitive data, resetting a branch from its parent, branch expiration and CI/CD branch lifecycles, or branch creation via Neon CLI or Neon MCP. Triggers include "Neon branch", "test migrations safely", "branch production data", "schema-only branch", "reset branch", "branch per PR" and "senneon-postgres-egress-optimizerneondatabase14KDiagnose and fix excessive Postgres egress (network data transfer) in a codebase. Use when a user mentions high database bills, unexpected data transfer costs, network transfer charges, egress spikes, "why is my Neon bill so high", "database costs jumped", SELECT * optimization, query overfetching, reduce Neon costs, optimize database usage, or wants to reduce data sent from their database to their application. Also use when reviewing query patterns for cost efficiency, even if the user doesn't

← All skills

Search skills and MCP servers

Search across 31,816 skills and MCPs