Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/en_US/publication_dialog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Click the *Options* tab to continue.
Use the *Options* tab to set option properties for the publication:

* Use the *With* section to determine which DML operations will be published by the new publication to the subscribers. Move the switch next to *INSERT*, *UPDATE*, *DELETE*, or *TRUNCATE* to *No* if you do not want to replicate any of these DML operations from Publication to Subscription. By default, all the switches are set to *Yes* allowing all the DML operations.
* With PostgreSQL 18 forward, use the *Publish generated columns* field to specify whether the generated columns present in the tables associated with the publication should be replicated. Select *None* (the default) to replicate no generated columns, or *Stored* to replicate stored generated columns.


.. note:: A published table must have a “replica identity” configured in order to be able to replicate UPDATE and DELETE operations. You can change with ALTER TABLE statement. For more information on replica identity see `Logical Replication Publication <https://www.postgresql.org/docs/15/logical-replication-publication.html>`_.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ export class DefaultWithSchema extends BaseUISchema {
id: 'publish_via_partition_root', label: gettext('Publish via root?'),
type: 'switch', group: gettext('With'),
min_version: 130000,
},{
id: 'publish_generated_columns', label: gettext('Publish generated columns'),
type: 'select', group: gettext('With'),
mode: ['create','edit', 'properties'],
options: [
{label: gettext('None'), value: 'none'},
{label: gettext('Stored'), value: 'stored'},
],
controlProps: { allowClear: false },
min_version: 180000,
helpMessage: gettext('Specifies whether the stored generated columns present in the tables associated with the publication should be replicated.'),
helpMessageMode: ['edit', 'create'],
},
];
}
Expand Down Expand Up @@ -171,6 +183,7 @@ export default class PublicationSchema extends BaseUISchema {
evnt_truncate:true,
only_table: undefined,
publish_via_partition_root: false,
publish_generated_columns: 'none',
...initValues,
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{% if data.evnt_delete or data.evnt_update or data.evnt_truncate %}
{% set add_comma_after_insert = 'insert' %}
{% endif %}
{% if data.evnt_truncate %}
{% set add_comma_after_delete = 'delete' %}
{% endif %}
{% if data.evnt_delete or data.evnt_truncate%}
{% set add_comma_after_update = 'update' %}
{% endif %}
{% if data.publish_via_partition_root%}
{% set add_comma_after_truncate = 'truncate' %}
{% endif %}
{% set publish_gencols = data.publish_generated_columns == 'stored' %}
{### Create PUBLICATION ###}
CREATE PUBLICATION {{ conn|qtIdent(data.name) }}
{% if data.all_table %}
FOR ALL TABLES
{% elif data.pubtable or data.pubschema %}
FOR {% if data.pubtable %}TABLE {% if data.only_table%}ONLY {% endif %}{% for pub_table in data.pubtable %}{% if loop.index != 1 %}, {% endif %}{{pub_table['table_name']}}{% if pub_table['columns'] %} ({% for column in pub_table['columns'] %}{% if loop.index != 1 %}, {% endif %}{{column}}{% endfor %}){% endif %}{% if pub_table['where'] %} WHERE ({{pub_table['where']}}){% endif %}{% endfor %}{% endif %}{% if data.pubtable and data.pubschema %},{% endif %}
{% if data.pubschema %}
TABLES IN SCHEMA {% for pub_schema in data.pubschema %}{% if loop.index != 1 %}, {% endif %}{{ pub_schema }}{% endfor %}
{% endif %}

{% endif %}
{% if data.evnt_insert or data.evnt_update or data.evnt_delete or data.evnt_truncate %}
WITH (publish = '{% if data.evnt_insert %}insert{% if add_comma_after_insert == 'insert' %}, {% endif %}{% endif %}{% if data.evnt_update %}update{% if add_comma_after_update == 'update' %}, {% endif %}{% endif %}{% if data.evnt_delete %}delete{% if add_comma_after_delete == 'delete' %}, {% endif %}{% endif %}{% if data.evnt_truncate %}truncate{% endif %}', publish_via_partition_root = {{ data.publish_via_partition_root|lower }}{% if publish_gencols %}, publish_generated_columns = stored{% endif %});
{% elif publish_gencols %}
WITH (publish_generated_columns = stored);
{% endif %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
SELECT c.oid AS oid, c.pubname AS name,
pubinsert AS evnt_insert, pubupdate AS evnt_update, pubdelete AS evnt_delete, pubtruncate AS evnt_truncate,
puballtables AS all_table,
pubviaroot AS publish_via_partition_root,
CASE c.pubgencols WHEN 's' THEN 'stored' ELSE 'none' END AS publish_generated_columns,
pga.rolname AS pubowner FROM pg_catalog.pg_publication c
JOIN pg_catalog.pg_roles pga ON c.pubowner= pga.oid
{% if pbid %}
WHERE c.oid = {{ pbid }}
{% endif %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{% if data.evnt_delete or data.evnt_update or data.evnt_truncate %}
{% set add_comma_after_insert = 'insert' %}
{% endif %}
{% if data.evnt_truncate %}
{% set add_comma_after_delete = 'delete' %}
{% endif %}
{% if data.evnt_delete or data.evnt_truncate%}
{% set add_comma_after_update = 'update' %}
{% endif %}
{### Alter publication owner ###}
{% if data.pubowner %}
ALTER PUBLICATION {{ conn|qtIdent(o_data.name) }}
OWNER TO {{ conn|qtIdent(data.pubowner) }};

{% endif %}
{### Alter publication event ###}
{% if (data.evnt_insert is defined and data.evnt_insert != o_data.evnt_insert) or (data.evnt_update is defined and data.evnt_update != o_data.evnt_update) or (data.evnt_delete is defined and data.evnt_delete != o_data.evnt_delete) or (data.evnt_truncate is defined and data.evnt_truncate != o_data.evnt_truncate) %}
ALTER PUBLICATION {{ conn|qtIdent(o_data.name) }} SET
(publish = '{% if data.evnt_insert %}insert{% if add_comma_after_insert == 'insert' %}, {% endif %}{% endif %}{% if data.evnt_update %}update{% if add_comma_after_update == 'update' %}, {% endif %}{% endif %}{% if data.evnt_delete %}delete{% if add_comma_after_delete == 'delete' %}, {% endif %}{% endif %}{% if data.evnt_truncate %}truncate{% endif %}');

{% endif %}
{### Alter publication partition root ###}
{% if data.publish_via_partition_root is defined and data.publish_via_partition_root != o_data.publish_via_partition_root%}
ALTER PUBLICATION {{ conn|qtIdent(o_data.name) }} SET
(publish_via_partition_root = {{ data.publish_via_partition_root|lower }});

{% endif %}
{### Alter publication generated columns ###}
{% if data.publish_generated_columns in ['none', 'stored'] and data.publish_generated_columns != o_data.publish_generated_columns %}
ALTER PUBLICATION {{ conn|qtIdent(o_data.name) }} SET
(publish_generated_columns = {{ data.publish_generated_columns }});

{% endif %}
{### Alter drop publication table ###}
{% if drop_table %}
ALTER PUBLICATION {{ conn|qtIdent(o_data.name) }}
DROP TABLE {% if data.only_table%}ONLY {% endif %}{% for pub_table in drop_table_data %}{% if loop.index != 1 %}, {% endif %}{{ pub_table['table_name'] or pub_table }}{% endfor %};

{% endif %}

{### Alter drop publication schema ###}
{% if drop_schema %}
ALTER PUBLICATION {{ conn|qtIdent(o_data.name) }}
DROP TABLES IN SCHEMA {% for pub_schema in drop_schema_data %}{% if loop.index != 1 %}, {% endif %}{{ pub_schema }}{% endfor %};

{% endif %}

{### Alter update publication table ###}
{% if update_table %}
ALTER PUBLICATION {{ conn|qtIdent(o_data.name) }}
SET TABLE {% for pub_table in update_table_data %}{% if loop.index != 1 %}, TABLE {% endif %}{{ pub_table['table_name'] or pub_table }}{% if pub_table['columns'] %} ({% for column in pub_table['columns'] %}{% if loop.index != 1 %}, {% endif %}{{ column }}{% endfor %}){% endif %}{% if pub_table['where'] %} WHERE ({{pub_table['where']}}){% endif %}{% endfor %};

{% endif %}

{### Alter publication table ###}
{% if add_table %}
ALTER PUBLICATION {{ conn|qtIdent(o_data.name) }}
ADD TABLE {% if data.only_table%}ONLY {% endif %}{% for pub_table in add_table_data %}{% if loop.index != 1 %}, {% endif %}{{ pub_table['table_name'] or pub_table }}{% if pub_table['columns'] %} ({% for column in pub_table['columns'] %}{% if loop.index != 1 %}, {% endif %}{{ column }}{% endfor %}){% endif %}{% if pub_table['where'] %} WHERE ({{pub_table['where']}}){% endif %}{% endfor %};

{% endif %}

{### Alter add publication schema ###}
{% if add_schema %}
ALTER PUBLICATION {{ conn|qtIdent(o_data.name) }}
ADD TABLES IN SCHEMA {% for pub_schema in add_schema_data %}{% if loop.index != 1 %}, {% endif %}{{ pub_schema }}{% endfor %};

{% endif %}

{### Alter publication name ###}
{% if data.name != o_data.name %}
ALTER PUBLICATION {{ conn|qtIdent(o_data.name) }}
RENAME TO {{ conn|qtIdent(data.name) }};
{% endif %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{% if data.evnt_delete or data.evnt_update or data.evnt_truncate %}
{% set add_comma_after_insert = 'insert' %}
{% endif %}
{% if data.evnt_truncate %}
{% set add_comma_after_delete = 'delete' %}
{% endif %}
{% if data.evnt_delete or data.evnt_truncate%}
{% set add_comma_after_update = 'update' %}
{% endif %}
{% if data.publish_via_partition_root%}
{% set add_comma_after_truncate = 'truncate' %}
{% endif %}
{% set publish_gencols = data.publish_generated_columns == 'stored' %}
{### Create PUBLICATION ###}
CREATE PUBLICATION {{ conn|qtIdent(data.name) }}
{% if data.all_table %}
FOR ALL TABLES
{% elif data.pubtable or data.pubschema %}
FOR {% if data.pubtable %}TABLE {% if data.only_table%}ONLY {% endif %}{% for pub_table in data.pubtable %}{% if loop.index != 1 %}, {% endif %}{{pub_table['table_name']}}{% if pub_table['columns'] %} ({% for column in pub_table['columns'] %}{% if loop.index != 1 %}, {% endif %}{{column}}{% endfor %}){% endif %}{% if pub_table['where'] %} WHERE ({{pub_table['where']}}){% endif %}{% endfor %}{% endif %}{% if data.pubtable and data.pubschema %},{% endif %}
{% if data.pubschema %}
TABLES IN SCHEMA {% for pub_schema in data.pubschema %}{% if loop.index != 1 %}, {% endif %}{{ pub_schema }}{% endfor %}
{% endif %}

{% endif %}
{% if data.evnt_insert or data.evnt_update or data.evnt_delete or data.evnt_truncate %}
WITH (publish = '{% if data.evnt_insert %}insert{% if add_comma_after_insert == 'insert' %}, {% endif %}{% endif %}{% if data.evnt_update %}update{% if add_comma_after_update == 'update' %}, {% endif %}{% endif %}{% if data.evnt_delete %}delete{% if add_comma_after_delete == 'delete' %}, {% endif %}{% endif %}{% if data.evnt_truncate %}truncate{% endif %}', publish_via_partition_root = {{ data.publish_via_partition_root|lower }}{% if publish_gencols %}, publish_generated_columns = stored{% endif %});
{% elif publish_gencols %}
WITH (publish_generated_columns = stored);
{% endif %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
SELECT c.oid AS oid, c.pubname AS name,
pubinsert AS evnt_insert, pubupdate AS evnt_update, pubdelete AS evnt_delete, pubtruncate AS evnt_truncate,
puballtables AS all_table,
pubviaroot AS publish_via_partition_root,
CASE c.pubgencols WHEN 's' THEN 'stored' ELSE 'none' END AS publish_generated_columns,
pga.rolname AS pubowner FROM pg_catalog.pg_publication c
JOIN pg_catalog.pg_roles pga ON c.pubowner= pga.oid
{% if pbid %}
WHERE c.oid = {{ pbid }}
{% endif %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{% if data.evnt_delete or data.evnt_update or data.evnt_truncate %}
{% set add_comma_after_insert = 'insert' %}
{% endif %}
{% if data.evnt_truncate %}
{% set add_comma_after_delete = 'delete' %}
{% endif %}
{% if data.evnt_delete or data.evnt_truncate%}
{% set add_comma_after_update = 'update' %}
{% endif %}
{### Alter publication owner ###}
{% if data.pubowner %}
ALTER PUBLICATION {{ conn|qtIdent(o_data.name) }}
OWNER TO {{ conn|qtIdent(data.pubowner) }};

{% endif %}
{### Alter publication event ###}
{% if (data.evnt_insert is defined and data.evnt_insert != o_data.evnt_insert) or (data.evnt_update is defined and data.evnt_update != o_data.evnt_update) or (data.evnt_delete is defined and data.evnt_delete != o_data.evnt_delete) or (data.evnt_truncate is defined and data.evnt_truncate != o_data.evnt_truncate) %}
ALTER PUBLICATION {{ conn|qtIdent(o_data.name) }} SET
(publish = '{% if data.evnt_insert %}insert{% if add_comma_after_insert == 'insert' %}, {% endif %}{% endif %}{% if data.evnt_update %}update{% if add_comma_after_update == 'update' %}, {% endif %}{% endif %}{% if data.evnt_delete %}delete{% if add_comma_after_delete == 'delete' %}, {% endif %}{% endif %}{% if data.evnt_truncate %}truncate{% endif %}');

{% endif %}
{### Alter publication partition root ###}
{% if data.publish_via_partition_root is defined and data.publish_via_partition_root != o_data.publish_via_partition_root%}
ALTER PUBLICATION {{ conn|qtIdent(o_data.name) }} SET
(publish_via_partition_root = {{ data.publish_via_partition_root|lower }});

{% endif %}
{### Alter publication generated columns ###}
{% if data.publish_generated_columns in ['none', 'stored'] and data.publish_generated_columns != o_data.publish_generated_columns %}
ALTER PUBLICATION {{ conn|qtIdent(o_data.name) }} SET
(publish_generated_columns = {{ data.publish_generated_columns }});

{% endif %}
{### Alter drop publication table ###}
{% if drop_table %}
ALTER PUBLICATION {{ conn|qtIdent(o_data.name) }}
DROP TABLE {% if data.only_table%}ONLY {% endif %}{% for pub_table in drop_table_data %}{% if loop.index != 1 %}, {% endif %}{{ pub_table['table_name'] or pub_table }}{% endfor %};

{% endif %}

{### Alter drop publication schema ###}
{% if drop_schema %}
ALTER PUBLICATION {{ conn|qtIdent(o_data.name) }}
DROP TABLES IN SCHEMA {% for pub_schema in drop_schema_data %}{% if loop.index != 1 %}, {% endif %}{{ pub_schema }}{% endfor %};

{% endif %}

{### Alter update publication table ###}
{% if update_table %}
ALTER PUBLICATION {{ conn|qtIdent(o_data.name) }}
SET TABLE {% for pub_table in update_table_data %}{% if loop.index != 1 %}, TABLE {% endif %}{{ pub_table['table_name'] or pub_table }}{% if pub_table['columns'] %} ({% for column in pub_table['columns'] %}{% if loop.index != 1 %}, {% endif %}{{ column }}{% endfor %}){% endif %}{% if pub_table['where'] %} WHERE ({{pub_table['where']}}){% endif %}{% endfor %};

{% endif %}

{### Alter publication table ###}
{% if add_table %}
ALTER PUBLICATION {{ conn|qtIdent(o_data.name) }}
ADD TABLE {% if data.only_table%}ONLY {% endif %}{% for pub_table in add_table_data %}{% if loop.index != 1 %}, {% endif %}{{ pub_table['table_name'] or pub_table }}{% if pub_table['columns'] %} ({% for column in pub_table['columns'] %}{% if loop.index != 1 %}, {% endif %}{{ column }}{% endfor %}){% endif %}{% if pub_table['where'] %} WHERE ({{pub_table['where']}}){% endif %}{% endfor %};

{% endif %}

{### Alter add publication schema ###}
{% if add_schema %}
ALTER PUBLICATION {{ conn|qtIdent(o_data.name) }}
ADD TABLES IN SCHEMA {% for pub_schema in add_schema_data %}{% if loop.index != 1 %}, {% endif %}{{ pub_schema }}{% endfor %};

{% endif %}

{### Alter publication name ###}
{% if data.name != o_data.name %}
ALTER PUBLICATION {{ conn|qtIdent(o_data.name) }}
RENAME TO {{ conn|qtIdent(data.name) }};
{% endif %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Publication: test_publication_create

-- DROP PUBLICATION IF EXISTS test_publication_create;

CREATE PUBLICATION test_publication_create
FOR TABLE public.test_table_publication
WITH (publish = 'insert, update, delete, truncate', publish_via_partition_root = false);
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER PUBLICATION test_publication_create SET
(publish_generated_columns = none);
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Publication: test_publication_create

-- DROP PUBLICATION IF EXISTS test_publication_create;

CREATE PUBLICATION test_publication_create
FOR TABLE public.test_table_publication
WITH (publish = 'insert, update, delete, truncate', publish_via_partition_root = false, publish_generated_columns = stored);
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER PUBLICATION test_publication_create SET
(publish_generated_columns = stored);
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Publication: test_publication_create

-- DROP PUBLICATION IF EXISTS test_publication_create;

CREATE PUBLICATION test_publication_create
FOR TABLE public.test_table_publication
WITH (publish = 'insert, update, delete, truncate', publish_via_partition_root = false, publish_generated_columns = stored);
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CREATE PUBLICATION test_publication_create
FOR TABLE public.test_table_publication
WITH (publish = 'insert, update, delete, truncate', publish_via_partition_root = false, publish_generated_columns = stored);
Loading
Loading