diff --git a/doc/src/sgml/ref/alter_publication.sgmlin b/doc/src/sgml/ref/alter_publication.sgmlin new file mode 100644 index 000000000..0e3345fcc --- /dev/null +++ b/doc/src/sgml/ref/alter_publication.sgmlin @@ -0,0 +1,150 @@ + + + + + ALTER PUBLICATION + + + + ALTER PUBLICATION + 7 + SQL - Language Statements + + + + ALTER PUBLICATION + change the definition of a publication + + + + +ALTER PUBLICATION name ADD TABLE table_name [, ...] +ALTER PUBLICATION name SET TABLE table_name [, ...] +ALTER PUBLICATION name DROP TABLE table_name [, ...] +ALTER PUBLICATION name SET ( publication_parameter [= value] [, ... ] ) +ALTER PUBLICATION name OWNER TO new_owner +ALTER PUBLICATION name RENAME TO new_name + + + + + Description + + + The command ALTER PUBLICATION can change the attributes + of a publication. + + + + The first three variants change which tables are part of the publication. + The SET TABLE clause will replace the list of tables in + the publication with the specified one. The ADD TABLE + and DROP TABLE clauses will add and remove one or more + tables from the publication. + + + + The fourth variant of this command listed in the synopsis can change + all of the publication properties specified in + . Properties not mentioned in the + command retain their previous settings. + + + + The remaining variants change the owner and the name of the publication. + + + + You must own the publication to use ALTER PUBLICATION. + Adding a table to a publication additionally requires owning that table. + To alter the owner, you must also be a direct or indirect member of the new + owning role. The new owner must have CREATE privilege on + the database. Also, the new owner of a FOR ALL TABLES + publication must be a superuser. However, a superuser can change the + ownership of a publication regardless of these restrictions. + + + + + Parameters + + + + name + + + The name of an existing publication whose definition is to be altered. + + + + + + SET ( publication_parameter [= value] [, ... ] ) + + + This clause alters publication parameters originally set by + . See there for more information. + + + + + + new_owner + + + The user name of the new owner of the publication. + + + + + + new_name + + + The new name for the publication. + + + + + + + + Examples + + + Change the publication to publish only deletes and updates: + +ALTER PUBLICATION noinsert SET (publish = 'update, delete'); + + + + + Add some tables to the publication: + +ALTER PUBLICATION mypublication ADD TABLE users, departments; + + + + + Compatibility + + + ALTER PUBLICATION is a PostgreSQL + extension. + + + + + See Also + + + + + + + + + diff --git a/doc/src/sgml/ref/alter_subscription.sgmlin b/doc/src/sgml/ref/alter_subscription.sgmlin new file mode 100644 index 000000000..d1f2dc501 --- /dev/null +++ b/doc/src/sgml/ref/alter_subscription.sgmlin @@ -0,0 +1,141 @@ + + + + + ALTER SUBSCRIPTION + + + + ALTER SUBSCRIPTION + 7 + SQL - Language Statements + + + + ALTER SUBSCRIPTION + change the definition of a subscription + + + + +ALTER SUBSCRIPTION name CONNECTION 'conninfo' +ALTER SUBSCRIPTION name SET PUBLICATION publication_name [, ...] +ALTER SUBSCRIPTION name ENABLE +ALTER SUBSCRIPTION name SET ( subscription_parameter [= value] [, ... ] ) +ALTER SUBSCRIPTION name OWNER TO new_owner +ALTER SUBSCRIPTION name RENAME TO new_name + + + + + Description + + + ALTER SUBSCRIPTION can change most of the subscription + properties that can be specified + in . + + + + You must own the subscription to use ALTER SUBSCRIPTION. + To alter the owner, you must also be a direct or indirect member of the + new owning role. The new owner has to be a superuser. + (Currently, all subscription owners must be superusers, so the owner checks + will be bypassed in practice. But this might change in the future.) + + + + + Parameters + + + + name + + + The name of a subscription whose properties are to be altered. + + + + + + CONNECTION 'conninfo' + + + This clause alters the connection property originally set by + . See there for more + information. + + + + + + SET PUBLICATION publication_name + + + + ENABLE + + + Enables the previously disabled subscription, starting the logical + replication worker at the end of transaction. + + + + + + SET ( subscription_parameter [= value] [, ... ] ) + + + This clause alters parameters originally set by + . See there for more + information. The parameters that can be altered + are slot_name and + synchronous_commit + + + + + + new_owner + + + The user name of the new owner of the subscription. + + + + + + new_name + + + The new name for the subscription. + + + + + + + + Compatibility + + + ALTER SUBSCRIPTION is a PostgreSQL + extension. + + + + + See Also + + + + + + + + + diff --git a/doc/src/sgml/ref/create_publication.sgmlin b/doc/src/sgml/ref/create_publication.sgmlin new file mode 100644 index 000000000..6da14c495 --- /dev/null +++ b/doc/src/sgml/ref/create_publication.sgmlin @@ -0,0 +1,220 @@ + + + + + CREATE PUBLICATION + + + + CREATE PUBLICATION + 7 + SQL - Language Statements + + + + CREATE PUBLICATION + define a new publication + + + + +CREATE PUBLICATION name + [ FOR TABLE table_name [, ...] + | FOR ALL TABLES ] + [ WITH ( publication_parameter [= value] [, ... ] ) ] + + + + + Description + + + CREATE PUBLICATION adds a new publication + into the current database. The publication name must be distinct from + the name of any existing publication in the current database. + + + + A publication is essentially a group of tables whose data changes are + intended to be replicated through logical replication. See + for details about how + publications fit into the logical replication setup. + + + + + Parameters + + + + name + + + The name of the new publication. + + + + + + FOR TABLE + + + Specifies a list of tables to add to the publication. + + + Only persistent base tables and partitioned tables can be part of a + publication. Temporary tables, unlogged tables, foreign tables, + materialized views, and regular views cannot be part of a publication. + + + + + + + FOR ALL TABLES + + + Marks the publication as one that replicates changes for all tables in + the database, including tables created in the future. + + + + + + WITH ( publication_parameter [= value] [, ... ] ) + + + This clause specifies optional parameters for a publication. The + following parameters are supported: + + + + publish (string) + + + This parameter determines which DML operations will be published by + the new publication to the subscribers. The value is + comma-separated list of operations. The allowed operations are + insert, update and + delete. + The default is to publish all actions, + and so the default value for this option is + 'insert, update, delete'. + + + + + + PUBLISH DELETE + NOPUBLISH DELETE + + + These clauses determine whether the new publication will send + the DELETE operations to the subscribers. + PUBLISH DELETE is the default. + + + + + + + + + Notes + + + If neither FOR TABLE nor FOR ALL + TABLES is specified, then the publication starts out with an + empty set of tables. That is useful if tables are to be added later. + + + + The creation of a publication does not start replication. It only defines + a grouping and filtering logic for future subscribers. + + + + To create a publication, the invoking user must have the + CREATE privilege for the current database. + (Of course, superusers bypass this check.) + + + + To add a table to a publication, the invoking user must have ownership + rights on the table. The FOR ALL TABLES clause requires + the invoking user to be a superuser. + + + + The tables added to a publication that publishes UPDATE + and/or DELETE operations must have + REPLICA IDENTITY defined. Otherwise those operations will be + disallowed on those tables. + + + + For an INSERT ... ON CONFLICT command, the publication will + publish the operation that actually results from the command. So depending + of the outcome, it may be published as either INSERT or + UPDATE, or it may not be published at all. + + + + COPY ... FROM commands are published + as INSERT operations. + + + + DDL operations are not published. + + + + + Examples + + + Create a publication that publishes all changes in two tables: + +CREATE PUBLICATION mypublication FOR TABLE users, departments; + + + + + Create a publication that publishes all changes in all tables: + +CREATE PUBLICATION alltables FOR ALL TABLES; + + + + + Create a publication that only publishes INSERT + operations in one table: + +CREATE PUBLICATION insert_only FOR TABLE mydata + WITH (publish = 'insert'); + + + + + Compatibility + + + CREATE PUBLICATION is a PostgreSQL + extension. + + + + + See Also + + + + + + + + + diff --git a/doc/src/sgml/ref/create_subscription.sgmlin b/doc/src/sgml/ref/create_subscription.sgmlin new file mode 100644 index 000000000..f1be6ed08 --- /dev/null +++ b/doc/src/sgml/ref/create_subscription.sgmlin @@ -0,0 +1,236 @@ + + + + + CREATE SUBSCRIPTION + + + + CREATE SUBSCRIPTION + 7 + SQL - Language Statements + + + + CREATE SUBSCRIPTION + define a new subscription + + + + +CREATE SUBSCRIPTION subscription_name + CONNECTION 'conninfo' + PUBLICATION publication_name [, ...] + [ WITH ( subscription_parameter [= value] [, ... ] ) ] + + + + + Description + + + CREATE SUBSCRIPTION adds a new subscription for the + current database. The subscription name must be distinct from the name of + any existing subscription in the database. + + + + The subscription represents a replication connection to the publisher. As + such this command does not only add definitions in the local catalogs but + also creates a replication slot on the publisher. + + + + A logical replication worker will be started to replicate data for the new + subscription at the commit of the transaction where this command is run. + + + + Additional information about subscriptions and logical replication as a + whole is available at and + . + + + + + + Parameters + + + + subscription_name + + + The name of the new subscription. + + + + + + CONNECTION 'conninfo' + + + The connection string to the publisher. For details + see . + + + + + + PUBLICATION publication_name + + + Names of the publications on the publisher to subscribe to. + + + + + + WITH ( subscription_parameter [= value] [, ... ] ) + + + This clause specifies optional parameters for a subscription. The + following parameters are supported: + + + + enabled (boolean) + + + Specifies whether the subscription should be actively replicating, + or whether it should be just setup but not started yet. The default + is true. + + + + + + slot_name (string) + + + Name of the replication slot to use. The default behavior is to + use the name of the subscription for the slot name. + + + + When slot_name is set to + NONE, there will be no replication slot + associated with the subscription. This can be used if the + replication slot will be created later manually. Such + subscriptions must also have both enabled and + create_slot set to false. + + + + + + synchronous_commit (enum) + + + The value of this parameter overrides the + setting within this + subscription's apply worker processes. The default value + is off. + + + + It is safe to use off for logical replication: + If the subscriber loses transactions because of missing + synchronization, the data will be sent again from the publisher. + + + + A different setting might be appropriate when doing synchronous + logical replication. The logical replication workers report the + positions of writes and flushes to the publisher, and when using + synchronous replication, the publisher will wait for the actual + flush. This means that setting + synchronous_commit for the subscriber to + off when the subscription is used for + synchronous replication might increase the latency for + COMMIT on the publisher. In this scenario, it + can be advantageous to set synchronous_commit + to local or higher. + + + + + + + + + + + Notes + + + See for details on + how to configure access control between the subscription and the + publication instance. + + + + When creating a replication slot (the default behavior), CREATE + SUBSCRIPTION cannot be executed inside a transaction block. + + + + Creating a subscription that connects to the same database cluster (for + example, to replicate between databases in the same cluster or to replicate + within the same database) will only succeed if the replication slot is not + created as part of the same command. Otherwise, the CREATE + SUBSCRIPTION call will hang. This is an + implementation restriction that might be lifted in a future release. + + + + + Examples + + + Create a subscription to a remote server that replicates tables in + the publications mypublication and + insert_only and starts replicating immediately on + commit: + +CREATE SUBSCRIPTION mysub + CONNECTION 'host=192.168.1.50 port=5432 user=foo dbname=foodb' + PUBLICATION mypublication, insert_only; + + + + + Create a subscription to a remote server that replicates tables in + the insert_only publication and does not start replicating + until enabled at a later time. + +CREATE SUBSCRIPTION mysub + CONNECTION 'host=192.168.1.50 port=5432 user=foo dbname=foodb' + PUBLICATION insert_only + WITH (enabled = false); + + + + + Compatibility + + + CREATE SUBSCRIPTION is a PostgreSQL + extension. + + + + + See Also + + + + + + + + + diff --git a/doc/src/sgml/ref/drop_publication.sgmlin b/doc/src/sgml/ref/drop_publication.sgmlin new file mode 100644 index 000000000..2dcc1da4a --- /dev/null +++ b/doc/src/sgml/ref/drop_publication.sgmlin @@ -0,0 +1,105 @@ + + + + + DROP PUBLICATION + + + + DROP PUBLICATION + 7 + SQL - Language Statements + + + + DROP PUBLICATION + remove a publication + + + + +DROP PUBLICATION [ IF EXISTS ] name [, ...] [ CASCADE | RESTRICT ] + + + + + Description + + + DROP PUBLICATION removes an existing publication from + the database. + + + + A publication can only be dropped by its owner or a superuser. + + + + + Parameters + + + + IF EXISTS + + + Do not throw an error if the publication does not exist. A notice is + issued in this case. + + + + + + name + + + The name of an existing publication. + + + + + + CASCADE + RESTRICT + + + + These key words do not have any effect, since there are no dependencies + on publications. + + + + + + + + Examples + + + Drop a publication: + +DROP PUBLICATION mypublication; + + + + + Compatibility + + + DROP PUBLICATION is a PostgreSQL + extension. + + + + + See Also + + + + + + + diff --git a/doc/src/sgml/ref/drop_subscription.sgmlin b/doc/src/sgml/ref/drop_subscription.sgmlin new file mode 100644 index 000000000..c51c4f6af --- /dev/null +++ b/doc/src/sgml/ref/drop_subscription.sgmlin @@ -0,0 +1,101 @@ + + + + + DROP SUBSCRIPTION + + + + DROP SUBSCRIPTION + 7 + SQL - Language Statements + + + + DROP SUBSCRIPTION + remove a subscription + + + + +DROP SUBSCRIPTION [ IF EXISTS ] name [ CASCADE | RESTRICT ] + + + + + Description + + + DROP SUBSCRIPTION removes a subscription from the + database cluster. + + + + A subscription can only be dropped by a superuser. + + + + The replication worker associated with the subscription will not stop until + after the transaction that issued this command has committed. + + + + + Parameters + + + + name + + + The name of a subscription to be dropped. + + + + + + CASCADE + RESTRICT + + + + These key words do not have any effect, since there are no dependencies + on subscriptions. + + + + + + + + + Examples + + + Drop a subscription: + +DROP SUBSCRIPTION mysub; + + + + + Compatibility + + + DROP SUBSCRIPTION is a PostgreSQL + extension. + + + + + See Also + + + + + + + diff --git a/src/test/regress/input/single_node_user_mapping.source b/src/test/regress/input/single_node_user_mapping.source index 8d23e37b2..bcde6742e 100644 --- a/src/test/regress/input/single_node_user_mapping.source +++ b/src/test/regress/input/single_node_user_mapping.source @@ -1,9 +1,9 @@ --clear audit log SELECT pg_delete_audit('1012-11-10', '3012-11-11'); --- prepare -\! echo $GAUSSHOME | sed 's/^.*tmp_check\/install\///g' | xargs -I{} rm -f {}/bin/usermapping.key.cipher -\! echo $GAUSSHOME | sed 's/^.*tmp_check\/install\///g' | xargs -I{} rm -f {}/bin/usermapping.key.rand -\! echo $GAUSSHOME | sed 's/^.*tmp_check\/install\///g' | xargs -I{} @abs_bindir@/gs_guc generate -S 123456@pwd -D {}/bin -o usermapping > /dev/null 2>&1 ; echo $? +\! echo $OLDGAUSSHOME | xargs -I{} rm -f {}/bin/usermapping.key.cipher +\! echo $OLDGAUSSHOME | xargs -I{} rm -f {}/bin/usermapping.key.rand +\! echo $OLDGAUSSHOME | xargs -I{} @abs_bindir@/gs_guc generate -S 123456@pwd -D {}/bin -o usermapping > /dev/null 2>&1 ; echo $? CREATE ROLE regress_usermapping_user LOGIN SYSADMIN PASSWORD 'Abcdef@123'; SET SESSION AUTHORIZATION 'regress_usermapping_user' PASSWORD 'Abcdef@123'; diff --git a/src/test/regress/input/subscription.source b/src/test/regress/input/subscription.source index a7ab85070..ff384b618 100644 --- a/src/test/regress/input/subscription.source +++ b/src/test/regress/input/subscription.source @@ -10,9 +10,9 @@ SELECT pg_delete_audit('1012-11-10', '3012-11-11'); --enable publication and subscription audit \! @abs_bindir@/gs_guc reload -D @abs_srcdir@/tmp_check/datanode1/ -c "audit_system_object=16777215" > /dev/null 2>&1 --- prepare -\! echo $GAUSSHOME | sed 's/^.*tmp_check\/install\///g' | xargs -I{} rm -f {}/bin/subscription.key.cipher -\! echo $GAUSSHOME | sed 's/^.*tmp_check\/install\///g' | xargs -I{} rm -f {}/bin/subscription.key.rand -\! echo $GAUSSHOME | sed 's/^.*tmp_check\/install\///g' | xargs -I{} @abs_bindir@/gs_guc generate -S 123456@pwd -D {}/bin -o subscription > /dev/null 2>&1 ; echo $? +\! echo $OLDGAUSSHOME | xargs -I{} rm -f {}/bin/subscription.key.cipher +\! echo $OLDGAUSSHOME | xargs -I{} rm -f {}/bin/subscription.key.rand +\! echo $OLDGAUSSHOME | xargs -I{} @abs_bindir@/gs_guc generate -S 123456@pwd -D {}/bin -o subscription > /dev/null 2>&1 ; echo $? CREATE ROLE regress_subscription_user LOGIN SYSADMIN PASSWORD 'Abcdef@123'; CREATE ROLE regress_subscription_user2 LOGIN SYSADMIN PASSWORD 'Abcdef@123'; SET SESSION AUTHORIZATION 'regress_subscription_user' PASSWORD 'Abcdef@123'; diff --git a/src/test/regress/output/single_node_user_mapping.source b/src/test/regress/output/single_node_user_mapping.source index 32315f2da..0c22ab74f 100644 --- a/src/test/regress/output/single_node_user_mapping.source +++ b/src/test/regress/output/single_node_user_mapping.source @@ -6,9 +6,9 @@ SELECT pg_delete_audit('1012-11-10', '3012-11-11'); (1 row) --- prepare -\! echo $GAUSSHOME | sed 's/^.*tmp_check\/install\///g' | xargs -I{} rm -f {}/bin/usermapping.key.cipher -\! echo $GAUSSHOME | sed 's/^.*tmp_check\/install\///g' | xargs -I{} rm -f {}/bin/usermapping.key.rand -\! echo $GAUSSHOME | sed 's/^.*tmp_check\/install\///g' | xargs -I{} @abs_bindir@/gs_guc generate -S 123456@pwd -D {}/bin -o usermapping > /dev/null 2>&1 ; echo $? +\! echo $OLDGAUSSHOME | xargs -I{} rm -f {}/bin/usermapping.key.cipher +\! echo $OLDGAUSSHOME | xargs -I{} rm -f {}/bin/usermapping.key.rand +\! echo $OLDGAUSSHOME | xargs -I{} @abs_bindir@/gs_guc generate -S 123456@pwd -D {}/bin -o usermapping > /dev/null 2>&1 ; echo $? 0 CREATE ROLE regress_usermapping_user LOGIN SYSADMIN PASSWORD 'Abcdef@123'; SET SESSION AUTHORIZATION 'regress_usermapping_user' PASSWORD 'Abcdef@123'; diff --git a/src/test/regress/output/subscription.source b/src/test/regress/output/subscription.source index c0bce67d3..d2317de8f 100644 --- a/src/test/regress/output/subscription.source +++ b/src/test/regress/output/subscription.source @@ -38,9 +38,9 @@ SELECT pg_delete_audit('1012-11-10', '3012-11-11'); --enable publication and subscription audit \! @abs_bindir@/gs_guc reload -D @abs_srcdir@/tmp_check/datanode1/ -c "audit_system_object=16777215" > /dev/null 2>&1 --- prepare -\! echo $GAUSSHOME | sed 's/^.*tmp_check\/install\///g' | xargs -I{} rm -f {}/bin/subscription.key.cipher -\! echo $GAUSSHOME | sed 's/^.*tmp_check\/install\///g' | xargs -I{} rm -f {}/bin/subscription.key.rand -\! echo $GAUSSHOME | sed 's/^.*tmp_check\/install\///g' | xargs -I{} @abs_bindir@/gs_guc generate -S 123456@pwd -D {}/bin -o subscription > /dev/null 2>&1 ; echo $? +\! echo $OLDGAUSSHOME | xargs -I{} rm -f {}/bin/subscription.key.cipher +\! echo $OLDGAUSSHOME | xargs -I{} rm -f {}/bin/subscription.key.rand +\! echo $OLDGAUSSHOME | xargs -I{} @abs_bindir@/gs_guc generate -S 123456@pwd -D {}/bin -o subscription > /dev/null 2>&1 ; echo $? 0 CREATE ROLE regress_subscription_user LOGIN SYSADMIN PASSWORD 'Abcdef@123'; CREATE ROLE regress_subscription_user2 LOGIN SYSADMIN PASSWORD 'Abcdef@123'; diff --git a/src/test/regress/parallel_schedule0 b/src/test/regress/parallel_schedule0 index 6f8e8214c..b86140e6a 100644 --- a/src/test/regress/parallel_schedule0 +++ b/src/test/regress/parallel_schedule0 @@ -899,11 +899,11 @@ test: toomanyparams test: test_astore_multixact test: component_view_enhancements -#test: single_node_user_mapping +test: single_node_user_mapping # publication and subscription, we need to record audit log for them, so seperate them into two test group -#test: publication -#test: subscription +test: publication +test: subscription test: fdw_audit test: gs_global_config_audit test: detail