Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Postgresql Knowledge Patch?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/nevaberry-postgresql-knowledge-patch)
---
name: postgresql-knowledge-patch
description: PostgreSQL
version: "19.0"
license: MIT
metadata:
author: Nevaberry
---
# PostgreSQL Knowledge Patch
Load this skill when writing or reviewing PostgreSQL SQL, upgrade plans,
server configuration, replication, backup procedures, monitoring, client code,
or extensions. Use the topic references for complete guidance and examples.
## Reference index
| Reference | Topics |
| --- | --- |
| [Migration and compatibility](references/migration-and-compatibility.md) | Index and foreign-key repairs, locale changes, encoding, upgrade configuration, release availability and support |
| [Clients and CLI](references/clients-and-cli.md) | Authentication, TLS, session identity, libpq, psql, pgbench, notification recovery |
| [COPY, backup, and maintenance](references/copy-backup-and-maintenance.md) | COPY filters, dump compatibility, backups, maintenance privileges, autovacuum, I/O and caches |
| [Observability and planning](references/observability-and-planning.md) | Monitoring changes, statistics resets and preservation, wait events, planner advice, JIT |
| [Replication and recovery](references/replication-and-recovery.md) | WAL boundaries, standby replay, logical slots, failover, replication origins and values |
| [SQL and schema](references/sql-and-schema.md) | Constraints, partitions, triggers, PL/pgSQL, time zones, UUIDs, collations |
| [JSON](references/json.md) | Constructors, nulls, serialization, record validation, paths, SQL/JSON query functions, JSON_TABLE |
| [Extensions and FDW](references/extensions-and-fdw.md) | C receive functions, index handlers, planner hooks, SCRAM passthrough, remote transaction modes |
## Breaking changes and upgrade actions
### Authentication and dump compatibility
PostgreSQL 19 removes RADIUS authentication: replace `radius` rules in
`pg_hba.conf` before upgrading. Successful MD5 password authentication issues
a warning; `md5_password_warnings = off` suppresses it.
PostgreSQL 19 fixes `standard_conforming_strings` at `on` and removes
`escape_string_warning`. Regenerate older dumps made with
`standard_conforming_strings = off` using version 19 or later of `pg_dump` or
`pg_dumpall`, or create the dumps with the setting enabled.
From 17.6, plain dump scripts can use `\restrict`; restore these scripts with
a psql client that supports it.
### Upgrade blockers and lock capacity
Before `pg_upgrade` to PostgreSQL 19, rename databases, roles, or tablespaces
whose names contain carriage returns or line feeds. Drop indexes using
`btree_gist` operator classes for `inet` or `cidr` before upgrading and recreate
them with the built-in GiST operator classes, now the defaults for both types.
Migrate databases using `MULE_INTERNAL` by dumping and restoring with a
supported encoding.
PostgreSQL 19 defaults `max_locks_per_transaction` to 128. Double an explicit
value carried over from an older release to keep equivalent lock capacity
under the new allocation scheme. Remove `io_workers` from carried-forward
configuration; four settings replace it for automatic I/O worker scaling.
### Index and constraint repairs
After updating to 14.24, run `REINDEX INDEX` on `btree_gist` indexes over
`float4` or `float8` columns that might contain `NaN`, and over `bit` or
`bit varying` columns. Also reindex B-tree indexes over `ltree` values with
more than about 14,653 labels.
After the relevant updates, drop and recreate affected detached-partition
foreign keys referencing partitioned tables (17.1), and self-referencing
foreign keys on partitioned tables that gained partitions after constraint
creation (17.5). Correct violating rows first; use the 17.1 diagnostic query
to identify affected detached-table constraints.
For PostgreSQL 18, each referencing/referenced foreign-key column pair must
both use deterministic collations or share the same nondeterministic collation.
Correct incompatible pairs before dump/restore or `pg_upgrade`.
### Locale-dependent stored data
After `pg_upgrade` to PostgreSQL 18, rebuild full-text search and `pg_trgm`
indexes on clusters whose non-libc provider differs from libc for `LC_CTYPE`
character handling.
PostgreSQL 19 classifies characters during full-text search and `pg_trgm`
parsing with each database's locale provider. After `pg_upgrade`, recompute stored `tsvector` values where
that non-libc provider classifies characters differently from its `LC_CTYPE`.
Also rebuild indexes using `dmetaphone()`, `dmetaphone_alt()`, `soundex()`,
`metaphone()`, or `difference()` after upgrading.
### COPY, foreign transactions, and empty JSON arrays
In PostgreSQL 18, server-side `COPY FROM` treats `\.` in CSV files as data;
in psql scripts feeding CSV to `COPY FROM STDIN`, a line containing only `\.`
still ends input. Check `\copy` scripts using older psql clients against an
18 server. PostgreSQL 19 rejects system columns in `COPY FROM ... WHERE`;
rewrite affected filters to use ordinary columns.
PostgreSQL 19 `postgres_fdw` passes `READ ONLY` and `DEFERRABLE` status to
remote sessions, so local `READ ONLY` transactions cannot modify remote rows.
`SELECT json_array(SELECT 1 WHERE false);` now returns `[]` in PostgreSQL 19;
update callers that tested for SQL `NULL` on an empty result.
### Monitoring and extension interfaces
In PostgreSQL 18, `pg_stat_io` replaces `op_bytes` with `read_bytes`,
`write_bytes`, and `extend_bytes`. Move `wal_write`, `wal_sync`,
`wal_write_time`, and `wal_sync_time` monitoring from `pg_stat_wal` to WAL
rows in `pg_stat_io`, where `track_wal_io_timing` applies.
For PostgreSQL 19, in `pg_stat_subscription_stats`, replace `sync_error_count`
with `sync_table_error_count` for table synchronization errors. The wait-event type
`BUFFERPIN` becomes `BUFFER`, and `BufferPin` becomes `BufferCleanup`;
replace `BufferContent` matches with handling for `BufferShared`,
`BufferShareExclusive`, and `BufferExclusive`.
Use static storage for routine structures returned by index access method
handlers in PostgreSQL 19. Port extensions using removed `get_relation_info_hook`
to `build_simple_rel_hook`, which runs at a different planning point.
Since 17.0, user-defined data type receive functions may get input without a terminating
NUL; use the buffer length or make a terminated copy before C string APIs.
## Maintenance, recovery, and performance
### Maintenance scope and privileges
Maintenance operations such as `CREATE INDEX`, `REFRESH MATERIALIZED VIEW`,
and `VACUUM` use a restricted `search_path` in PostgreSQL 17. If a function
called by an expression index or materialized view needs objects outside that
path, give it an explicit path through trusted schemas.
Grant `MAINTAIN` on a relation or grant `pg_maintain` across relations for
`VACUUM`, `ANALYZE`, `REINDEX`, `REFRESH MATERIALIZED VIEW`, `CLUSTER`, and
`LOCK TABLE`.
In PostgreSQL 18, parent `VACUUM` and `ANALYZE` also process inheritance
children. Use `ANALYZE ONLY public.events;` for the partitioned parent's
statistics without analyzing each partition. PostgreSQL 19 provides
`REPACK (CONCURRENTLY) public.events;` to reclaim disk space while keeping
the table available for reads and writes.
### Worker capacity and statistics preservation
In PostgreSQL 18, `autovacuum_worker_slots` reserves capacity at server start;
adjust `autovacuum_max_workers` at runtime up to that count. Use
`autovacuum_vacuum_max_threshold` to cap large-table dead-tuple thresholds.
PostgreSQL 19's `autovacuum_max_parallel_workers` controls parallel index
vacuuming by autovacuum. In parallel `VACUUM`, the leader and workers share
`vacuum_cost_limit` when cost-based delay is enabled; tune for the whole operation.
PostgreSQL 18 `pg_upgrade` preserves ordinary optimizer statistics by default;
extended statistics still need `ANALYZE`. Use `pg_upgrade --no-statistics` to
opt out, or run `vacuumdb --analyze-only --missing-stats-only appdb` as a
superuser to fill missing statistics. PostgreSQL 19 defaults JIT off;
set `jit = on` where workloads benefit.
### Backup and logical replication
Enable `summarize_wal = on` and retain summaries with `wal_summary_keep_time`
over the LSN range an incremental backup needs. `pg_combinebackup --link`
can hard-link eligible input files into the output; use the default mode when
input and output backups must be usable independently.
Mark a subscription at creation with `WITH (failover = true)` or pass `true`
as the fifth argument to `pg_create_logical_replication_slot()`. On the
standby, use `sync_replication_slots` or call `pg_sync_replication_slots()`;
on the publisher, `synchronized_standby_slots` holds logical delivery until
specified physical slots confirm WAL.
`pg_upgrade` can preserve valid publisher slots and subscriber state when
the source cluster is already on 17 or later.
PostgreSQL 19 can enable logical replication without restarting when already
running with `wal_level = replica`, and can logically replicate sequence
values. Use `WAIT` on a standby to wait for replay to reach the primary's write
before reading the result.
From 17.8, a server error processing a received `NOTIFY` closes the listening
connection: reconnect, issue `LISTEN` again, and refresh application state if
missed notifications could leave it stale.
## SQL and client quick reference
### SQL/JSON result semantics
Query-fed `json_array` takes a single-column `SELECT` and always skips SQL
`NULL` rows. The expression-list form supports `NULL ON NULL` or
`ABSENT ON NULL`. Use `@?` or `jsonb_path_exists` for matching items, and
`@@` or `jsonb_path_match` for a predicate emitting one Boolean or null result:
even a false predicate result counts as an item for an existence check.
`JSON_QUERY` defaults to unwrapped `jsonb`, so multiple matches trigger
`ON ERROR`; `WITH WRAPPER` always wraps and `WITH CONDITIONAL WRAPPER` wraps
multiple results. `JSON_VALUE` requires a single scalar, removes string quotes,
and defaults to `text`. JSON null becomes SQL `NULL` with `JSON_VALUE` but
stays JSON null with `JSON_QUERY`. Errors casting input to `jsonb` propagate
before the SQL/JSON query functions' `ON ERROR` clauses apply.
`JSON_TABLE` emits one row per row-path match and can directly reference a
preceding `FROM` item. Sibling `NESTED PATH` matches contribute separate rows
with `NULL` in the other sibling's columns. `FOR ORDINALITY` starts at 1,
with a separate counter for each nested path.
### Constraint staging and UUID inspection
PostgreSQL 18 supports named `NOT NULL` constraints in `pg_constraint`;
`NOT VALID` checks new writes immediately and allows separate validation:
```sql
ALTER TABLE accounts ADD CONSTRAINT accounts_email_nn NOT NULL email NOT VALID;
ALTER TABLE accounts VALIDATE CONSTRAINT accounts_email_nn;
```
`CHECK` and foreign key constraints declared `NOT ENFORCED` are recorded
without checking writes. Inspect `pg_constraint.conenforced` for enforcement.
Pass an optional `interval` to `uuidv7()` to shift its embedded timestamp.
`uuid_extract_timestamp(uuid)` returns `timestamp with time zone` for UUID
versions 1 and 7, and `NULL` otherwise; closeness to actual generation time
depends on the generator. `uuid_extract_version(uuid)` returns `smallint`
for supported RFC 9562 variants and `NULL` for other variants.
### psql and libpq
Use `\startpipeline` to queue commands without waiting after each one and
`\endpipeline` to collect results and return to normal execution.
Use `\watch min_rows=1` to end a watch when the query returns zero rows.
For libpq cancellation, create with `PQcancelCreate()`, use
`PQcancelBlocking()` or drive `PQcancelStart()` and `PQcancelPoll()`, and
release with `PQcancelFinish()`. The cancellation connection can use encryption
when the original connection uses it.