postgresql-best-practices
SKILL.md
PostgreSQL Best Practices (OpenAI Golden Knowledgebase)
Canonical Source
- Read
{baseDir}/references/openai-scaling-postgresql.mdfirst. - Source URL:
https://openai.com/index/scaling-postgresql/ - Published:
January 22, 2026
Non-Negotiable Rules
- Preserve all named technologies, numbers, and dates exactly as written in the source.
- Preserve section order and intent exactly:
Use Postgres for everythingPartitioning and indexing strategyQuery optimizationSchema managementReplication and load balancingResults
- Keep technology and project names unchanged:
Citus,Citus columnar,PgBouncer,PgAnalyze,Patroni,Haste,pgroll,pgai. - If a detail is not in the source file, explicitly state:
Not stated in the source. - Do not add outside recommendations, interpretations, or alternative patterns that are not present in the source.
Required Coverage
When summarizing or operationalizing, cover all of the following source facts:
- Scale baseline and growth metrics:
- Over
4 billion queriesevery day - Over
2,000database instances - Growth from one Postgres instance in
2022 - Over
1 billionmonthly users and over800 millionweekly users - Traffic growth of about
2.5xin just over a year
- Over
- Platform strategy:
- Keep PostgreSQL as the core datastore
- Use
CitusandCitus columnarfor distributed and analytical/high-throughput use cases
- Partitioning/indexing decisions:
- Hash partitioning for large event/log tables
- Time-range partitioning for append-only datasets
- Composite index strategy
- Custom index migration tooling to avoid blocking writes
- Bottlenecks: table bloat, autovacuum inefficiencies, poor index selectivity
- Spike drivers: full table scans, huge B-tree indexes, write amplification from hot rows
- Query optimization operations:
- Query fingerprints and execution stats
- Lock contention and long-running transaction identification
- Rewriting expensive joins/subqueries
- Statement-level timeout and retry strategy
- Query budget alerts and EXPLAIN-based review workflows
- Reported impact:
43%DB load reduction,38%p95 latency reduction
- Schema management workflows:
- Expand -> migrate -> contract
- Async backfills with throttling and checkpointing
- Canary migrations with progressive rollout
- Automatic rollback on failing migration health checks
- Open-sourced tools:
Hasteandpgroll
- Replication and load balancing:
- Region-aware read replicas
- Replica lag monitoring and query shedding
- Dedicated analytical replicas
- Failover orchestration with
Patroniand custom routing logic - Deep integration of
PgBouncerandPgAnalyze
- Results and forward direction:
- Low latency under exponential growth
- High migration velocity without sacrificing uptime
- Operating thousands of instances with lean infrastructure teams
- Ongoing iteration and open-source contributions including
haste,pgroll,pgai
Output Format
When producing a complete answer, use these exact headings in this order:
Use Postgres for everythingPartitioning and indexing strategyQuery optimizationSchema managementReplication and load balancingResults
Always include the source URL when attribution is requested.
Weekly Installs
1
Repository
ahmed6ww/ax-agentsGitHub Stars
1
First Seen
7 days ago
Security Audits
Installed on
zencoder1
amp1
cline1
openclaw1
opencode1
cursor1