Re: Pgoutput not capturing the generated columns
Amit Kapila <amit.kapila16@gmail.com>
On Wed, Oct 9, 2024 at 10:19 PM Masahiko Sawada <sawada.mshk@gmail.com> wrote: > > Regarding the 0001 patch, it seems to me that UPDATE and DELETE are > allowed on the table even if its replica identity is set to generated > columns that are not published. For example, consider the following > scenario: > > create table t (a int not null, b int generated always as (a + 1) > stored not null); > create unique index t_idx on t (b); > alter table t replica identity using index t_idx; > create publication pub for table t with (publish_generated_columns = false); > insert into t values (1); > update t set a = 100 where a = 1; > > The publication pub doesn't include the generated column 'b' which is > the replica identity of the table 't'. Therefore, the update message > generated by the last UPDATE would have NULL for the column 'b'. I > think we should not allow UPDATE and DELETE on such a table. > I see the same behavior even without a patch on the HEAD. See the following example executed on HEAD: postgres=# create table t (a int not null, b int generated always as (a + 1) postgres(# stored not null); CREATE TABLE postgres=# create unique index t_idx on t (b); CREATE INDEX postgres=# alter table t replica identity using index t_idx; ALTER TABLE postgres=# create publication pub for table t; CREATE PUBLICATION postgres=# insert into t values (1); INSERT 0 1 postgres=# update t set a = 100 where a = 1; UPDATE 1 So, the update is allowed even when we don't publish generated columns, if so, why do we need to handle it in this patch when the user gave publish_generated_columns=false? Also, on the subscriber side, I see the ERROR: "publisher did not send replica identity column expected by the logical replication target relation "public.t"". Considering this, I feel if find this behavior buggy then we should fix this separately rather than part of this patch. What do you think? -- With Regards, Amit Kapila.
Commits
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Doc: Generated column replication.
- 6252b1eaf82b 18.0 landed
-
Rename pubgencols_type to pubgencols in pg_publication.
- 75eb9766ec20 18.0 landed
-
Doc: Fix column name in pg_publication catalog.
- 117f9f328e0f 18.0 landed
-
Fix buildfarm failure introduced by commit e65dbc9927.
- b35434b134b1 18.0 landed
-
Change publication's publish_generated_columns option type to enum.
- e65dbc9927fb 18.0 landed
-
Fix \dRp+ output when describing publications with a lower server version.
- 991974bb4888 18.0 landed
-
Replicate generated columns when 'publish_generated_columns' is set.
- 7054186c4ebe 18.0 landed
-
Doc: Update the behavior of generated columns in Logical Replication.
- 5b0c46ea0932 18.0 landed
-
Replicate generated columns when specified in the column list.
- 745217a051a9 18.0 landed
-
Doc: Generated columns are skipped for logical replication.
- 7a089f6e6a14 17.0 cited