Postgres AI Prompts
42 free, production-ready Postgres AI prompts — copy-paste ready for ChatGPT, Claude, or Cursor. Every prompt ships with fill-in placeholders, a worked example, and production-safety notes, so you get a usable answer on the first try.
- Postgres Advanced
Postgres md5-to-SCRAM Password Migration Prompt
Migrate a Postgres instance from legacy md5 password auth to scram-sha-256 without locking out clients — sequencing password_encryption, per-user re-hashing, driver compatibility, and pg_hba.conf so no role is stranded.
- Claude
- ChatGPT
- Cursor
Open prompt - Postgres Advanced
Postgres auto_explain Plan Regression Detection Prompt
Set up auto_explain to catch the query whose plan flipped in production — capturing the bad plan with timing and buffers only when it matters — then diagnose why the planner chose it, without logging every fast query.
- Claude
- ChatGPT
- Cursor
Open prompt - Postgres Advanced
Postgres BRIN Index Design for Time-Series Tables Prompt
Decide whether a BRIN index will actually speed up your large, naturally-ordered table — and size pages_per_range correctly — instead of blindly reaching for a B-tree that bloats storage on append-only data.
- Claude
- ChatGPT
- Cursor
Open prompt - Postgres Advanced
Postgres postgres_fdw Federation Design Prompt
Design a postgres_fdw setup that actually pushes down joins, filters, and aggregates to the remote server — instead of dragging whole tables across the network — and get the security and failure modes right.
- Claude
- ChatGPT
- Cursor
Open prompt - Postgres Intermediate
Postgres Keyset (Cursor) Pagination Optimization Prompt
Convert a slow OFFSET/LIMIT pagination query into stable keyset (seek) pagination that stays fast on deep pages — with a matching index and a correct tuple-comparison predicate, not a broken one-column WHERE.
- Claude
- ChatGPT
- Cursor
Open prompt - Postgres Advanced
Postgres Parallel Query Worker Tuning Prompt
Work out why a big analytical query isn't going parallel — or is spawning too many workers and starving everything else — and set the parallel GUCs from evidence in the plan instead of copy-pasted blog values.
- Claude
- ChatGPT
- Cursor
Open prompt - Postgres Advanced
Postgres pgAudit Audit Logging Setup Prompt
Configure pgAudit for compliance-grade logging that captures the statements auditors need without drowning the disk or leaking secrets — scoped by role and object instead of logging every SELECT on the whole database.
- Claude
- ChatGPT
- Cursor
Open prompt - Postgres Advanced
Postgres Read-Replica Load Balancing Design Prompt
Design read/write query routing across streaming replicas that respects replication lag and read-your-writes consistency — so you scale reads without serving stale data to the user who just wrote it.
- Claude
- ChatGPT
- Cursor
Open prompt - Postgres Intermediate
Postgres Memory Sizing (shared_buffers & work_mem) Prompt
Size shared_buffers, work_mem, maintenance_work_mem and effective_cache_size from your actual RAM, connection count, and cache-hit evidence — not the '25% of RAM' rule of thumb that quietly causes OOM or disk spills.
- Claude
- ChatGPT
- Cursor
Open prompt - Postgres Advanced
Postgres HOT Update and Fillfactor Tuning Prompt
Diagnose why an update-heavy table bloats and burns write I/O despite autovacuum, then decide on fillfactor, index removal, and column changes to unlock Heap-Only Tuple (HOT) updates — cutting index write amplification and bloat at the source.
- Claude
- ChatGPT
- Cursor
Open prompt - Postgres Advanced
Postgres Index Bloat and REINDEX CONCURRENTLY Strategy Prompt
Turn raw index-bloat and usage stats into a ranked, safe REINDEX/DROP plan — so you reclaim space and restore performance without taking an outage or dropping an index something silently depends on.
- Claude
- ChatGPT
- Cursor
Open prompt - Postgres Advanced
Postgres Prepared Statement Generic vs Custom Plan Tuning Prompt
Diagnose why a parameterized/prepared query flipped to a bad generic plan after the sixth execution — and decide between plan_cache_mode, query rewrites, or letting Postgres re-plan — so latency stops spiking under skewed parameters.
- Claude
- ChatGPT
- Cursor
Open prompt - Postgres Advanced
Postgres Idle-in-Transaction Session Remediation Prompt
Track down long 'idle in transaction' sessions that hold locks and pin the xmin horizon so autovacuum can't reclaim dead tuples, then decide what to terminate, what to fix in the app, and which timeouts to set — before bloat and lock waits cascade into an outage.
- Claude
- ChatGPT
- Cursor
Open prompt - Postgres Advanced
Postgres Materialized View Refresh Strategy Prompt
Design a safe refresh strategy for Postgres materialized views — choosing between plain and CONCURRENTLY refresh, scheduling cadence, staleness tolerance, and the unique index CONCURRENTLY requires — so dashboards stay fast without long ACCESS EXCLUSIVE locks or runaway bloat on the matview.
- Claude
- ChatGPT
- Cursor
Open prompt - Postgres Advanced
Postgres Temp File Spill & work_mem Tuning Prompt
Diagnose why queries spill sorts, hashes, and aggregates to temp files on disk, then right-size work_mem per-query and per-role instead of globally — so slow queries stop thrashing disk without blowing up total memory under concurrency.
- Claude
- ChatGPT
- Cursor
Open prompt - Postgres Advanced
Postgres Checkpoint & WAL Throughput Tuning Prompt
Smooth out checkpoint-driven I/O spikes and write stalls by tuning checkpoint, WAL, and full-page-write settings for the workload — without risking longer crash recovery than the RTO allows.
- Claude
- ChatGPT
Open prompt - Postgres Advanced
Postgres Disk-Full & pg_wal Growth Emergency Triage Prompt
Work through a Postgres disk-full or runaway pg_wal/pg_xlog incident under pressure — find what is consuming space, free it safely, and recover the instance without deleting WAL Postgres still needs.
- Claude
- ChatGPT
Open prompt - Postgres Advanced
Postgres Integer Primary-Key / Sequence Exhaustion Remediation Prompt
Plan the migration of an int4 (serial) primary key approaching its 2.1-billion ceiling to bigint, with a low-downtime backfill and a tested cutover before INSERTs start failing.
- Claude
- ChatGPT
Open prompt - Postgres Advanced
Postgres on Kubernetes Operator Troubleshooting Prompt
Diagnose a Postgres cluster managed by a Kubernetes operator (CloudNativePG, Crunchy PGO, Zalando) — stuck failovers, pods CrashLooping, PVC/storage issues, and split-brain risk — using operator status and pod logs.
- Claude
- ChatGPT
Open prompt - Postgres Intermediate
Postgres pg_dump / pg_restore & Bulk Load Tuning Prompt
Speed up a slow logical dump/restore or large data load by tuning pg_dump/pg_restore parallelism and the session-level settings (maintenance_work_mem, WAL, indexes, constraints) without compromising durability of the live system.
- Claude
- ChatGPT
Open prompt - Postgres Intermediate
Postgres pg_hba.conf Authentication & TLS Hardening Prompt
Review and harden Postgres client authentication — pg_hba.conf rules, auth methods (scram vs md5 vs trust), and TLS configuration — to close access gaps without locking out legitimate apps or replicas.
- Claude
- ChatGPT
Open prompt - Postgres Advanced
Postgres Planner Mis-Estimation & Extended Statistics Prompt
Fix bad query plans caused by wrong row estimates — correlated columns, skewed distributions, or stale stats — using ANALYZE, statistics targets, and CREATE STATISTICS rather than blunt planner hacks.
- Claude
- ChatGPT
Open prompt - Postgres Intermediate
Postgres Statement Timeout & Runaway Query Governance Prompt
Set up guardrails against runaway and stuck queries — statement_timeout, idle_in_transaction_session_timeout, lock_timeout, and a safe termination playbook — scoped per role so analytics and OLTP get the right limits.
- Claude
- ChatGPT
Open prompt - Postgres Advanced
Postgres TOAST & Large-Value Storage Tuning Prompt
Diagnose performance and bloat problems caused by large column values (text, JSONB, bytea) and tune TOAST storage strategy, compression, and column layout to cut I/O and detoasting overhead.
- Claude
- ChatGPT
Open prompt - Postgres Intermediate
Postgres Full-Text Search Design Prompt
Turn a fuzzy search requirement into a concrete Postgres full-text design — tsvector storage, the right index, a text search configuration, and a ranked query — so search is fast, relevant, and maintainable instead of a pile of ILIKE scans.
- Claude
- ChatGPT
- Cursor
Open prompt - Postgres Advanced
PostgreSQL HA Automatic Failover Design Prompt
Produces a reviewed high-availability architecture for automatic PostgreSQL failover using Patroni or repmgr, covering quorum/DCS topology, replication mode, fencing, traffic routing, and a concrete failover test plan.
- Claude
- ChatGPT
- Cursor
Open prompt - Postgres Intermediate
Postgres Index Type Selector Prompt
Pick the right index access method — B-tree, BRIN, GIN, GiST, Hash, or SP-GiST — for a specific column and query pattern, reasoning from cardinality, data distribution, and the operators your queries actually use.
- Claude
- ChatGPT
- Cursor
Open prompt - Postgres Intermediate
Postgres JSONB Schema Design Review Prompt
Review or design a JSONB column — deciding JSONB vs normalized columns, choosing the GIN opclass (jsonb_path_ops vs default), shaping containment and path queries, and avoiding TOAST and bloat — for a table that mixes structured and semi-structured data.
- Claude
- ChatGPT
- Cursor
Open prompt - Postgres Advanced
Postgres Logical Replication and CDC Setup Prompt
Design a complete logical replication / Change Data Capture pipeline — publications, subscriptions, replication slots, initial sync strategy, conflict handling, and slot-bloat monitoring — for streaming Postgres changes to a downstream system.
- Claude
- ChatGPT
- Cursor
Open prompt - Postgres Advanced
Postgres Major Version Upgrade Planner Prompt
Turn a 'we need to upgrade Postgres' ask into a concrete, sequenced upgrade plan — pg_upgrade vs logical-replication cutover, pre-checks, extension compatibility, a rollback, and post-upgrade statistics — so the upgrade lands with known downtime instead of a surprise outage.
- Claude
- ChatGPT
- Cursor
Open prompt - Postgres Advanced
Postgres PITR WAL Backup Strategy Prompt
Turn an RPO/RTO target into a concrete WAL-archiving and Point-In-Time-Recovery design — base backups, archive command, retention, and a tested restore runbook — so you can recover to any moment instead of hoping a nightly dump is enough.
- Claude
- ChatGPT
- Cursor
Open prompt - Postgres Advanced
PostgreSQL Row-Level Security Policy Design Prompt
Produces a reviewed Row-Level Security design for multi-tenant isolation, with CREATE POLICY statements separating USING and WITH CHECK, a tenant-context strategy via session variables, performance analysis, and a test matrix proving tenants cannot see each other's rows.
- Claude
- ChatGPT
- Cursor
Open prompt - Postgres Advanced
PostgreSQL XID Wraparound Prevention Prompt
Produces a prioritized diagnosis and remediation plan for transaction ID and multixact wraparound risk, reading datfrozenxid/relfrozenxid ages, tuning freeze settings, and staging emergency aggressive vacuums before the cluster is forced read-only.
- Claude
- ChatGPT
- Cursor
Open prompt - Postgres Intermediate
Postgres postgresql.conf Workload Tuning Prompt
Get a reviewed postgresql.conf tuning plan for your specific hardware and workload — memory, WAL/checkpoint, planner, and autovacuum settings explained one by one, with how to verify each took effect.
- Claude
- ChatGPT
- Cursor
Open prompt - Postgres Advanced
Postgres Declarative Partitioning Design Prompt
Design a declarative partitioning scheme for a large table — pick the strategy and key, plan indexes and constraints, and lay out a safe migration from the existing monolith with automated partition maintenance.
- Claude
- ChatGPT
- Cursor
Open prompt - Postgres Advanced
Postgres Index Advisor from pg_stat_statements Prompt
Mine pg_stat_statements for your most expensive queries and get a prioritized list of missing indexes to add and redundant indexes to drop — with the write cost of each spelled out.
- Claude
- ChatGPT
- Cursor
Open prompt - Postgres Advanced
Postgres Lock Contention & Deadlock Investigation Prompt
Untangle blocking chains and deadlocks from pg_locks, pg_stat_activity, and log output — pinpoint the blocker, explain the lock conflict, and fix the access pattern so it stops recurring.
- Claude
- ChatGPT
- Cursor
Open prompt - Postgres Intermediate
Postgres pgbouncer Pool Sizing & Connection Tuning Prompt
Size pgbouncer pools and pick a pooling mode for your app's connection behavior — so you stop exhausting max_connections, cut connection overhead, and avoid the subtle bugs transaction pooling introduces.
- Claude
- ChatGPT
- Cursor
Open prompt - Postgres Advanced
Postgres Replication Lag Debugging Prompt
Diagnose streaming or logical replication lag from pg_stat_replication and pg_replication_slots — find where the bytes are stuck (send, write, flush, replay) and fix the cause without losing WAL or risking the primary.
- Claude
- ChatGPT
- Cursor
Open prompt - Postgres Intermediate
Postgres Slow Query EXPLAIN Triage Prompt
Turn a confusing EXPLAIN (ANALYZE, BUFFERS) plan into a ranked, plain-English diagnosis with concrete index/rewrite fixes and a verification step — so you fix the real bottleneck, not a guess.
- Claude
- ChatGPT
- Cursor
Open prompt - Postgres Advanced
Postgres VACUUM, Bloat & Autovacuum Tuning Prompt
Diagnose table and index bloat, decide between VACUUM, autovacuum tuning, and a rebuild, and produce per-table autovacuum settings — so dead tuples and wraparound risk stop quietly degrading your database.
- Claude
- ChatGPT
- Cursor
Open prompt - Postgres Advanced
Postgres Zero-Downtime Schema Migration Planner Prompt
Turn a risky schema change into a lock-aware, multi-step migration plan that avoids long ACCESS EXCLUSIVE locks — with the exact statements, lock_timeout guards, and a back-out path for each phase.
- Claude
- ChatGPT
- Cursor
Open prompt
About these Postgres AI prompts
This is a free, curated collection of Postgres AI prompts for DevOps and platform engineers — prompt templates that turn Claude, ChatGPT, or Cursor into a focused Postgres assistant. Instead of re-explaining your setup every time, each prompt has fill-in placeholders, a realistic worked example, and explicit safety and back-out notes, so it's safe to use against production Postgres.
Browse all 42 above, or explore the wider Postgres prompts and troubleshooting guides, the full DevOps AI prompt library, and run or compare any prompt live in the Prompt Workspace. Hit a production issue instead? Try the free Incident Assistant.