Skip to content

PostgreSQL 19 publications: read EXCEPT entries, manage allSequences and except - #354

Merged
archlemon merged 4 commits into
mainfrom
pg19-publications
Nov 21, 2026
Merged

archlemon merged 4 commits into
mainfrom
pg19-publications

Conversation

@archlemon

Copy link
Copy Markdown
Member

Fixes #327
Fixes #328
Fixes #335
Fixes #336

Part of #325.

What changes

  • Introspection (Publications on PostgreSQL 19: EXCEPT rows read as published tables #327): pg_publication_rel rows with prexcept = true (PostgreSQL 19) are read into LivePublication.Except instead of Tables, and puballsequences into AllSequences. Both columns are read through to_jsonb(...), so the queries still run on 15–18. Excepted inheritance children fold into their parent the way published ones do, so except (table x) and except (table only x) read back as written.
  • YAML (Publications: allSequences and except (PostgreSQL 19) #328): publications take allSequences: true and except: [schema.table, {table: schema.table, only: true}] (only with allTables). pgy pull writes them, Simulate models them, and schemas/pgy.schema.json accepts them. pgy validate rejects allSequences combined with tables/schemas, except without allTables, and a partition in except. A database-wide FOR ALL SEQUENCES publication is treated like FOR ALL TABLES for external handling and limited pulls.
  • Plans: create renders FOR ALL TABLES EXCEPT (TABLE ..., TABLE ONLY ...), ALL SEQUENCES. A change among allTables, except and allSequences emits ALTER PUBLICATION ... SET ALL .... On PostgreSQL 19, a publication of tables or schemas switches to allTables/allSequences in place: its members are dropped, then SET ALL ... runs in the same transaction, and its options stay. I checked on 19.0 that the other direction isn't possible: SET TABLE on a FOR ALL TABLES or FOR ALL SEQUENCES publication fails with "publication is defined as FOR ALL TABLES". So switching from all tables/sequences back to tables or schemas still needs --unsafe drop + create, as does any allTables switch on 15–18.
  • Older servers: versionWarnings now covers servers before PostgreSQL 19 (the guard is v >= 190000). It reports allSequences and except as needing PostgreSQL 19, so the migration would fail. pgy writes the statement as declared rather than dropping the EXCEPT, because dropping it would publish tables the YAML leaves out. The notNullName warning is now limited to servers before PostgreSQL 18, since it used to rely on the old early return.
  • Publications: emptying one that lists a table with only: true fails #335 (all versions): emptying a publication, or switching it in place, dropped a table listed with only: true using plain DROP TABLE. PostgreSQL then also tries to drop the table's inheritance children from the publication and fails with "relation ... is not part of the publication". The drop now uses DROP TABLE ONLY for those tables.
  • PostgreSQL 19: ATTACH PARTITION fails while a publication excepts the table #336 (PostgreSQL 19): PostgreSQL rejects ATTACH PARTITION while a publication's EXCEPT clause lists the table. Before attaching, the plan now takes the table out of each live EXCEPT list with SET ALL TABLES EXCEPT (...) when the YAML declares that publication with allTables and without the table in except. It warns about any other publication that excepts the table.
  • Docs: docs/schema.md (Publications section and the list of names that are quoted like SQL), docs/feature_support.md (the Publications entry) and README (limited pull) are updated.

Tests

  • Unit tests: schema parse (TestPublicationAllSequencesAndExceptParse); diff create, skip-if-same, each alter, in-place switch on 19 compared with --unsafe drop + create on 18, switching back from all tables/sequences, DROP TABLE ONLY, except before attach, and the PostgreSQL 19 version warnings; pull writes the keys and the result diffs clean; validate errors; JSON Schema fixture.
  • Integration tests:
    • TestIntegrationPublicationAllTablesExceptAndSequences and TestIntegrationPublicationExceptedTableAttached run on servers >= 19 and are skipped below.
    • A publication_pg19 pull fixture is skipped on servers below 19. It checks pull, diff clean, rebuild and the pg_dump comparison.
    • TestIntegrationPublicationEmptiedWithOnlyTable runs on every version.
  • make test and go vet ./... pass. The cli and integration packages pass against PostgreSQL 19.0, 18 and 15, with PGY_TEST_REQUIRE_PL=1 and the pg_dump oracle.

… and except, switch publications to them in place, drop ONLY tables from publications with ONLY, take a table out of EXCEPT lists before attaching it.
@archlemon
archlemon merged commit 8d0c5cc into main Nov 21, 2026
8 checks passed
@archlemon
archlemon deleted the pg19-publications branch November 21, 2026 02:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant