PostgreSQL Skill
This skill is the working reference for PostgreSQL 16, 17, and 18 (current baseline: PG16). Cross-version notes go back to PG14 where behavior changed; PG13 and earlier are out of scope. PG14 reached end-of-life on 2026-11-12 (final minor 14.25); flag upgrade urgency when a user is on it. PostgreSQL 19 is a release candidate with GA planned for 2026-11-19; its changes live in 100-pg-versions-features.md and in PostgreSQL 19 callouts in topic files.
The skill is provider-neutral: bare-metal/self-hosted, containers, and Kubernetes operators are all covered. Managed-service limitations are called out categorically ("most managed providers disable X") without naming or recommending any specific vendor.
Each topic lives in its own reference file under references/. SKILL.md routes a user question to the right reference; the reference contains the executable detail, version admonitions, and primary-source citations.
Usage Workflow
When this skill is loaded, follow these steps to answer the user's question:
- Identify the topic. Match the user's question against the Routing Table below using the keyword column. For multi-topic questions (e.g. "the locking behavior of REINDEX CONCURRENTLY") select multiple files.
- Load the matched reference file(s). Use the Read tool against
references/NN-topic.md. Do not paraphrase from memory; use the reference's version notes and primary-source URLs. - Follow See Also. Each reference ends with a See Also section linking related files. Follow it for cross-cutting questions (e.g. a VACUUM question pulls in MVCC, autovacuum, and wraparound).
- Answer using the file. Lead with the direct answer or code, then version notes via admonitions, then caveats, then citation URLs.
- Verify high-risk instructions against primary sources. These references are a working compilation, not a substitute for the matching PostgreSQL manual. Before advising recovery, durability changes, failover, privilege changes, or destructive maintenance, fetch the cited upstream section for the actual server version. Resolve conflicting advice before giving commands; identify anything you could not verify.
- Assume PG16 unless told otherwise. If the user does not state a version, answer for PG16 and add a one-line note for differences on PG17/PG18 (and PG19, a release candidate until GA). Only ask the user which version they are on if the answer materially changes across supported versions (e.g. wraparound mechanics, planner statistics behavior, archive_command vs archive_library). When the project pins a version (a Docker tag, a CI service image,
SELECT version()), use that one.
When the task is to build, not to answer. Writing a schema, migration, query, index, trigger, function, or ORM model that targets Postgres goes through the same lookup, before any code is written:
- List the Postgres operations the change involves: new tables, column types, keys and constraints, indexes,
ALTERon a populated table, JSONB access, bulk loads, queue or locking patterns. - Route each operation through the Routing Table and read the matching sections. Common starting points:
- Column types: 14, 17, 18, 19.
- Keys and constraints: 37, 38.
- Indexes: 22, then the type-specific file.
- DDL on live tables: 01 for lock levels, 43, and 26 for
CONCURRENTLY. - Partitioning: 35.
- RLS: 47.
- Bulk loads: 66.
- Work queues: 104 or 43.
- Write the code the references support. In the reply, name any pitfall the references raised that shaped the code, such as a lock level, a type choice, or a version difference.
[!NOTE]
When a Postgres question does not obviously match a single file, load these cross-cutting entry points first:
references/102-skill-cookbook.md(symptom-driven recipes spanning multiple files),references/22-indexes-overview.md(index decision routing),references/56-explain.md(plan reading),references/64-system-catalogs.md(catalog introspection).
User Response Format
Structure every answer using this skill as follows:
- Lead with the direct answer or pattern. If a SQL snippet or
psqlcommand satisfies the question, put that first. - Add version admonitions inline. Use
> [!NOTE] PostgreSQL 17for new-in-17 features,> [!WARNING] Removed/Deprecatedfor things gone (with the version they were removed in and the replacement). - Call out managed-service limitations categorically when relevant. Phrase as "most managed providers disable X" — never name a specific provider.
- End with source links. Cite the official PostgreSQL docs pinned to the correct major version (e.g.
https://www.postgresql.org/docs/16/sql-vacuum.html, not/docs/current/). - For longer answers, use headers matching the reference file's section headings so the user can jump to the source.
- For version-sensitive answers, default to PG16 + add inline
> [!NOTE] PG17/> [!NOTE] PG18/PostgreSQL 19deltas. Only ask the user to confirm version when the answer flips between supported majors. - For performance investigations, explain the plan tree from leaf inputs toward their parents. Compare estimated
rowswithactual rowsper loop; useloopsto calculate total work separately. A 10× mismatch is a useful investigation threshold, not proof of a root cause. Account for LIMIT, early termination, and unexecuted nodes. PostgreSQL executes plans on demand, not in a strict deepest-node-first sequence.
<constraints>
Operational Safety
- XID hard stop: connect to the affected database as a superuser, resolve old transaction and slot horizons, then run ordinary database-wide
VACUUMoutside a transaction block. Do not useFULL,FREEZE, or routine single-user recovery.VACUUM FREEZEandVACUUM (FREEZE)are equivalent. Follow the version-pinned recovery procedure. - Corruption salvage: preserve the complete stopped cluster, including external WAL and tablespaces. Work on an isolated copy.
pg_resetwalis only a last resort for WAL/control corruption that prevents startup, not an XID-exhaustion repair. Its dry run does not prove consistency; use same-major binaries, then dump and restore into a separate new cluster. Do not replace individual live relation files from an old backup. - Destructive decisions: resolve prepared transactions with their coordinator, confirm a slot's consumer before dropping it, and fence the former primary before failover. State data-loss and rebuild consequences before presenting the operation.
- Verification limits: successful
pg_dump,pg_amcheck, or checksum checks do not prove absence of every corruption class or application inconsistency. Distinguish a documented procedure, a tested example, and an unverified assumption.
</constraints>
Routing Table
Keywords are matched case-insensitively. A single file can match multiple keyword phrases.
| Keywords | File | Scope |
|---|---|---|
| CREATE TABLE, ALTER TABLE, DROP TABLE, schema, sequence, generated column, identity column, IF NOT EXISTS |