Adds a new subscription to the current database. The subscription name must be different from a name of any existing subscription in the database. A subscription represents a replication for connecting to the publication side.
1 2 3 4 | CREATE SUBSCRIPTION name CONNECTION 'conninfo' PUBLICATION publication_name [, ...] [ WITH ( subscription_parameter [= value] [, ... ] ) ] |
Specifies the name of a subscription.
Value range: A string. It must comply with the naming convention.
Specifies the string for connecting to the publication side.
Example: host=1.1.1.1,2.2.2.2 port=10000,20000 dbname=postgres user=repusr1 password=password_123
IP address of the publication side. You can specify the IP addresses of both the primary and standby nodes of the publication side. Separate the IP addresses with commas (,).
The publication port cannot be the primary port. Instead, it must be the primary port number plus 1. Otherwise, the port number conflicts with the thread pool. You can specify the ports of both the primary and standby nodes of the publication side. Separate the ports with commas (,).
The number of hosts must be the same as that of ports.
Specifies the database where a publication is deployed.
Specifies the username and password used to connect to the publication side. The user has the system administrator permission (SYSADMIN) or O&M administrator permission (OPRADMIN).
Specifies the name of the publication you want to subscribe to on the publication side. A subscription corresponds to multiple publications.
Specifies the optional parameters for a subscription. The following parameters are supported:
Specifies whether a subscription should be actively replicated, or whether it should be just set but not started.
The value can be true or false.
The default value is true.
Specifies whether a replication slot is created on the publisher.
The value can be true or false.
The default value is true.
Specifies the name of the replication slot.
Value range: a string
Default value: the subscription name
CREATE SUBSCRIPTION mysub CONNECTION 'host=192.168.1.50 port=5432 user=foo dbname=foodb password=xxxx' PUBLICATION mypublication;