postgresql_16:7.1.82.3 Notes
PostgreSQL 16 > Reference > SQL Commands > CREATE SUBSCRIPTION > Notes
See (see postgresql_16:4.16.9) 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. To make this work, create the replication slot separately (using the function pg_create_logical_replication_slot with the plugin name pgoutput) and create the subscription using the parameter create_slot = false. See (see postgresql_16:4.16.2.3) for examples. This is an implementation restriction that might be lifted in a future release.
If any table in the publication has a WHERE clause, rows for which the *expression* evaluates to false or null will not be published. If the subscription has several publications in which the same table has been published with different WHERE clauses, a row will be published if any of the expressions (referring to that publish operation) are satisfied. In the case of different WHERE clauses, if one of the publications has no WHERE clause (referring to that publish operation) or the publication is declared as FOR ALL TABLES (see sql-createpublication-for-all-tables) or FOR TABLES IN SCHEMA (see sql-createpublication-for-tables-in-schema), rows are always published regardless of the definition of the other expressions. If the subscriber is a PostgreSQL version before 15, then any row filtering is ignored during the initial data synchronization phase. For this case, the user might want to consider deleting any initially copied data that would be incompatible with subsequent filtering. Because initial data synchronization does not take into account the publication publish (see sql-createpublication-with-publish) parameter when copying existing table data, some rows may be copied that would not be replicated using DML. See (see postgresql_16:4.16.2.2) for examples.
Subscriptions having several publications in which the same table has been published with different column lists are not supported.
We allow non-existent publications to be specified so that users can add those later. This means pg_subscription (see postgresql_16:8.2.54) can have non-existent publications.
When using a subscription parameter combination of copy_data = true and origin = NONE, the initial sync table data is copied directly from the publisher, meaning that knowledge of the true origin of that data is not possible. If the publisher also has subscriptions then the copied table data might have originated from further upstream. This scenario is detected and a WARNING is logged to the user, but the warning is only an indication of a potential problem; it is the user's responsibility to make the necessary checks to ensure the copied data origins are really as wanted or not.
To find which tables might potentially include non-local origins (due to other subscriptions created on the publisher) try this SQL query: # substitute <pub-names> below with your publication name(s) to be queried SELECT DISTINCT PT.schemaname, PT.tablename FROM pg_publication_tables PT JOIN pg_class C ON (C.relname = PT.tablename) JOIN pg_namespace N ON (N.nspname = PT.schemaname), pg_subscription_rel PS WHERE C.relnamespace = N.oid AND (PS.srrelid = C.oid OR C.oid IN (SELECT relid FROM pg_partition_ancestors(PS.srrelid) UNION SELECT relid FROM pg_partition_tree(PS.srrelid))) AND PT.pubname IN (<pub-names>);