2 29.6. Generated Column Replication #
4 Typically, a table at the subscriber will be defined the same as the
5 publisher table, so if the publisher table has a GENERATED column then
6 the subscriber table will have a matching generated column. In this
7 case, it is always the subscriber table generated column value that is
10 For example, note below that subscriber table generated column value
11 comes from the subscriber column's calculation.
12 /* pub # */ CREATE TABLE tab_gen_to_gen (a int, b int GENERATED ALWAYS AS (a + 1
14 /* pub # */ INSERT INTO tab_gen_to_gen VALUES (1),(2),(3);
15 /* pub # */ CREATE PUBLICATION pub1 FOR TABLE tab_gen_to_gen;
16 /* pub # */ SELECT * FROM tab_gen_to_gen;
24 /* sub # */ CREATE TABLE tab_gen_to_gen (a int, b int GENERATED ALWAYS AS (a * 1
26 /* sub # */ CREATE SUBSCRIPTION sub1 CONNECTION 'dbname=test_pub' PUBLICATION pu
28 /* sub # */ SELECT * from tab_gen_to_gen;
36 In fact, prior to version 18.0, logical replication does not publish
37 GENERATED columns at all.
39 But, replicating a generated column to a regular column can sometimes
44 This feature may be useful when replicating data to a non-PostgreSQL
45 database via output plugin, especially if the target database does not
46 support generated columns.
48 Generated columns are not published by default, but users can opt to
49 publish stored generated columns just like regular ones.
51 There are two ways to do this:
52 * Set the PUBLICATION parameter publish_generated_columns to stored.
53 This instructs PostgreSQL logical replication to publish current
54 and future stored generated columns of the publication's tables.
55 * Specify a table column list to explicitly nominate which stored
56 generated columns will be published.
59 When determining which table columns will be published, a column
60 list takes precedence, overriding the effect of the
61 publish_generated_columns parameter.
63 The following table summarizes behavior when there are generated
64 columns involved in the logical replication. Results are shown for when
65 publishing generated columns is not enabled, and for when it is
68 Table 29.2. Replication Result Summary
69 Publish generated columns? Publisher table column Subscriber table
71 No GENERATED GENERATED Publisher table column is not replicated. Use
72 the subscriber table generated column value.
73 No GENERATED regular Publisher table column is not replicated. Use the
74 subscriber table regular column default value.
75 No GENERATED --missing-- Publisher table column is not replicated.
77 Yes GENERATED GENERATED ERROR. Not supported.
78 Yes GENERATED regular Publisher table column value is replicated to the
79 subscriber table column.
80 Yes GENERATED --missing-- ERROR. The column is reported as missing from
85 There's currently no support for subscriptions comprising several
86 publications where the same table has been published with different
87 column lists. See Section 29.5.
89 This same situation can occur if one publication is publishing
90 generated columns, while another publication in the same subscription
91 is not publishing generated columns for the same table.
95 If the subscriber is from a release prior to 18, then initial table
96 synchronization won't copy generated columns even if they are defined