Re: Support logical replication of DDLs, take2 - Mailing list pgsql-hackers

From Hannu Krosing
Subject Re: Support logical replication of DDLs, take2
Date
Msg-id CAMT0RQThNce3+0MEzbqNWov7uZZQbiyFrhrod3g+MeKoAqjRbw@mail.gmail.com
Whole thread
In response to Re: Support logical replication of DDLs, take2  (Dilip Kumar <dilipbalaut@gmail.com>)
Responses Re: Support logical replication of DDLs, take2
Re: Support logical replication of DDLs, take2
List pgsql-hackers
On Wed, Apr 29, 2026 at 5:39 AM Dilip Kumar <dilipbalaut@gmail.com> wrote:

> I am trying to understand your idea. If we are trying to deparse from
> an actual system table using a snapshot, why don't we just use the
> WAL? I mean, the WAL should contain the actual catalog modifications
> it has made.

We have the full data in the catalog and we would likely need catalog
queries for any change, even when de-parsing the tree.

And we should not add the extra load on the original DDL side, just as
we don't for DML.

At most we could just serialize the statement tree into the WAL,
though even that may be an overkill if we can get the change from
existing records.

- insert new row in pg_class --> extract the CREATE TABLE (or INDEX, or ...)
- update row in pg_class or insert, update or delete a row in
pg_attribute --> extract ALTER TABLE
  - except when it just updates relfilenod --> extract TRUNCATE
- delete row in pg_class --> DROP TABLE
- dml on pg_constraint --> ALTER TABLE

... etc

> Although converting the catalog changes into a deparse
> representation of the DDL could be complex no?

Both de-parsing the tree and converting the catalog change could be complex.
The advantage of using the catalog is that we already have decades of
experience doing this via pg_dump.

> Another question is
> what we would do with those deparsed representations: will we convert
> them to SQL on the subscriber and execute, or do something else?

Current pg_dump approach is logically equivalent to "doing it on the
subscriber", pg_dump is designed to dump schemas from all older
database versions in format that is compatible with the version the
pg_dump is written for.

This brings us back to the uncomfortable discussion of needing to
back-port some changes to older versions contrary to general
PostgreSQL development principles of adding new features to only the
latest version.

Or we could enable exporting the catalog snapshot from logical
replication stream so that subscriber could use that snapshot in a
"callback connection: to extract the catalog state at that snapshot



pgsql-hackers by date:

Previous
From: John Naylor
Date:
Subject: Re: Inherit regression outputs rows in alternative ordering when run on other table AM than heap
Next
From: "Hayato Kuroda (Fujitsu)"
Date:
Subject: RE: [PATCH] Preserve replication origin OIDs in pg_upgrade