{"Entry":{"collection":"tool","key":"pg-createsubscriber","name":"pg_createsubscriber","aliases":["pg_createsubscriber"],"metadata":{"aliases":["pg_createsubscriber"],"category":"Server applications","content_hash":"c4b251615b714c289c0c54356896bce5978e2206a711c18be1da52a81af966ee","imported_at":"2026-09-30T00:40:34.134372+08:00","name":"pg_createsubscriber","name_zh":"","slug":"pg-createsubscriber","summary":"pg_createsubscriber — convert a physical replica into a new logical replica"}},"Definition":{"Collection":"tool","Key":"pg-createsubscriber","SourceDatabase":"center","Version":"18","SourceTable":"command_tool","SourceKey":"pg-createsubscriber","SourceRevision":"ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8","Facts":{"comparison_data":{"environment":[],"options":[{"description":"Create one subscription per database on the target server. Exceptions are template databases and databases that don't allow connections. To discover the list of all databases, connect to the source server using the database name specified in the --publisher-server connection string, or if not specified, the postgres database will be used, or if that does not exist, template1 will be used. Automatically generated names for subscriptions, publications, and replication slots are used when this option is specified. This option cannot be used along with --database , --publication , --replication-slot , or --subscription .","names":["-a","--all"],"signature":"-a --all"},{"description":"The name of the database in which to create a subscription. Multiple databases can be selected by writing multiple -d switches. This option cannot be used together with -a . If -d option is not provided, the database name will be obtained from -P option. If the database name is not specified in either the -d option, or the -P option, and -a option is not specified, an error will be reported.","names":["-d dbname","--database= dbname"],"signature":"-d dbname --database= dbname"},{"description":"The target directory that contains a cluster directory from a physical replica.","names":["-D directory","--pgdata= directory"],"signature":"-D directory --pgdata= directory"},{"description":"Do everything except actually modifying the target directory.","names":["-n","--dry-run"],"signature":"-n --dry-run"},{"description":"The port number on which the target server is listening for connections. Defaults to running the target server on port 50432 to avoid unintended client connections.","names":["-p port","--subscriber-port= port"],"signature":"-p port --subscriber-port= port"},{"description":"The connection string to the publisher. For details see Section 32.1.1 .","names":["-P connstr","--publisher-server= connstr"],"signature":"-P connstr --publisher-server= connstr"},{"description":"The directory to use for postmaster sockets on target server. The default is current directory.","names":["-s dir","--socketdir= dir"],"signature":"-s dir --socketdir= dir"},{"description":"The maximum number of seconds to wait for recovery to end. Setting to 0 disables. The default is 0.","names":["-t seconds","--recovery-timeout= seconds"],"signature":"-t seconds --recovery-timeout= seconds"},{"description":"Enables two_phase commit for the subscription. When multiple databases are specified, this option applies uniformly to all subscriptions created on those databases. The default is false .","names":["-T","--enable-two-phase"],"signature":"-T --enable-two-phase"},{"description":"The user name to connect as on target server. Defaults to the current operating system user name.","names":["-U username","--subscriber-username= username"],"signature":"-U username --subscriber-username= username"},{"description":"Enables verbose mode. This will cause pg_createsubscriber to output progress messages and detailed information about each step to standard error. Repeating the option causes additional debug-level messages to appear on standard error.","names":["-v","--verbose"],"signature":"-v --verbose"},{"description":"Drop all objects of the specified type from specified databases on the target server. publications : The FOR ALL TABLES publications established for this subscriber are always dropped; specifying this object type causes all other publications replicated from the source server to be dropped as well. The objects selected to be dropped are individually logged, including during a --dry-run . There is no opportunity to affect or stop the dropping of the selected objects, so consider taking a backup of them using pg_dump .","names":["--clean= objtype"],"signature":"--clean= objtype"},{"description":"Use the specified main server configuration file for the target data directory. pg_createsubscriber internally uses the pg_ctl command to start and stop the target server. It allows you to specify the actual postgresql.conf configuration file if it is stored outside the data directory.","names":["--config-file= filename"],"signature":"--config-file= filename"},{"description":"The publication name to set up the logical replication. Multiple publications can be specified by writing multiple --publication switches. The number of publication names must match the number of specified databases, otherwise an error is reported. The order of the multiple publication name switches must match the order of database switches. If this option is not specified, a generated name is assigned to the publication name. This option cannot be used together with --all .","names":["--publication= name"],"signature":"--publication= name"},{"description":"The replication slot name to set up the logical replication. Multiple replication slots can be specified by writing multiple --replication-slot switches. The number of replication slot names must match the number of specified databases, otherwise an error is reported. The order of the multiple replication slot name switches must match the order of database switches. If this option is not specified, the subscription name is assigned to the replication slot name. This option cannot be used together with --all .","names":["--replication-slot= name"],"signature":"--replication-slot= name"},{"description":"The subscription name to set up the logical replication. Multiple subscriptions can be specified by writing multiple --subscription switches. The number of subscription names must match the number of specified databases, otherwise an error is reported. The order of the multiple subscription name switches must match the order of database switches. If this option is not specified, a generated name is assigned to the subscription name. This option cannot be used together with --all .","names":["--subscription= name"],"signature":"--subscription= name"},{"description":"Print the pg_createsubscriber version and exit.","names":["-V","--version"],"signature":"-V --version"},{"description":"Show help about pg_createsubscriber command line arguments, and exit.","names":["-?","--help"],"signature":"-? --help"}],"synopsis":["pg_createsubscriber [ option ...] { -d | --database } dbname { -D | --pgdata } datadir { -P | --publisher-server } connstr"]},"comparison_hash":"ab2f9ba9dc71a377cdb3a682c66b1a84f3cb3ae29cb8c1b178c5acc418bc4441","description":["pg_createsubscriber — convert a physical replica into a new logical replica"],"environment":[],"facts":[{"label":"Documented executable","value":"pg_createsubscriber"},{"label":"Executable version","value":"18.6"},{"label":"Reference inventory","value":"Server applications"},{"label":"Option definition groups","value":"18"}],"manual_html":"\u003cdiv\u003e\u003cdiv class=\"refentry\" id=\"APP-PGCREATESUBSCRIBER\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\u003c/div\u003e\n\u003cdiv class=\"refnamediv\"\u003e\n\u003ch2\u003e\u003cspan class=\"refentrytitle\"\u003e\u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e\u003c/span\u003e\u003c/h2\u003e\n\u003cp\u003epg_createsubscriber — convert a physical replica into a new logical replica\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsynopsisdiv\"\u003e\n\u003ch2\u003eSynopsis\u003c/h2\u003e\n\u003cdiv class=\"cmdsynopsis\"\u003e\n\u003cp id=\"id-1.9.5.7.4.1\"\u003e\u003ccode class=\"command\"\u003epg_createsubscriber\u003c/code\u003e [\u003cem class=\"replaceable\"\u003e\u003ccode\u003eoption\u003c/code\u003e\u003c/em\u003e...] { \u003ccode class=\"option\"\u003e-d\u003c/code\u003e | \u003ccode class=\"option\"\u003e--database\u003c/code\u003e }\u003cem class=\"replaceable\"\u003e\u003ccode\u003edbname\u003c/code\u003e\u003c/em\u003e { \u003ccode class=\"option\"\u003e-D\u003c/code\u003e | \u003ccode class=\"option\"\u003e--pgdata\u003c/code\u003e }\u003cem class=\"replaceable\"\u003e\u003ccode\u003edatadir\u003c/code\u003e\u003c/em\u003e { \u003ccode class=\"option\"\u003e-P\u003c/code\u003e | \u003ccode class=\"option\"\u003e--publisher-server\u003c/code\u003e }\u003cem class=\"replaceable\"\u003e\u003ccode\u003econnstr\u003c/code\u003e\u003c/em\u003e\u003c/p\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsect1\" id=\"id-1.9.5.7.5\"\u003e\n\u003ch2\u003eDescription\u003c/h2\u003e\n\u003cp\u003e\u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e creates a new logical replica from a physical standby server. All tables in the specified database are included in the \u003ca class=\"link\" href=\"/docs/18/logical-replication.html\" title=\"Chapter 29. Logical Replication\"\u003elogical replication\u003c/a\u003e setup. A pair of publication and subscription objects are created for each database. It must be run at the target server.\u003c/p\u003e\n\u003cp\u003eAfter a successful run, the state of the target server is analogous to a fresh logical replication setup. The main difference between the logical replication setup and \u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e is how the data synchronization is done. \u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e does not copy the initial table data. It does only the synchronization phase, which ensures each table is brought up to a synchronized state.\u003c/p\u003e\n\u003cp\u003e\u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e targets large database systems because in logical replication setup, most of the time is spent doing the initial data copy. Furthermore, a side effect of this long time spent synchronizing data is usually a large amount of changes to be applied (that were produced during the initial data copy), which increases even more the time when the logical replica will be available. For smaller databases, it is recommended to set up logical replication with initial data synchronization. For details, see the \u003ccode class=\"command\"\u003eCREATE SUBSCRIPTION\u003c/code\u003e \u003ca class=\"link\" href=\"/docs/18/sql-createsubscription.html#SQL-CREATESUBSCRIPTION-PARAMS-WITH-COPY-DATA\"\u003e\u003ccode class=\"literal\"\u003ecopy_data\u003c/code\u003e\u003c/a\u003e option.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsect1\" id=\"id-1.9.5.7.6\"\u003e\n\u003ch2\u003eOptions\u003c/h2\u003e\n\u003cp\u003e\u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e accepts the following command-line arguments:\u003c/p\u003e\n\u003cdiv class=\"variablelist\"\u003e\n\u003cdl class=\"variablelist\"\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-a\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--all\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eCreate one subscription per database on the target server. Exceptions are template databases and databases that don't allow connections. To discover the list of all databases, connect to the source server using the database name specified in the \u003ccode class=\"option\"\u003e--publisher-server\u003c/code\u003e connection string, or if not specified, the \u003ccode class=\"literal\"\u003epostgres\u003c/code\u003e database will be used, or if that does not exist, \u003ccode class=\"literal\"\u003etemplate1\u003c/code\u003e will be used. Automatically generated names for subscriptions, publications, and replication slots are used when this option is specified. This option cannot be used along with \u003ccode class=\"option\"\u003e--database\u003c/code\u003e, \u003ccode class=\"option\"\u003e--publication\u003c/code\u003e, \u003ccode class=\"option\"\u003e--replication-slot\u003c/code\u003e, or \u003ccode class=\"option\"\u003e--subscription\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-d \u003cem class=\"replaceable\"\u003e\u003ccode\u003edbname\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--database=\u003cem class=\"replaceable\"\u003e\u003ccode\u003edbname\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe name of the database in which to create a subscription. Multiple databases can be selected by writing multiple \u003ccode class=\"option\"\u003e-d\u003c/code\u003e switches. This option cannot be used together with \u003ccode class=\"option\"\u003e-a\u003c/code\u003e. If \u003ccode class=\"option\"\u003e-d\u003c/code\u003e option is not provided, the database name will be obtained from \u003ccode class=\"option\"\u003e-P\u003c/code\u003e option. If the database name is not specified in either the \u003ccode class=\"option\"\u003e-d\u003c/code\u003e option, or the \u003ccode class=\"option\"\u003e-P\u003c/code\u003e option, and \u003ccode class=\"option\"\u003e-a\u003c/code\u003e option is not specified, an error will be reported.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-D \u003cem class=\"replaceable\"\u003e\u003ccode\u003edirectory\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--pgdata=\u003cem class=\"replaceable\"\u003e\u003ccode\u003edirectory\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe target directory that contains a cluster directory from a physical replica.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-n\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--dry-run\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eDo everything except actually modifying the target directory.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-p \u003cem class=\"replaceable\"\u003e\u003ccode\u003eport\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--subscriber-port=\u003cem class=\"replaceable\"\u003e\u003ccode\u003eport\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe port number on which the target server is listening for connections. Defaults to running the target server on port 50432 to avoid unintended client connections.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-P \u003cem class=\"replaceable\"\u003e\u003ccode\u003econnstr\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--publisher-server=\u003cem class=\"replaceable\"\u003e\u003ccode\u003econnstr\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe connection string to the publisher. For details see \u003ca class=\"xref\" href=\"/docs/18/libpq-connect.html#LIBPQ-CONNSTRING\" title=\"32.1.1. Connection Strings\"\u003eSection 32.1.1\u003c/a\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-s \u003cem class=\"replaceable\"\u003e\u003ccode\u003edir\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--socketdir=\u003cem class=\"replaceable\"\u003e\u003ccode\u003edir\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe directory to use for postmaster sockets on target server. The default is current directory.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-t \u003cem class=\"replaceable\"\u003e\u003ccode\u003eseconds\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--recovery-timeout=\u003cem class=\"replaceable\"\u003e\u003ccode\u003eseconds\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe maximum number of seconds to wait for recovery to end. Setting to 0 disables. The default is 0.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-T\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--enable-two-phase\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eEnables \u003ca class=\"link\" href=\"/docs/18/sql-createsubscription.html#SQL-CREATESUBSCRIPTION-PARAMS-WITH-TWO-PHASE\"\u003e\u003ccode class=\"literal\"\u003etwo_phase\u003c/code\u003e\u003c/a\u003e commit for the subscription. When multiple databases are specified, this option applies uniformly to all subscriptions created on those databases. The default is \u003ccode class=\"literal\"\u003efalse\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-U \u003cem class=\"replaceable\"\u003e\u003ccode\u003eusername\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--subscriber-username=\u003cem class=\"replaceable\"\u003e\u003ccode\u003eusername\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe user name to connect as on target server. Defaults to the current operating system user name.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-v\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--verbose\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eEnables verbose mode. This will cause \u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e to output progress messages and detailed information about each step to standard error. Repeating the option causes additional debug-level messages to appear on standard error.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--clean=\u003cem class=\"replaceable\"\u003e\u003ccode\u003eobjtype\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eDrop all objects of the specified type from specified databases on the target server.\u003c/p\u003e\n\u003cdiv class=\"itemizedlist\"\u003e\n\u003cul class=\"itemizedlist\"\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003e\u003ccode class=\"literal\"\u003epublications\u003c/code\u003e: The \u003ccode class=\"literal\"\u003eFOR ALL TABLES\u003c/code\u003e publications established for this subscriber are always dropped; specifying this object type causes all other publications replicated from the source server to be dropped as well.\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/div\u003e\n\u003cp\u003eThe objects selected to be dropped are individually logged, including during a \u003ccode class=\"option\"\u003e--dry-run\u003c/code\u003e. There is no opportunity to affect or stop the dropping of the selected objects, so consider taking a backup of them using \u003cspan class=\"application\"\u003epg_dump\u003c/span\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--config-file=\u003cem class=\"replaceable\"\u003e\u003ccode\u003efilename\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eUse the specified main server configuration file for the target data directory. \u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e internally uses the \u003cspan class=\"application\"\u003epg_ctl\u003c/span\u003e command to start and stop the target server. It allows you to specify the actual \u003ccode class=\"filename\"\u003epostgresql.conf\u003c/code\u003e configuration file if it is stored outside the data directory.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--publication=\u003cem class=\"replaceable\"\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe publication name to set up the logical replication. Multiple publications can be specified by writing multiple \u003ccode class=\"option\"\u003e--publication\u003c/code\u003e switches. The number of publication names must match the number of specified databases, otherwise an error is reported. The order of the multiple publication name switches must match the order of database switches. If this option is not specified, a generated name is assigned to the publication name. This option cannot be used together with \u003ccode class=\"option\"\u003e--all\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--replication-slot=\u003cem class=\"replaceable\"\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe replication slot name to set up the logical replication. Multiple replication slots can be specified by writing multiple \u003ccode class=\"option\"\u003e--replication-slot\u003c/code\u003e switches. The number of replication slot names must match the number of specified databases, otherwise an error is reported. The order of the multiple replication slot name switches must match the order of database switches. If this option is not specified, the subscription name is assigned to the replication slot name. This option cannot be used together with \u003ccode class=\"option\"\u003e--all\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--subscription=\u003cem class=\"replaceable\"\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe subscription name to set up the logical replication. Multiple subscriptions can be specified by writing multiple \u003ccode class=\"option\"\u003e--subscription\u003c/code\u003e switches. The number of subscription names must match the number of specified databases, otherwise an error is reported. The order of the multiple subscription name switches must match the order of database switches. If this option is not specified, a generated name is assigned to the subscription name. This option cannot be used together with \u003ccode class=\"option\"\u003e--all\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-V\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--version\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003ePrint the \u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e version and exit.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-?\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--help\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eShow help about \u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e command line arguments, and exit.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsect1\" id=\"id-1.9.5.7.7\"\u003e\n\u003ch2\u003eNotes\u003c/h2\u003e\n\u003cdiv class=\"refsect2\" id=\"id-1.9.5.7.7.2\"\u003e\n\u003ch3\u003ePrerequisites\u003c/h3\u003e\n\u003cp\u003eThere are some prerequisites for \u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e to convert the target server into a logical replica. If these are not met, an error will be reported. The source and target servers must have the same major version as the \u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e. The given target data directory must have the same system identifier as the source data directory. The given database user for the target data directory must have privileges for creating \u003ca class=\"link\" href=\"/docs/18/sql-createsubscription.html\" title=\"CREATE SUBSCRIPTION\"\u003esubscriptions\u003c/a\u003e and using \u003ca class=\"link\" href=\"/docs/18/functions-admin.html#PG-REPLICATION-ORIGIN-ADVANCE\"\u003e\u003ccode class=\"function\"\u003epg_replication_origin_advance()\u003c/code\u003e\u003c/a\u003e.\u003c/p\u003e\n\u003cp\u003eThe target server must be used as a physical standby. The target server must have \u003ca class=\"xref\" href=\"/docs/18/runtime-config-replication.html#GUC-MAX-ACTIVE-REPLICATION-ORIGINS\"\u003emax_active_replication_origins\u003c/a\u003e and \u003ca class=\"xref\" href=\"/docs/18/runtime-config-replication.html#GUC-MAX-LOGICAL-REPLICATION-WORKERS\"\u003emax_logical_replication_workers\u003c/a\u003e configured to a value greater than or equal to the number of specified databases. The target server must have \u003ca class=\"xref\" href=\"/docs/18/runtime-config-resource.html#GUC-MAX-WORKER-PROCESSES\"\u003emax_worker_processes\u003c/a\u003e configured to a value greater than the number of specified databases. The target server must accept local connections. If you are planning to use the \u003ccode class=\"option\"\u003e--enable-two-phase\u003c/code\u003e switch then you will also need to set the \u003ca class=\"xref\" href=\"/docs/18/runtime-config-resource.html#GUC-MAX-PREPARED-TRANSACTIONS\"\u003emax_prepared_transactions\u003c/a\u003e appropriately.\u003c/p\u003e\n\u003cp\u003eThe source server must accept connections from the target server. The source server must not be in recovery. The source server must have \u003ca class=\"xref\" href=\"/docs/18/runtime-config-wal.html#GUC-WAL-LEVEL\"\u003ewal_level\u003c/a\u003e as \u003ccode class=\"literal\"\u003elogical\u003c/code\u003e. The source server must have \u003ca class=\"xref\" href=\"/docs/18/runtime-config-replication.html#GUC-MAX-REPLICATION-SLOTS\"\u003emax_replication_slots\u003c/a\u003e configured to a value greater than or equal to the number of specified databases plus existing replication slots. The source server must have \u003ca class=\"xref\" href=\"/docs/18/runtime-config-replication.html#GUC-MAX-WAL-SENDERS\"\u003emax_wal_senders\u003c/a\u003e configured to a value greater than or equal to the number of specified databases and existing WAL sender processes.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsect2\" id=\"id-1.9.5.7.7.3\"\u003e\n\u003ch3\u003eWarnings\u003c/h3\u003e\n\u003cp\u003eIf \u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e fails after the target server was promoted, then the data directory is likely not in a state that can be recovered. In such case, creating a new standby server is recommended.\u003c/p\u003e\n\u003cp\u003e\u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e usually starts the target server with different connection settings during transformation. Hence, connections to the target server should fail.\u003c/p\u003e\n\u003cp\u003eSince DDL commands are not replicated by logical replication, avoid executing DDL commands that change the database schema while running \u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e. If the target server has already been converted to logical replica, the DDL commands might not be replicated, which might cause an error.\u003c/p\u003e\n\u003cp\u003eIf \u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e fails while processing, objects (publications, replication slots) created on the source server are removed. The removal might fail if the target server cannot connect to the source server. In such a case, a warning message will inform the objects left. If the target server is running, it will be stopped.\u003c/p\u003e\n\u003cp\u003eIf the replication is using \u003ca class=\"xref\" href=\"/docs/18/runtime-config-replication.html#GUC-PRIMARY-SLOT-NAME\"\u003eprimary_slot_name\u003c/a\u003e, it will be removed from the source server after the logical replication setup.\u003c/p\u003e\n\u003cp\u003eIf the target server is a synchronous replica, transaction commits on the primary might wait for replication while running \u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e.\u003c/p\u003e\n\u003cp\u003eUnless the \u003ccode class=\"option\"\u003e--enable-two-phase\u003c/code\u003e switch is specified, \u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e sets up logical replication with two-phase commit disabled. This means that any prepared transactions will be replicated at the time of \u003ccode class=\"command\"\u003eCOMMIT PREPARED\u003c/code\u003e, without advance preparation. Once setup is complete, you can manually drop and re-create the subscription(s) with the \u003ca class=\"link\" href=\"/docs/18/sql-createsubscription.html#SQL-CREATESUBSCRIPTION-PARAMS-WITH-TWO-PHASE\"\u003e\u003ccode class=\"literal\"\u003etwo_phase\u003c/code\u003e\u003c/a\u003e option enabled.\u003c/p\u003e\n\u003cp\u003e\u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e changes the system identifier using \u003cspan class=\"application\"\u003epg_resetwal\u003c/span\u003e. It would avoid situations in which the target server might use WAL files from the source server. If the target server has a standby, replication will break and a fresh standby should be created.\u003c/p\u003e\n\u003cp\u003eReplication failures can occur if required WAL files are missing. To prevent this, the source server must set \u003ca class=\"xref\" href=\"/docs/18/runtime-config-replication.html#GUC-MAX-SLOT-WAL-KEEP-SIZE\"\u003emax_slot_wal_keep_size\u003c/a\u003e to \u003ccode class=\"literal\"\u003e-1\u003c/code\u003e to ensure that required WAL files are not prematurely removed.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsect2\" id=\"id-1.9.5.7.7.4\"\u003e\n\u003ch3\u003eHow It Works\u003c/h3\u003e\n\u003cp\u003eThe basic idea is to have a replication start point from the source server and set up a logical replication to start from this point:\u003c/p\u003e\n\u003cdiv class=\"procedure\"\u003e\n\u003col class=\"procedure\"\u003e\n\u003cli class=\"step\"\u003e\n\u003cp\u003eStart the target server with the specified command-line options. If the target server is already running, \u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e will terminate with an error.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp\u003eCheck if the target server can be converted. There are also a few checks on the source server. If any of the prerequisites are not met, \u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e will terminate with an error.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp\u003eCreate a publication and replication slot for each specified database on the source server. Each publication is created using \u003ca class=\"link\" href=\"/docs/18/sql-createpublication.html#SQL-CREATEPUBLICATION-PARAMS-FOR-ALL-TABLES\"\u003e\u003ccode class=\"literal\"\u003eFOR ALL TABLES\u003c/code\u003e\u003c/a\u003e. If the \u003ccode class=\"option\"\u003e--publication\u003c/code\u003e option is not specified, the publication has the following name pattern: \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003e\u003ccode class=\"literal\"\u003epg_createsubscriber_%u_%x\u003c/code\u003e\u003c/span\u003e”\u003c/span\u003e (parameter: database \u003cem class=\"parameter\"\u003e\u003ccode\u003eoid\u003c/code\u003e\u003c/em\u003e, random \u003cem class=\"parameter\"\u003e\u003ccode\u003eint\u003c/code\u003e\u003c/em\u003e). If the \u003ccode class=\"option\"\u003e--replication-slot\u003c/code\u003e option is not specified, the replication slot has the following name pattern: \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003e\u003ccode class=\"literal\"\u003epg_createsubscriber_%u_%x\u003c/code\u003e\u003c/span\u003e”\u003c/span\u003e (parameters: database \u003cem class=\"parameter\"\u003e\u003ccode\u003eoid\u003c/code\u003e\u003c/em\u003e, random \u003cem class=\"parameter\"\u003e\u003ccode\u003eint\u003c/code\u003e\u003c/em\u003e). These replication slots will be used by the subscriptions in a future step. The last replication slot LSN is used as a stopping point in the \u003ca class=\"xref\" href=\"/docs/18/runtime-config-wal.html#GUC-RECOVERY-TARGET-LSN\"\u003erecovery_target_lsn\u003c/a\u003e parameter and by the subscriptions as a replication start point. It guarantees that no transaction will be lost.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp\u003eWrite recovery parameters into the target data directory and restart the target server. It specifies an LSN (\u003ca class=\"xref\" href=\"/docs/18/runtime-config-wal.html#GUC-RECOVERY-TARGET-LSN\"\u003erecovery_target_lsn\u003c/a\u003e) of the write-ahead log location up to which recovery will proceed. It also specifies \u003ccode class=\"literal\"\u003epromote\u003c/code\u003e as the action that the server should take once the recovery target is reached. Additional \u003ca class=\"link\" href=\"/docs/18/runtime-config-wal.html#RUNTIME-CONFIG-WAL-RECOVERY-TARGET\" title=\"19.5.6. Recovery Target\"\u003erecovery parameters\u003c/a\u003e are added to avoid unexpected behavior during the recovery process such as end of the recovery as soon as a consistent state is reached (WAL should be applied until the replication start location) and multiple recovery targets that can cause a failure. This step finishes once the server ends standby mode and is accepting read-write transactions. If \u003ccode class=\"option\"\u003e--recovery-timeout\u003c/code\u003e option is set, \u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e terminates if recovery does not end until the given number of seconds.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp\u003eCreate a subscription for each specified database on the target server. If the \u003ccode class=\"option\"\u003e--subscription\u003c/code\u003e option is not specified, the subscription has the following name pattern: \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003e\u003ccode class=\"literal\"\u003epg_createsubscriber_%u_%x\u003c/code\u003e\u003c/span\u003e”\u003c/span\u003e (parameters: database \u003cem class=\"parameter\"\u003e\u003ccode\u003eoid\u003c/code\u003e\u003c/em\u003e, random \u003cem class=\"parameter\"\u003e\u003ccode\u003eint\u003c/code\u003e\u003c/em\u003e). It does not copy existing data from the source server. It does not create a replication slot. Instead, it uses the replication slot that was created in a previous step. The subscription is created but it is not enabled yet. The reason is the replication progress must be set to the replication start point before starting the replication.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp\u003eDrop publications on the target server that were replicated because they were created before the replication start location. It has no use on the subscriber.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp\u003eSet the replication progress to the replication start point for each subscription. When the target server starts the recovery process, it catches up to the replication start point. This is the exact LSN to be used as a initial replication location for each subscription. The replication origin name is obtained since the subscription was created. The replication origin name and the replication start point are used in \u003ca class=\"link\" href=\"/docs/18/functions-admin.html#PG-REPLICATION-ORIGIN-ADVANCE\"\u003e\u003ccode class=\"function\"\u003epg_replication_origin_advance()\u003c/code\u003e\u003c/a\u003e to set up the initial replication location.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp\u003eEnable the subscription for each specified database on the target server. The subscription starts applying transactions from the replication start point.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp\u003eIf the standby server was using \u003ca class=\"xref\" href=\"/docs/18/runtime-config-replication.html#GUC-PRIMARY-SLOT-NAME\"\u003eprimary_slot_name\u003c/a\u003e, it has no use from now on so drop it.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp\u003eIf the standby server contains \u003ca class=\"link\" href=\"/docs/18/logicaldecoding-explanation.html#LOGICALDECODING-REPLICATION-SLOTS-SYNCHRONIZATION\" title=\"47.2.3. Replication Slot Synchronization\"\u003efailover replication slots\u003c/a\u003e, they cannot be synchronized anymore, so drop them.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp\u003eUpdate the system identifier on the target server. The \u003ca class=\"xref\" href=\"/docs/18/app-pgresetwal.html\" title=\"pg_resetwal\"\u003e\u003cspan class=\"refentrytitle\"\u003e\u003cspan class=\"application\"\u003epg_resetwal\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e is run to modify the system identifier. The target server is stopped as a \u003ccode class=\"command\"\u003epg_resetwal\u003c/code\u003e requirement.\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ol\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsect1\" id=\"id-1.9.5.7.8\"\u003e\n\u003ch2\u003eExamples\u003c/h2\u003e\n\u003cp\u003eTo create a logical replica for databases \u003ccode class=\"literal\"\u003ehr\u003c/code\u003e and \u003ccode class=\"literal\"\u003efinance\u003c/code\u003e from a physical replica at \u003ccode class=\"literal\"\u003efoo\u003c/code\u003e:\u003c/p\u003e\n\u003cpre class=\"screen\"\u003e\u003ccode class=\"prompt\"\u003e$\u003c/code\u003e \u003cstrong class=\"userinput\"\u003e\u003ccode\u003epg_createsubscriber -D /usr/local/pgsql/data -P \"host=foo\" -d hr -d finance\u003c/code\u003e\u003c/strong\u003e\n\u003c/pre\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsect1\" id=\"id-1.9.5.7.9\"\u003e\n\u003ch2\u003eSee Also\u003c/h2\u003e\u003cspan class=\"simplelist\"\u003e\u003ca class=\"xref\" href=\"/docs/18/app-pgbasebackup.html\" title=\"pg_basebackup\"\u003e\u003cspan class=\"refentrytitle\"\u003e\u003cspan class=\"application\"\u003epg_basebackup\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e\n\u003c/div\u003e\n\u003c/div\u003e\u003c/div\u003e","manual_path":"app-pgcreatesubscriber.html","options":[{"description":"Create one subscription per database on the target server. Exceptions are template databases and databases that don't allow connections. To discover the list of all databases, connect to the source server using the database name specified in the --publisher-server connection string, or if not specified, the postgres database will be used, or if that does not exist, template1 will be used. Automatically generated names for subscriptions, publications, and replication slots are used when this option is specified. This option cannot be used along with --database , --publication , --replication-slot , or --subscription .","names":["-a","--all"],"signature":"-a --all","source_url":"/docs/18/app-pgcreatesubscriber.html","summary":"Create one subscription per database on the target server. Exceptions are template databases and databases that don't allow connections. To discover the list of all databases, connect to the source server using the database name specified in the --publisher-server connection string, or if not specified, the postgres database will be used, or if that does not exist, template1 will be used. Automatically generated names for subscriptions, publications, and replication slots are used when this option is specified. This option cannot be used along with --database , --publication , --replication-slot , or --subscription ."},{"description":"The name of the database in which to create a subscription. Multiple databases can be selected by writing multiple -d switches. This option cannot be used together with -a . If -d option is not provided, the database name will be obtained from -P option. If the database name is not specified in either the -d option, or the -P option, and -a option is not specified, an error will be reported.","names":["-d dbname","--database= dbname"],"signature":"-d dbname --database= dbname","source_url":"/docs/18/app-pgcreatesubscriber.html","summary":"The name of the database in which to create a subscription. Multiple databases can be selected by writing multiple -d switches. This option cannot be used together with -a . If -d option is not provided, the database name will be obtained from -P option. If the database name is not specified in either the -d option, or the -P option, and -a option is not specified, an error will be reported."},{"description":"The target directory that contains a cluster directory from a physical replica.","names":["-D directory","--pgdata= directory"],"signature":"-D directory --pgdata= directory","source_url":"/docs/18/app-pgcreatesubscriber.html","summary":"The target directory that contains a cluster directory from a physical replica."},{"description":"Do everything except actually modifying the target directory.","names":["-n","--dry-run"],"signature":"-n --dry-run","source_url":"/docs/18/app-pgcreatesubscriber.html","summary":"Do everything except actually modifying the target directory."},{"description":"The port number on which the target server is listening for connections. Defaults to running the target server on port 50432 to avoid unintended client connections.","names":["-p port","--subscriber-port= port"],"signature":"-p port --subscriber-port= port","source_url":"/docs/18/app-pgcreatesubscriber.html","summary":"The port number on which the target server is listening for connections. Defaults to running the target server on port 50432 to avoid unintended client connections."},{"description":"The connection string to the publisher. For details see Section 32.1.1 .","names":["-P connstr","--publisher-server= connstr"],"signature":"-P connstr --publisher-server= connstr","source_url":"/docs/18/app-pgcreatesubscriber.html","summary":"The connection string to the publisher. For details see Section 32.1.1 ."},{"description":"The directory to use for postmaster sockets on target server. The default is current directory.","names":["-s dir","--socketdir= dir"],"signature":"-s dir --socketdir= dir","source_url":"/docs/18/app-pgcreatesubscriber.html","summary":"The directory to use for postmaster sockets on target server. The default is current directory."},{"description":"The maximum number of seconds to wait for recovery to end. Setting to 0 disables. The default is 0.","names":["-t seconds","--recovery-timeout= seconds"],"signature":"-t seconds --recovery-timeout= seconds","source_url":"/docs/18/app-pgcreatesubscriber.html","summary":"The maximum number of seconds to wait for recovery to end. Setting to 0 disables. The default is 0."},{"description":"Enables two_phase commit for the subscription. When multiple databases are specified, this option applies uniformly to all subscriptions created on those databases. The default is false .","names":["-T","--enable-two-phase"],"signature":"-T --enable-two-phase","source_url":"/docs/18/app-pgcreatesubscriber.html","summary":"Enables two_phase commit for the subscription. When multiple databases are specified, this option applies uniformly to all subscriptions created on those databases. The default is false ."},{"description":"The user name to connect as on target server. Defaults to the current operating system user name.","names":["-U username","--subscriber-username= username"],"signature":"-U username --subscriber-username= username","source_url":"/docs/18/app-pgcreatesubscriber.html","summary":"The user name to connect as on target server. Defaults to the current operating system user name."},{"description":"Enables verbose mode. This will cause pg_createsubscriber to output progress messages and detailed information about each step to standard error. Repeating the option causes additional debug-level messages to appear on standard error.","names":["-v","--verbose"],"signature":"-v --verbose","source_url":"/docs/18/app-pgcreatesubscriber.html","summary":"Enables verbose mode. This will cause pg_createsubscriber to output progress messages and detailed information about each step to standard error. Repeating the option causes additional debug-level messages to appear on standard error."},{"description":"Drop all objects of the specified type from specified databases on the target server. publications : The FOR ALL TABLES publications established for this subscriber are always dropped; specifying this object type causes all other publications replicated from the source server to be dropped as well. The objects selected to be dropped are individually logged, including during a --dry-run . There is no opportunity to affect or stop the dropping of the selected objects, so consider taking a backup of them using pg_dump .","names":["--clean= objtype"],"signature":"--clean= objtype","source_url":"/docs/18/app-pgcreatesubscriber.html","summary":"Drop all objects of the specified type from specified databases on the target server."},{"description":"Use the specified main server configuration file for the target data directory. pg_createsubscriber internally uses the pg_ctl command to start and stop the target server. It allows you to specify the actual postgresql.conf configuration file if it is stored outside the data directory.","names":["--config-file= filename"],"signature":"--config-file= filename","source_url":"/docs/18/app-pgcreatesubscriber.html","summary":"Use the specified main server configuration file for the target data directory. pg_createsubscriber internally uses the pg_ctl command to start and stop the target server. It allows you to specify the actual postgresql.conf configuration file if it is stored outside the data directory."},{"description":"The publication name to set up the logical replication. Multiple publications can be specified by writing multiple --publication switches. The number of publication names must match the number of specified databases, otherwise an error is reported. The order of the multiple publication name switches must match the order of database switches. If this option is not specified, a generated name is assigned to the publication name. This option cannot be used together with --all .","names":["--publication= name"],"signature":"--publication= name","source_url":"/docs/18/app-pgcreatesubscriber.html","summary":"The publication name to set up the logical replication. Multiple publications can be specified by writing multiple --publication switches. The number of publication names must match the number of specified databases, otherwise an error is reported. The order of the multiple publication name switches must match the order of database switches. If this option is not specified, a generated name is assigned to the publication name. This option cannot be used together with --all ."},{"description":"The replication slot name to set up the logical replication. Multiple replication slots can be specified by writing multiple --replication-slot switches. The number of replication slot names must match the number of specified databases, otherwise an error is reported. The order of the multiple replication slot name switches must match the order of database switches. If this option is not specified, the subscription name is assigned to the replication slot name. This option cannot be used together with --all .","names":["--replication-slot= name"],"signature":"--replication-slot= name","source_url":"/docs/18/app-pgcreatesubscriber.html","summary":"The replication slot name to set up the logical replication. Multiple replication slots can be specified by writing multiple --replication-slot switches. The number of replication slot names must match the number of specified databases, otherwise an error is reported. The order of the multiple replication slot name switches must match the order of database switches. If this option is not specified, the subscription name is assigned to the replication slot name. This option cannot be used together with --all ."},{"description":"The subscription name to set up the logical replication. Multiple subscriptions can be specified by writing multiple --subscription switches. The number of subscription names must match the number of specified databases, otherwise an error is reported. The order of the multiple subscription name switches must match the order of database switches. If this option is not specified, a generated name is assigned to the subscription name. This option cannot be used together with --all .","names":["--subscription= name"],"signature":"--subscription= name","source_url":"/docs/18/app-pgcreatesubscriber.html","summary":"The subscription name to set up the logical replication. Multiple subscriptions can be specified by writing multiple --subscription switches. The number of subscription names must match the number of specified databases, otherwise an error is reported. The order of the multiple subscription name switches must match the order of database switches. If this option is not specified, a generated name is assigned to the subscription name. This option cannot be used together with --all ."},{"description":"Print the pg_createsubscriber version and exit.","names":["-V","--version"],"signature":"-V --version","source_url":"/docs/18/app-pgcreatesubscriber.html","summary":"Print the pg_createsubscriber version and exit."},{"description":"Show help about pg_createsubscriber command line arguments, and exit.","names":["-?","--help"],"signature":"-? --help","source_url":"/docs/18/app-pgcreatesubscriber.html","summary":"Show help about pg_createsubscriber command line arguments, and exit."}],"related":[],"release":{"channel":"stable","evidence_kind":"English manual and source declarations","label":"18.6","major":"18","manifest":{"index":"index.html","major":"18","pages":1148,"pdf":{"A4":{"built_at":"2026-09-26","bytes":15865106,"pages":3154,"sha256":"19512c405da53f9f7fcf0abba359223aa65f021be025bf3411381918f92e3190","url":"/files/documentation/pdf/18/postgresql-18-A4.pdf"},"US":{"built_at":"2026-09-26","bytes":15748059,"pages":3328,"sha256":"facbe6c229e598b872d3d98bef53308f46e06746006fa4590de9a7de9dd46319","url":"/files/documentation/pdf/18/postgresql-18-US.pdf"}},"release":"18.6","source_mode":"en SGML built with pinned official archive","source_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","source_url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2","svg_assets":3,"tree":"18"},"ref":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2","revision":"ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8","source_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f"},"sections":[],"signature":"pg_createsubscriber [ option ...] { -d | --database } dbname { -D | --pgdata } datadir { -P | --publisher-server } connstr","sources":[{"anchor":"","file":"app-pgcreatesubscriber.html","label":"18.6 English manual · app-pgcreatesubscriber.html","sha256":"fb0e5cd7f37044410e06deb436d7b70a1bceffbd849ce10f468351d9cf11d385","url":"/docs/18/app-pgcreatesubscriber.html"},{"anchor":"","file":"reference-server.html","label":"Server applications inventory","sha256":"e9f8bbcc8e3641fadd1d20991e8aad6b532155b786ba5a1b7b364ec4f1a5bef3","url":"/docs/18/reference-server.html"}],"synopsis":["pg_createsubscriber [ option ...] { -d | --database } dbname { -D | --pgdata } datadir { -P | --publisher-server } connstr"],"tables":[{"columns":[{"key":"signature","label":"Option and arguments"},{"key":"summary","label":"Description"}],"key":"options","rows":[{"signature":{"text":"-a --all","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"Create one subscription per database on the target server. Exceptions are template databases and databases that don't allow connections. To discover the list of all databases, connect to the source server using the database name specified in the --publisher-server connection string, or if not specified, the postgres database will be used, or if that does not exist, template1 will be used. Automatically generated names for subscriptions, publications, and replication slots are used when this option is specified. This option cannot be used along with --database , --publication , --replication-slot , or --subscription ."},{"signature":{"text":"-d dbname --database= dbname","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"The name of the database in which to create a subscription. Multiple databases can be selected by writing multiple -d switches. This option cannot be used together with -a . If -d option is not provided, the database name will be obtained from -P option. If the database name is not specified in either the -d option, or the -P option, and -a option is not specified, an error will be reported."},{"signature":{"text":"-D directory --pgdata= directory","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"The target directory that contains a cluster directory from a physical replica."},{"signature":{"text":"-n --dry-run","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"Do everything except actually modifying the target directory."},{"signature":{"text":"-p port --subscriber-port= port","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"The port number on which the target server is listening for connections. Defaults to running the target server on port 50432 to avoid unintended client connections."},{"signature":{"text":"-P connstr --publisher-server= connstr","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"The connection string to the publisher. For details see Section 32.1.1 ."},{"signature":{"text":"-s dir --socketdir= dir","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"The directory to use for postmaster sockets on target server. The default is current directory."},{"signature":{"text":"-t seconds --recovery-timeout= seconds","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"The maximum number of seconds to wait for recovery to end. Setting to 0 disables. The default is 0."},{"signature":{"text":"-T --enable-two-phase","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"Enables two_phase commit for the subscription. When multiple databases are specified, this option applies uniformly to all subscriptions created on those databases. The default is false ."},{"signature":{"text":"-U username --subscriber-username= username","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"The user name to connect as on target server. Defaults to the current operating system user name."},{"signature":{"text":"-v --verbose","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"Enables verbose mode. This will cause pg_createsubscriber to output progress messages and detailed information about each step to standard error. Repeating the option causes additional debug-level messages to appear on standard error."},{"signature":{"text":"--clean= objtype","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"Drop all objects of the specified type from specified databases on the target server."},{"signature":{"text":"--config-file= filename","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"Use the specified main server configuration file for the target data directory. pg_createsubscriber internally uses the pg_ctl command to start and stop the target server. It allows you to specify the actual postgresql.conf configuration file if it is stored outside the data directory."},{"signature":{"text":"--publication= name","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"The publication name to set up the logical replication. Multiple publications can be specified by writing multiple --publication switches. The number of publication names must match the number of specified databases, otherwise an error is reported. The order of the multiple publication name switches must match the order of database switches. If this option is not specified, a generated name is assigned to the publication name. This option cannot be used together with --all ."},{"signature":{"text":"--replication-slot= name","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"The replication slot name to set up the logical replication. Multiple replication slots can be specified by writing multiple --replication-slot switches. The number of replication slot names must match the number of specified databases, otherwise an error is reported. The order of the multiple replication slot name switches must match the order of database switches. If this option is not specified, the subscription name is assigned to the replication slot name. This option cannot be used together with --all ."},{"signature":{"text":"--subscription= name","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"The subscription name to set up the logical replication. Multiple subscriptions can be specified by writing multiple --subscription switches. The number of subscription names must match the number of specified databases, otherwise an error is reported. The order of the multiple subscription name switches must match the order of database switches. If this option is not specified, a generated name is assigned to the subscription name. This option cannot be used together with --all ."},{"signature":{"text":"-V --version","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"Print the pg_createsubscriber version and exit."},{"signature":{"text":"-? --help","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"Show help about pg_createsubscriber command line arguments, and exit."}],"title":"Documented options"}]},"ManualEvidence":{"manual_path":"app-pgcreatesubscriber.html","release":{"channel":"stable","evidence_kind":"English manual and source declarations","label":"18.6","major":"18","manifest":{"index":"index.html","major":"18","pages":1148,"pdf":{"A4":{"built_at":"2026-09-26","bytes":15865106,"pages":3154,"sha256":"19512c405da53f9f7fcf0abba359223aa65f021be025bf3411381918f92e3190","url":"/files/documentation/pdf/18/postgresql-18-A4.pdf"},"US":{"built_at":"2026-09-26","bytes":15748059,"pages":3328,"sha256":"facbe6c229e598b872d3d98bef53308f46e06746006fa4590de9a7de9dd46319","url":"/files/documentation/pdf/18/postgresql-18-US.pdf"}},"release":"18.6","source_mode":"en SGML built with pinned official archive","source_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","source_url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2","svg_assets":3,"tree":"18"},"ref":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2","revision":"ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8","source_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f"},"sources":[{"anchor":"","file":"app-pgcreatesubscriber.html","label":"18.6 English manual · app-pgcreatesubscriber.html","sha256":"fb0e5cd7f37044410e06deb436d7b70a1bceffbd849ce10f468351d9cf11d385","url":"/docs/18/app-pgcreatesubscriber.html"},{"anchor":"","file":"reference-server.html","label":"Server applications inventory","sha256":"e9f8bbcc8e3641fadd1d20991e8aad6b532155b786ba5a1b7b364ec4f1a5bef3","url":"/docs/18/reference-server.html"}]},"MeasuredEvidence":{}},"Text":{"Collection":"tool","Key":"pg-createsubscriber","SourceDatabase":"center","Version":"18","Locale":"en","Title":"pg_createsubscriber","Summary":"pg_createsubscriber — convert a physical replica into a new logical replica","BodyHTML":"\u003cdiv\u003e\u003cdiv id=\"APP-PGCREATESUBSCRIBER\"\u003e\n\u003cdiv\u003e\u003c/div\u003e\n\u003cdiv\u003e\n\u003ch2\u003e\u003cspan\u003e\u003cspan\u003epg_createsubscriber\u003c/span\u003e\u003c/span\u003e\u003c/h2\u003e\n\u003cp\u003epg_createsubscriber — convert a physical replica into a new logical replica\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv\u003e\n\u003ch2\u003eSynopsis\u003c/h2\u003e\n\u003cdiv\u003e\n\u003cp id=\"id-1.9.5.7.4.1\"\u003e\u003ccode\u003epg_createsubscriber\u003c/code\u003e [\u003cem\u003e\u003ccode\u003eoption\u003c/code\u003e\u003c/em\u003e...] { \u003ccode\u003e-d\u003c/code\u003e | \u003ccode\u003e--database\u003c/code\u003e }\u003cem\u003e\u003ccode\u003edbname\u003c/code\u003e\u003c/em\u003e { \u003ccode\u003e-D\u003c/code\u003e | \u003ccode\u003e--pgdata\u003c/code\u003e }\u003cem\u003e\u003ccode\u003edatadir\u003c/code\u003e\u003c/em\u003e { \u003ccode\u003e-P\u003c/code\u003e | \u003ccode\u003e--publisher-server\u003c/code\u003e }\u003cem\u003e\u003ccode\u003econnstr\u003c/code\u003e\u003c/em\u003e\u003c/p\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv id=\"id-1.9.5.7.5\"\u003e\n\u003ch2\u003eDescription\u003c/h2\u003e\n\u003cp\u003e\u003cspan\u003epg_createsubscriber\u003c/span\u003e creates a new logical replica from a physical standby server. All tables in the specified database are included in the \u003ca href=\"/docs/18/logical-replication.html\" rel=\"nofollow\"\u003elogical replication\u003c/a\u003e setup. A pair of publication and subscription objects are created for each database. It must be run at the target server.\u003c/p\u003e\n\u003cp\u003eAfter a successful run, the state of the target server is analogous to a fresh logical replication setup. The main difference between the logical replication setup and \u003cspan\u003epg_createsubscriber\u003c/span\u003e is how the data synchronization is done. \u003cspan\u003epg_createsubscriber\u003c/span\u003e does not copy the initial table data. It does only the synchronization phase, which ensures each table is brought up to a synchronized state.\u003c/p\u003e\n\u003cp\u003e\u003cspan\u003epg_createsubscriber\u003c/span\u003e targets large database systems because in logical replication setup, most of the time is spent doing the initial data copy. Furthermore, a side effect of this long time spent synchronizing data is usually a large amount of changes to be applied (that were produced during the initial data copy), which increases even more the time when the logical replica will be available. For smaller databases, it is recommended to set up logical replication with initial data synchronization. For details, see the \u003ccode\u003eCREATE SUBSCRIPTION\u003c/code\u003e \u003ca href=\"/docs/18/sql-createsubscription.html#SQL-CREATESUBSCRIPTION-PARAMS-WITH-COPY-DATA\" rel=\"nofollow\"\u003e\u003ccode\u003ecopy_data\u003c/code\u003e\u003c/a\u003e option.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv id=\"id-1.9.5.7.6\"\u003e\n\u003ch2\u003eOptions\u003c/h2\u003e\n\u003cp\u003e\u003cspan\u003epg_createsubscriber\u003c/span\u003e accepts the following command-line arguments:\u003c/p\u003e\n\u003cdiv\u003e\n\u003cdl\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e-a\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e--all\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eCreate one subscription per database on the target server. Exceptions are template databases and databases that don\u0026#39;t allow connections. To discover the list of all databases, connect to the source server using the database name specified in the \u003ccode\u003e--publisher-server\u003c/code\u003e connection string, or if not specified, the \u003ccode\u003epostgres\u003c/code\u003e database will be used, or if that does not exist, \u003ccode\u003etemplate1\u003c/code\u003e will be used. Automatically generated names for subscriptions, publications, and replication slots are used when this option is specified. This option cannot be used along with \u003ccode\u003e--database\u003c/code\u003e, \u003ccode\u003e--publication\u003c/code\u003e, \u003ccode\u003e--replication-slot\u003c/code\u003e, or \u003ccode\u003e--subscription\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e-d \u003cem\u003e\u003ccode\u003edbname\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e--database=\u003cem\u003e\u003ccode\u003edbname\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe name of the database in which to create a subscription. Multiple databases can be selected by writing multiple \u003ccode\u003e-d\u003c/code\u003e switches. This option cannot be used together with \u003ccode\u003e-a\u003c/code\u003e. If \u003ccode\u003e-d\u003c/code\u003e option is not provided, the database name will be obtained from \u003ccode\u003e-P\u003c/code\u003e option. If the database name is not specified in either the \u003ccode\u003e-d\u003c/code\u003e option, or the \u003ccode\u003e-P\u003c/code\u003e option, and \u003ccode\u003e-a\u003c/code\u003e option is not specified, an error will be reported.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e-D \u003cem\u003e\u003ccode\u003edirectory\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e--pgdata=\u003cem\u003e\u003ccode\u003edirectory\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe target directory that contains a cluster directory from a physical replica.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e-n\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e--dry-run\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eDo everything except actually modifying the target directory.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e-p \u003cem\u003e\u003ccode\u003eport\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e--subscriber-port=\u003cem\u003e\u003ccode\u003eport\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe port number on which the target server is listening for connections. Defaults to running the target server on port 50432 to avoid unintended client connections.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e-P \u003cem\u003e\u003ccode\u003econnstr\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e--publisher-server=\u003cem\u003e\u003ccode\u003econnstr\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe connection string to the publisher. For details see \u003ca href=\"/docs/18/libpq-connect.html#LIBPQ-CONNSTRING\" rel=\"nofollow\"\u003eSection 32.1.1\u003c/a\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e-s \u003cem\u003e\u003ccode\u003edir\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e--socketdir=\u003cem\u003e\u003ccode\u003edir\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe directory to use for postmaster sockets on target server. The default is current directory.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e-t \u003cem\u003e\u003ccode\u003eseconds\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e--recovery-timeout=\u003cem\u003e\u003ccode\u003eseconds\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe maximum number of seconds to wait for recovery to end. Setting to 0 disables. The default is 0.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e-T\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e--enable-two-phase\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eEnables \u003ca href=\"/docs/18/sql-createsubscription.html#SQL-CREATESUBSCRIPTION-PARAMS-WITH-TWO-PHASE\" rel=\"nofollow\"\u003e\u003ccode\u003etwo_phase\u003c/code\u003e\u003c/a\u003e commit for the subscription. When multiple databases are specified, this option applies uniformly to all subscriptions created on those databases. The default is \u003ccode\u003efalse\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e-U \u003cem\u003e\u003ccode\u003eusername\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e--subscriber-username=\u003cem\u003e\u003ccode\u003eusername\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe user name to connect as on target server. Defaults to the current operating system user name.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e-v\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e--verbose\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eEnables verbose mode. This will cause \u003cspan\u003epg_createsubscriber\u003c/span\u003e to output progress messages and detailed information about each step to standard error. Repeating the option causes additional debug-level messages to appear on standard error.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e--clean=\u003cem\u003e\u003ccode\u003eobjtype\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eDrop all objects of the specified type from specified databases on the target server.\u003c/p\u003e\n\u003cdiv\u003e\n\u003cul\u003e\n\u003cli\u003e\n\u003cp\u003e\u003ccode\u003epublications\u003c/code\u003e: The \u003ccode\u003eFOR ALL TABLES\u003c/code\u003e publications established for this subscriber are always dropped; specifying this object type causes all other publications replicated from the source server to be dropped as well.\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/div\u003e\n\u003cp\u003eThe objects selected to be dropped are individually logged, including during a \u003ccode\u003e--dry-run\u003c/code\u003e. There is no opportunity to affect or stop the dropping of the selected objects, so consider taking a backup of them using \u003cspan\u003epg_dump\u003c/span\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e--config-file=\u003cem\u003e\u003ccode\u003efilename\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eUse the specified main server configuration file for the target data directory. \u003cspan\u003epg_createsubscriber\u003c/span\u003e internally uses the \u003cspan\u003epg_ctl\u003c/span\u003e command to start and stop the target server. It allows you to specify the actual \u003ccode\u003epostgresql.conf\u003c/code\u003e configuration file if it is stored outside the data directory.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e--publication=\u003cem\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe publication name to set up the logical replication. Multiple publications can be specified by writing multiple \u003ccode\u003e--publication\u003c/code\u003e switches. The number of publication names must match the number of specified databases, otherwise an error is reported. The order of the multiple publication name switches must match the order of database switches. If this option is not specified, a generated name is assigned to the publication name. This option cannot be used together with \u003ccode\u003e--all\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e--replication-slot=\u003cem\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe replication slot name to set up the logical replication. Multiple replication slots can be specified by writing multiple \u003ccode\u003e--replication-slot\u003c/code\u003e switches. The number of replication slot names must match the number of specified databases, otherwise an error is reported. The order of the multiple replication slot name switches must match the order of database switches. If this option is not specified, the subscription name is assigned to the replication slot name. This option cannot be used together with \u003ccode\u003e--all\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e--subscription=\u003cem\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe subscription name to set up the logical replication. Multiple subscriptions can be specified by writing multiple \u003ccode\u003e--subscription\u003c/code\u003e switches. The number of subscription names must match the number of specified databases, otherwise an error is reported. The order of the multiple subscription name switches must match the order of database switches. If this option is not specified, a generated name is assigned to the subscription name. This option cannot be used together with \u003ccode\u003e--all\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e-V\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e--version\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003ePrint the \u003cspan\u003epg_createsubscriber\u003c/span\u003e version and exit.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e-?\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e--help\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eShow help about \u003cspan\u003epg_createsubscriber\u003c/span\u003e command line arguments, and exit.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv id=\"id-1.9.5.7.7\"\u003e\n\u003ch2\u003eNotes\u003c/h2\u003e\n\u003cdiv id=\"id-1.9.5.7.7.2\"\u003e\n\u003ch3\u003ePrerequisites\u003c/h3\u003e\n\u003cp\u003eThere are some prerequisites for \u003cspan\u003epg_createsubscriber\u003c/span\u003e to convert the target server into a logical replica. If these are not met, an error will be reported. The source and target servers must have the same major version as the \u003cspan\u003epg_createsubscriber\u003c/span\u003e. The given target data directory must have the same system identifier as the source data directory. The given database user for the target data directory must have privileges for creating \u003ca href=\"/docs/18/sql-createsubscription.html\" title=\"CREATE SUBSCRIPTION\" rel=\"nofollow\"\u003esubscriptions\u003c/a\u003e and using \u003ca href=\"/docs/18/functions-admin.html#PG-REPLICATION-ORIGIN-ADVANCE\" rel=\"nofollow\"\u003e\u003ccode\u003epg_replication_origin_advance()\u003c/code\u003e\u003c/a\u003e.\u003c/p\u003e\n\u003cp\u003eThe target server must be used as a physical standby. The target server must have \u003ca href=\"/docs/18/runtime-config-replication.html#GUC-MAX-ACTIVE-REPLICATION-ORIGINS\" rel=\"nofollow\"\u003emax_active_replication_origins\u003c/a\u003e and \u003ca href=\"/docs/18/runtime-config-replication.html#GUC-MAX-LOGICAL-REPLICATION-WORKERS\" rel=\"nofollow\"\u003emax_logical_replication_workers\u003c/a\u003e configured to a value greater than or equal to the number of specified databases. The target server must have \u003ca href=\"/docs/18/runtime-config-resource.html#GUC-MAX-WORKER-PROCESSES\" rel=\"nofollow\"\u003emax_worker_processes\u003c/a\u003e configured to a value greater than the number of specified databases. The target server must accept local connections. If you are planning to use the \u003ccode\u003e--enable-two-phase\u003c/code\u003e switch then you will also need to set the \u003ca href=\"/docs/18/runtime-config-resource.html#GUC-MAX-PREPARED-TRANSACTIONS\" rel=\"nofollow\"\u003emax_prepared_transactions\u003c/a\u003e appropriately.\u003c/p\u003e\n\u003cp\u003eThe source server must accept connections from the target server. The source server must not be in recovery. The source server must have \u003ca href=\"/docs/18/runtime-config-wal.html#GUC-WAL-LEVEL\" rel=\"nofollow\"\u003ewal_level\u003c/a\u003e as \u003ccode\u003elogical\u003c/code\u003e. The source server must have \u003ca href=\"/docs/18/runtime-config-replication.html#GUC-MAX-REPLICATION-SLOTS\" rel=\"nofollow\"\u003emax_replication_slots\u003c/a\u003e configured to a value greater than or equal to the number of specified databases plus existing replication slots. The source server must have \u003ca href=\"/docs/18/runtime-config-replication.html#GUC-MAX-WAL-SENDERS\" rel=\"nofollow\"\u003emax_wal_senders\u003c/a\u003e configured to a value greater than or equal to the number of specified databases and existing WAL sender processes.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv id=\"id-1.9.5.7.7.3\"\u003e\n\u003ch3\u003eWarnings\u003c/h3\u003e\n\u003cp\u003eIf \u003cspan\u003epg_createsubscriber\u003c/span\u003e fails after the target server was promoted, then the data directory is likely not in a state that can be recovered. In such case, creating a new standby server is recommended.\u003c/p\u003e\n\u003cp\u003e\u003cspan\u003epg_createsubscriber\u003c/span\u003e usually starts the target server with different connection settings during transformation. Hence, connections to the target server should fail.\u003c/p\u003e\n\u003cp\u003eSince DDL commands are not replicated by logical replication, avoid executing DDL commands that change the database schema while running \u003cspan\u003epg_createsubscriber\u003c/span\u003e. If the target server has already been converted to logical replica, the DDL commands might not be replicated, which might cause an error.\u003c/p\u003e\n\u003cp\u003eIf \u003cspan\u003epg_createsubscriber\u003c/span\u003e fails while processing, objects (publications, replication slots) created on the source server are removed. The removal might fail if the target server cannot connect to the source server. In such a case, a warning message will inform the objects left. If the target server is running, it will be stopped.\u003c/p\u003e\n\u003cp\u003eIf the replication is using \u003ca href=\"/docs/18/runtime-config-replication.html#GUC-PRIMARY-SLOT-NAME\" rel=\"nofollow\"\u003eprimary_slot_name\u003c/a\u003e, it will be removed from the source server after the logical replication setup.\u003c/p\u003e\n\u003cp\u003eIf the target server is a synchronous replica, transaction commits on the primary might wait for replication while running \u003cspan\u003epg_createsubscriber\u003c/span\u003e.\u003c/p\u003e\n\u003cp\u003eUnless the \u003ccode\u003e--enable-two-phase\u003c/code\u003e switch is specified, \u003cspan\u003epg_createsubscriber\u003c/span\u003e sets up logical replication with two-phase commit disabled. This means that any prepared transactions will be replicated at the time of \u003ccode\u003eCOMMIT PREPARED\u003c/code\u003e, without advance preparation. Once setup is complete, you can manually drop and re-create the subscription(s) with the \u003ca href=\"/docs/18/sql-createsubscription.html#SQL-CREATESUBSCRIPTION-PARAMS-WITH-TWO-PHASE\" rel=\"nofollow\"\u003e\u003ccode\u003etwo_phase\u003c/code\u003e\u003c/a\u003e option enabled.\u003c/p\u003e\n\u003cp\u003e\u003cspan\u003epg_createsubscriber\u003c/span\u003e changes the system identifier using \u003cspan\u003epg_resetwal\u003c/span\u003e. It would avoid situations in which the target server might use WAL files from the source server. If the target server has a standby, replication will break and a fresh standby should be created.\u003c/p\u003e\n\u003cp\u003eReplication failures can occur if required WAL files are missing. To prevent this, the source server must set \u003ca href=\"/docs/18/runtime-config-replication.html#GUC-MAX-SLOT-WAL-KEEP-SIZE\" rel=\"nofollow\"\u003emax_slot_wal_keep_size\u003c/a\u003e to \u003ccode\u003e-1\u003c/code\u003e to ensure that required WAL files are not prematurely removed.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv id=\"id-1.9.5.7.7.4\"\u003e\n\u003ch3\u003eHow It Works\u003c/h3\u003e\n\u003cp\u003eThe basic idea is to have a replication start point from the source server and set up a logical replication to start from this point:\u003c/p\u003e\n\u003cdiv\u003e\n\u003col\u003e\n\u003cli\u003e\n\u003cp\u003eStart the target server with the specified command-line options. If the target server is already running, \u003cspan\u003epg_createsubscriber\u003c/span\u003e will terminate with an error.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003eCheck if the target server can be converted. There are also a few checks on the source server. If any of the prerequisites are not met, \u003cspan\u003epg_createsubscriber\u003c/span\u003e will terminate with an error.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003eCreate a publication and replication slot for each specified database on the source server. Each publication is created using \u003ca href=\"/docs/18/sql-createpublication.html#SQL-CREATEPUBLICATION-PARAMS-FOR-ALL-TABLES\" rel=\"nofollow\"\u003e\u003ccode\u003eFOR ALL TABLES\u003c/code\u003e\u003c/a\u003e. If the \u003ccode\u003e--publication\u003c/code\u003e option is not specified, the publication has the following name pattern: \u003cspan\u003e“\u003cspan\u003e\u003ccode\u003epg_createsubscriber_%u_%x\u003c/code\u003e\u003c/span\u003e”\u003c/span\u003e (parameter: database \u003cem\u003e\u003ccode\u003eoid\u003c/code\u003e\u003c/em\u003e, random \u003cem\u003e\u003ccode\u003eint\u003c/code\u003e\u003c/em\u003e). If the \u003ccode\u003e--replication-slot\u003c/code\u003e option is not specified, the replication slot has the following name pattern: \u003cspan\u003e“\u003cspan\u003e\u003ccode\u003epg_createsubscriber_%u_%x\u003c/code\u003e\u003c/span\u003e”\u003c/span\u003e (parameters: database \u003cem\u003e\u003ccode\u003eoid\u003c/code\u003e\u003c/em\u003e, random \u003cem\u003e\u003ccode\u003eint\u003c/code\u003e\u003c/em\u003e). These replication slots will be used by the subscriptions in a future step. The last replication slot LSN is used as a stopping point in the \u003ca href=\"/docs/18/runtime-config-wal.html#GUC-RECOVERY-TARGET-LSN\" rel=\"nofollow\"\u003erecovery_target_lsn\u003c/a\u003e parameter and by the subscriptions as a replication start point. It guarantees that no transaction will be lost.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003eWrite recovery parameters into the target data directory and restart the target server. It specifies an LSN (\u003ca href=\"/docs/18/runtime-config-wal.html#GUC-RECOVERY-TARGET-LSN\" rel=\"nofollow\"\u003erecovery_target_lsn\u003c/a\u003e) of the write-ahead log location up to which recovery will proceed. It also specifies \u003ccode\u003epromote\u003c/code\u003e as the action that the server should take once the recovery target is reached. Additional \u003ca href=\"/docs/18/runtime-config-wal.html#RUNTIME-CONFIG-WAL-RECOVERY-TARGET\" rel=\"nofollow\"\u003erecovery parameters\u003c/a\u003e are added to avoid unexpected behavior during the recovery process such as end of the recovery as soon as a consistent state is reached (WAL should be applied until the replication start location) and multiple recovery targets that can cause a failure. This step finishes once the server ends standby mode and is accepting read-write transactions. If \u003ccode\u003e--recovery-timeout\u003c/code\u003e option is set, \u003cspan\u003epg_createsubscriber\u003c/span\u003e terminates if recovery does not end until the given number of seconds.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003eCreate a subscription for each specified database on the target server. If the \u003ccode\u003e--subscription\u003c/code\u003e option is not specified, the subscription has the following name pattern: \u003cspan\u003e“\u003cspan\u003e\u003ccode\u003epg_createsubscriber_%u_%x\u003c/code\u003e\u003c/span\u003e”\u003c/span\u003e (parameters: database \u003cem\u003e\u003ccode\u003eoid\u003c/code\u003e\u003c/em\u003e, random \u003cem\u003e\u003ccode\u003eint\u003c/code\u003e\u003c/em\u003e). It does not copy existing data from the source server. It does not create a replication slot. Instead, it uses the replication slot that was created in a previous step. The subscription is created but it is not enabled yet. The reason is the replication progress must be set to the replication start point before starting the replication.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003eDrop publications on the target server that were replicated because they were created before the replication start location. It has no use on the subscriber.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003eSet the replication progress to the replication start point for each subscription. When the target server starts the recovery process, it catches up to the replication start point. This is the exact LSN to be used as a initial replication location for each subscription. The replication origin name is obtained since the subscription was created. The replication origin name and the replication start point are used in \u003ca href=\"/docs/18/functions-admin.html#PG-REPLICATION-ORIGIN-ADVANCE\" rel=\"nofollow\"\u003e\u003ccode\u003epg_replication_origin_advance()\u003c/code\u003e\u003c/a\u003e to set up the initial replication location.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003eEnable the subscription for each specified database on the target server. The subscription starts applying transactions from the replication start point.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003eIf the standby server was using \u003ca href=\"/docs/18/runtime-config-replication.html#GUC-PRIMARY-SLOT-NAME\" rel=\"nofollow\"\u003eprimary_slot_name\u003c/a\u003e, it has no use from now on so drop it.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003eIf the standby server contains \u003ca href=\"/docs/18/logicaldecoding-explanation.html#LOGICALDECODING-REPLICATION-SLOTS-SYNCHRONIZATION\" rel=\"nofollow\"\u003efailover replication slots\u003c/a\u003e, they cannot be synchronized anymore, so drop them.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003eUpdate the system identifier on the target server. The \u003ca href=\"/docs/18/app-pgresetwal.html\" title=\"pg_resetwal\" rel=\"nofollow\"\u003e\u003cspan\u003e\u003cspan\u003epg_resetwal\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e is run to modify the system identifier. The target server is stopped as a \u003ccode\u003epg_resetwal\u003c/code\u003e requirement.\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ol\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv id=\"id-1.9.5.7.8\"\u003e\n\u003ch2\u003eExamples\u003c/h2\u003e\n\u003cp\u003eTo create a logical replica for databases \u003ccode\u003ehr\u003c/code\u003e and \u003ccode\u003efinance\u003c/code\u003e from a physical replica at \u003ccode\u003efoo\u003c/code\u003e:\u003c/p\u003e\n\u003cpre\u003e\u003ccode\u003e$\u003c/code\u003e \u003cstrong\u003e\u003ccode\u003epg_createsubscriber -D /usr/local/pgsql/data -P \u0026#34;host=foo\u0026#34; -d hr -d finance\u003c/code\u003e\u003c/strong\u003e\n\u003c/pre\u003e\n\u003c/div\u003e\n\u003cdiv id=\"id-1.9.5.7.9\"\u003e\n\u003ch2\u003eSee Also\u003c/h2\u003e\u003cspan\u003e\u003ca href=\"/docs/18/app-pgbasebackup.html\" title=\"pg_basebackup\" rel=\"nofollow\"\u003e\u003cspan\u003e\u003cspan\u003epg_basebackup\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e\n\u003c/div\u003e\n\u003c/div\u003e\u003c/div\u003e","SourceRevision":"ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8","ContentHash":"d0c3c065af3128910bdbf7d2ccf6e9f9b681d70ed161191e502c911b206a43ae","Payload":{"description":["pg_createsubscriber — convert a physical replica into a new logical replica"],"manual_html":"\u003cdiv\u003e\u003cdiv class=\"refentry\" id=\"APP-PGCREATESUBSCRIBER\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\u003c/div\u003e\n\u003cdiv class=\"refnamediv\"\u003e\n\u003ch2\u003e\u003cspan class=\"refentrytitle\"\u003e\u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e\u003c/span\u003e\u003c/h2\u003e\n\u003cp\u003epg_createsubscriber — convert a physical replica into a new logical replica\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsynopsisdiv\"\u003e\n\u003ch2\u003eSynopsis\u003c/h2\u003e\n\u003cdiv class=\"cmdsynopsis\"\u003e\n\u003cp id=\"id-1.9.5.7.4.1\"\u003e\u003ccode class=\"command\"\u003epg_createsubscriber\u003c/code\u003e [\u003cem class=\"replaceable\"\u003e\u003ccode\u003eoption\u003c/code\u003e\u003c/em\u003e...] { \u003ccode class=\"option\"\u003e-d\u003c/code\u003e | \u003ccode class=\"option\"\u003e--database\u003c/code\u003e }\u003cem class=\"replaceable\"\u003e\u003ccode\u003edbname\u003c/code\u003e\u003c/em\u003e { \u003ccode class=\"option\"\u003e-D\u003c/code\u003e | \u003ccode class=\"option\"\u003e--pgdata\u003c/code\u003e }\u003cem class=\"replaceable\"\u003e\u003ccode\u003edatadir\u003c/code\u003e\u003c/em\u003e { \u003ccode class=\"option\"\u003e-P\u003c/code\u003e | \u003ccode class=\"option\"\u003e--publisher-server\u003c/code\u003e }\u003cem class=\"replaceable\"\u003e\u003ccode\u003econnstr\u003c/code\u003e\u003c/em\u003e\u003c/p\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsect1\" id=\"id-1.9.5.7.5\"\u003e\n\u003ch2\u003eDescription\u003c/h2\u003e\n\u003cp\u003e\u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e creates a new logical replica from a physical standby server. All tables in the specified database are included in the \u003ca class=\"link\" href=\"/docs/18/logical-replication.html\" title=\"Chapter 29. Logical Replication\"\u003elogical replication\u003c/a\u003e setup. A pair of publication and subscription objects are created for each database. It must be run at the target server.\u003c/p\u003e\n\u003cp\u003eAfter a successful run, the state of the target server is analogous to a fresh logical replication setup. The main difference between the logical replication setup and \u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e is how the data synchronization is done. \u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e does not copy the initial table data. It does only the synchronization phase, which ensures each table is brought up to a synchronized state.\u003c/p\u003e\n\u003cp\u003e\u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e targets large database systems because in logical replication setup, most of the time is spent doing the initial data copy. Furthermore, a side effect of this long time spent synchronizing data is usually a large amount of changes to be applied (that were produced during the initial data copy), which increases even more the time when the logical replica will be available. For smaller databases, it is recommended to set up logical replication with initial data synchronization. For details, see the \u003ccode class=\"command\"\u003eCREATE SUBSCRIPTION\u003c/code\u003e \u003ca class=\"link\" href=\"/docs/18/sql-createsubscription.html#SQL-CREATESUBSCRIPTION-PARAMS-WITH-COPY-DATA\"\u003e\u003ccode class=\"literal\"\u003ecopy_data\u003c/code\u003e\u003c/a\u003e option.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsect1\" id=\"id-1.9.5.7.6\"\u003e\n\u003ch2\u003eOptions\u003c/h2\u003e\n\u003cp\u003e\u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e accepts the following command-line arguments:\u003c/p\u003e\n\u003cdiv class=\"variablelist\"\u003e\n\u003cdl class=\"variablelist\"\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-a\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--all\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eCreate one subscription per database on the target server. Exceptions are template databases and databases that don't allow connections. To discover the list of all databases, connect to the source server using the database name specified in the \u003ccode class=\"option\"\u003e--publisher-server\u003c/code\u003e connection string, or if not specified, the \u003ccode class=\"literal\"\u003epostgres\u003c/code\u003e database will be used, or if that does not exist, \u003ccode class=\"literal\"\u003etemplate1\u003c/code\u003e will be used. Automatically generated names for subscriptions, publications, and replication slots are used when this option is specified. This option cannot be used along with \u003ccode class=\"option\"\u003e--database\u003c/code\u003e, \u003ccode class=\"option\"\u003e--publication\u003c/code\u003e, \u003ccode class=\"option\"\u003e--replication-slot\u003c/code\u003e, or \u003ccode class=\"option\"\u003e--subscription\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-d \u003cem class=\"replaceable\"\u003e\u003ccode\u003edbname\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--database=\u003cem class=\"replaceable\"\u003e\u003ccode\u003edbname\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe name of the database in which to create a subscription. Multiple databases can be selected by writing multiple \u003ccode class=\"option\"\u003e-d\u003c/code\u003e switches. This option cannot be used together with \u003ccode class=\"option\"\u003e-a\u003c/code\u003e. If \u003ccode class=\"option\"\u003e-d\u003c/code\u003e option is not provided, the database name will be obtained from \u003ccode class=\"option\"\u003e-P\u003c/code\u003e option. If the database name is not specified in either the \u003ccode class=\"option\"\u003e-d\u003c/code\u003e option, or the \u003ccode class=\"option\"\u003e-P\u003c/code\u003e option, and \u003ccode class=\"option\"\u003e-a\u003c/code\u003e option is not specified, an error will be reported.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-D \u003cem class=\"replaceable\"\u003e\u003ccode\u003edirectory\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--pgdata=\u003cem class=\"replaceable\"\u003e\u003ccode\u003edirectory\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe target directory that contains a cluster directory from a physical replica.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-n\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--dry-run\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eDo everything except actually modifying the target directory.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-p \u003cem class=\"replaceable\"\u003e\u003ccode\u003eport\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--subscriber-port=\u003cem class=\"replaceable\"\u003e\u003ccode\u003eport\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe port number on which the target server is listening for connections. Defaults to running the target server on port 50432 to avoid unintended client connections.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-P \u003cem class=\"replaceable\"\u003e\u003ccode\u003econnstr\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--publisher-server=\u003cem class=\"replaceable\"\u003e\u003ccode\u003econnstr\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe connection string to the publisher. For details see \u003ca class=\"xref\" href=\"/docs/18/libpq-connect.html#LIBPQ-CONNSTRING\" title=\"32.1.1. Connection Strings\"\u003eSection 32.1.1\u003c/a\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-s \u003cem class=\"replaceable\"\u003e\u003ccode\u003edir\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--socketdir=\u003cem class=\"replaceable\"\u003e\u003ccode\u003edir\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe directory to use for postmaster sockets on target server. The default is current directory.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-t \u003cem class=\"replaceable\"\u003e\u003ccode\u003eseconds\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--recovery-timeout=\u003cem class=\"replaceable\"\u003e\u003ccode\u003eseconds\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe maximum number of seconds to wait for recovery to end. Setting to 0 disables. The default is 0.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-T\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--enable-two-phase\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eEnables \u003ca class=\"link\" href=\"/docs/18/sql-createsubscription.html#SQL-CREATESUBSCRIPTION-PARAMS-WITH-TWO-PHASE\"\u003e\u003ccode class=\"literal\"\u003etwo_phase\u003c/code\u003e\u003c/a\u003e commit for the subscription. When multiple databases are specified, this option applies uniformly to all subscriptions created on those databases. The default is \u003ccode class=\"literal\"\u003efalse\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-U \u003cem class=\"replaceable\"\u003e\u003ccode\u003eusername\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--subscriber-username=\u003cem class=\"replaceable\"\u003e\u003ccode\u003eusername\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe user name to connect as on target server. Defaults to the current operating system user name.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-v\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--verbose\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eEnables verbose mode. This will cause \u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e to output progress messages and detailed information about each step to standard error. Repeating the option causes additional debug-level messages to appear on standard error.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--clean=\u003cem class=\"replaceable\"\u003e\u003ccode\u003eobjtype\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eDrop all objects of the specified type from specified databases on the target server.\u003c/p\u003e\n\u003cdiv class=\"itemizedlist\"\u003e\n\u003cul class=\"itemizedlist\"\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003e\u003ccode class=\"literal\"\u003epublications\u003c/code\u003e: The \u003ccode class=\"literal\"\u003eFOR ALL TABLES\u003c/code\u003e publications established for this subscriber are always dropped; specifying this object type causes all other publications replicated from the source server to be dropped as well.\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/div\u003e\n\u003cp\u003eThe objects selected to be dropped are individually logged, including during a \u003ccode class=\"option\"\u003e--dry-run\u003c/code\u003e. There is no opportunity to affect or stop the dropping of the selected objects, so consider taking a backup of them using \u003cspan class=\"application\"\u003epg_dump\u003c/span\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--config-file=\u003cem class=\"replaceable\"\u003e\u003ccode\u003efilename\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eUse the specified main server configuration file for the target data directory. \u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e internally uses the \u003cspan class=\"application\"\u003epg_ctl\u003c/span\u003e command to start and stop the target server. It allows you to specify the actual \u003ccode class=\"filename\"\u003epostgresql.conf\u003c/code\u003e configuration file if it is stored outside the data directory.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--publication=\u003cem class=\"replaceable\"\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe publication name to set up the logical replication. Multiple publications can be specified by writing multiple \u003ccode class=\"option\"\u003e--publication\u003c/code\u003e switches. The number of publication names must match the number of specified databases, otherwise an error is reported. The order of the multiple publication name switches must match the order of database switches. If this option is not specified, a generated name is assigned to the publication name. This option cannot be used together with \u003ccode class=\"option\"\u003e--all\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--replication-slot=\u003cem class=\"replaceable\"\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe replication slot name to set up the logical replication. Multiple replication slots can be specified by writing multiple \u003ccode class=\"option\"\u003e--replication-slot\u003c/code\u003e switches. The number of replication slot names must match the number of specified databases, otherwise an error is reported. The order of the multiple replication slot name switches must match the order of database switches. If this option is not specified, the subscription name is assigned to the replication slot name. This option cannot be used together with \u003ccode class=\"option\"\u003e--all\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--subscription=\u003cem class=\"replaceable\"\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe subscription name to set up the logical replication. Multiple subscriptions can be specified by writing multiple \u003ccode class=\"option\"\u003e--subscription\u003c/code\u003e switches. The number of subscription names must match the number of specified databases, otherwise an error is reported. The order of the multiple subscription name switches must match the order of database switches. If this option is not specified, a generated name is assigned to the subscription name. This option cannot be used together with \u003ccode class=\"option\"\u003e--all\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-V\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--version\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003ePrint the \u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e version and exit.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-?\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--help\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eShow help about \u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e command line arguments, and exit.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsect1\" id=\"id-1.9.5.7.7\"\u003e\n\u003ch2\u003eNotes\u003c/h2\u003e\n\u003cdiv class=\"refsect2\" id=\"id-1.9.5.7.7.2\"\u003e\n\u003ch3\u003ePrerequisites\u003c/h3\u003e\n\u003cp\u003eThere are some prerequisites for \u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e to convert the target server into a logical replica. If these are not met, an error will be reported. The source and target servers must have the same major version as the \u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e. The given target data directory must have the same system identifier as the source data directory. The given database user for the target data directory must have privileges for creating \u003ca class=\"link\" href=\"/docs/18/sql-createsubscription.html\" title=\"CREATE SUBSCRIPTION\"\u003esubscriptions\u003c/a\u003e and using \u003ca class=\"link\" href=\"/docs/18/functions-admin.html#PG-REPLICATION-ORIGIN-ADVANCE\"\u003e\u003ccode class=\"function\"\u003epg_replication_origin_advance()\u003c/code\u003e\u003c/a\u003e.\u003c/p\u003e\n\u003cp\u003eThe target server must be used as a physical standby. The target server must have \u003ca class=\"xref\" href=\"/docs/18/runtime-config-replication.html#GUC-MAX-ACTIVE-REPLICATION-ORIGINS\"\u003emax_active_replication_origins\u003c/a\u003e and \u003ca class=\"xref\" href=\"/docs/18/runtime-config-replication.html#GUC-MAX-LOGICAL-REPLICATION-WORKERS\"\u003emax_logical_replication_workers\u003c/a\u003e configured to a value greater than or equal to the number of specified databases. The target server must have \u003ca class=\"xref\" href=\"/docs/18/runtime-config-resource.html#GUC-MAX-WORKER-PROCESSES\"\u003emax_worker_processes\u003c/a\u003e configured to a value greater than the number of specified databases. The target server must accept local connections. If you are planning to use the \u003ccode class=\"option\"\u003e--enable-two-phase\u003c/code\u003e switch then you will also need to set the \u003ca class=\"xref\" href=\"/docs/18/runtime-config-resource.html#GUC-MAX-PREPARED-TRANSACTIONS\"\u003emax_prepared_transactions\u003c/a\u003e appropriately.\u003c/p\u003e\n\u003cp\u003eThe source server must accept connections from the target server. The source server must not be in recovery. The source server must have \u003ca class=\"xref\" href=\"/docs/18/runtime-config-wal.html#GUC-WAL-LEVEL\"\u003ewal_level\u003c/a\u003e as \u003ccode class=\"literal\"\u003elogical\u003c/code\u003e. The source server must have \u003ca class=\"xref\" href=\"/docs/18/runtime-config-replication.html#GUC-MAX-REPLICATION-SLOTS\"\u003emax_replication_slots\u003c/a\u003e configured to a value greater than or equal to the number of specified databases plus existing replication slots. The source server must have \u003ca class=\"xref\" href=\"/docs/18/runtime-config-replication.html#GUC-MAX-WAL-SENDERS\"\u003emax_wal_senders\u003c/a\u003e configured to a value greater than or equal to the number of specified databases and existing WAL sender processes.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsect2\" id=\"id-1.9.5.7.7.3\"\u003e\n\u003ch3\u003eWarnings\u003c/h3\u003e\n\u003cp\u003eIf \u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e fails after the target server was promoted, then the data directory is likely not in a state that can be recovered. In such case, creating a new standby server is recommended.\u003c/p\u003e\n\u003cp\u003e\u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e usually starts the target server with different connection settings during transformation. Hence, connections to the target server should fail.\u003c/p\u003e\n\u003cp\u003eSince DDL commands are not replicated by logical replication, avoid executing DDL commands that change the database schema while running \u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e. If the target server has already been converted to logical replica, the DDL commands might not be replicated, which might cause an error.\u003c/p\u003e\n\u003cp\u003eIf \u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e fails while processing, objects (publications, replication slots) created on the source server are removed. The removal might fail if the target server cannot connect to the source server. In such a case, a warning message will inform the objects left. If the target server is running, it will be stopped.\u003c/p\u003e\n\u003cp\u003eIf the replication is using \u003ca class=\"xref\" href=\"/docs/18/runtime-config-replication.html#GUC-PRIMARY-SLOT-NAME\"\u003eprimary_slot_name\u003c/a\u003e, it will be removed from the source server after the logical replication setup.\u003c/p\u003e\n\u003cp\u003eIf the target server is a synchronous replica, transaction commits on the primary might wait for replication while running \u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e.\u003c/p\u003e\n\u003cp\u003eUnless the \u003ccode class=\"option\"\u003e--enable-two-phase\u003c/code\u003e switch is specified, \u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e sets up logical replication with two-phase commit disabled. This means that any prepared transactions will be replicated at the time of \u003ccode class=\"command\"\u003eCOMMIT PREPARED\u003c/code\u003e, without advance preparation. Once setup is complete, you can manually drop and re-create the subscription(s) with the \u003ca class=\"link\" href=\"/docs/18/sql-createsubscription.html#SQL-CREATESUBSCRIPTION-PARAMS-WITH-TWO-PHASE\"\u003e\u003ccode class=\"literal\"\u003etwo_phase\u003c/code\u003e\u003c/a\u003e option enabled.\u003c/p\u003e\n\u003cp\u003e\u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e changes the system identifier using \u003cspan class=\"application\"\u003epg_resetwal\u003c/span\u003e. It would avoid situations in which the target server might use WAL files from the source server. If the target server has a standby, replication will break and a fresh standby should be created.\u003c/p\u003e\n\u003cp\u003eReplication failures can occur if required WAL files are missing. To prevent this, the source server must set \u003ca class=\"xref\" href=\"/docs/18/runtime-config-replication.html#GUC-MAX-SLOT-WAL-KEEP-SIZE\"\u003emax_slot_wal_keep_size\u003c/a\u003e to \u003ccode class=\"literal\"\u003e-1\u003c/code\u003e to ensure that required WAL files are not prematurely removed.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsect2\" id=\"id-1.9.5.7.7.4\"\u003e\n\u003ch3\u003eHow It Works\u003c/h3\u003e\n\u003cp\u003eThe basic idea is to have a replication start point from the source server and set up a logical replication to start from this point:\u003c/p\u003e\n\u003cdiv class=\"procedure\"\u003e\n\u003col class=\"procedure\"\u003e\n\u003cli class=\"step\"\u003e\n\u003cp\u003eStart the target server with the specified command-line options. If the target server is already running, \u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e will terminate with an error.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp\u003eCheck if the target server can be converted. There are also a few checks on the source server. If any of the prerequisites are not met, \u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e will terminate with an error.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp\u003eCreate a publication and replication slot for each specified database on the source server. Each publication is created using \u003ca class=\"link\" href=\"/docs/18/sql-createpublication.html#SQL-CREATEPUBLICATION-PARAMS-FOR-ALL-TABLES\"\u003e\u003ccode class=\"literal\"\u003eFOR ALL TABLES\u003c/code\u003e\u003c/a\u003e. If the \u003ccode class=\"option\"\u003e--publication\u003c/code\u003e option is not specified, the publication has the following name pattern: \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003e\u003ccode class=\"literal\"\u003epg_createsubscriber_%u_%x\u003c/code\u003e\u003c/span\u003e”\u003c/span\u003e (parameter: database \u003cem class=\"parameter\"\u003e\u003ccode\u003eoid\u003c/code\u003e\u003c/em\u003e, random \u003cem class=\"parameter\"\u003e\u003ccode\u003eint\u003c/code\u003e\u003c/em\u003e). If the \u003ccode class=\"option\"\u003e--replication-slot\u003c/code\u003e option is not specified, the replication slot has the following name pattern: \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003e\u003ccode class=\"literal\"\u003epg_createsubscriber_%u_%x\u003c/code\u003e\u003c/span\u003e”\u003c/span\u003e (parameters: database \u003cem class=\"parameter\"\u003e\u003ccode\u003eoid\u003c/code\u003e\u003c/em\u003e, random \u003cem class=\"parameter\"\u003e\u003ccode\u003eint\u003c/code\u003e\u003c/em\u003e). These replication slots will be used by the subscriptions in a future step. The last replication slot LSN is used as a stopping point in the \u003ca class=\"xref\" href=\"/docs/18/runtime-config-wal.html#GUC-RECOVERY-TARGET-LSN\"\u003erecovery_target_lsn\u003c/a\u003e parameter and by the subscriptions as a replication start point. It guarantees that no transaction will be lost.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp\u003eWrite recovery parameters into the target data directory and restart the target server. It specifies an LSN (\u003ca class=\"xref\" href=\"/docs/18/runtime-config-wal.html#GUC-RECOVERY-TARGET-LSN\"\u003erecovery_target_lsn\u003c/a\u003e) of the write-ahead log location up to which recovery will proceed. It also specifies \u003ccode class=\"literal\"\u003epromote\u003c/code\u003e as the action that the server should take once the recovery target is reached. Additional \u003ca class=\"link\" href=\"/docs/18/runtime-config-wal.html#RUNTIME-CONFIG-WAL-RECOVERY-TARGET\" title=\"19.5.6. Recovery Target\"\u003erecovery parameters\u003c/a\u003e are added to avoid unexpected behavior during the recovery process such as end of the recovery as soon as a consistent state is reached (WAL should be applied until the replication start location) and multiple recovery targets that can cause a failure. This step finishes once the server ends standby mode and is accepting read-write transactions. If \u003ccode class=\"option\"\u003e--recovery-timeout\u003c/code\u003e option is set, \u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e terminates if recovery does not end until the given number of seconds.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp\u003eCreate a subscription for each specified database on the target server. If the \u003ccode class=\"option\"\u003e--subscription\u003c/code\u003e option is not specified, the subscription has the following name pattern: \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003e\u003ccode class=\"literal\"\u003epg_createsubscriber_%u_%x\u003c/code\u003e\u003c/span\u003e”\u003c/span\u003e (parameters: database \u003cem class=\"parameter\"\u003e\u003ccode\u003eoid\u003c/code\u003e\u003c/em\u003e, random \u003cem class=\"parameter\"\u003e\u003ccode\u003eint\u003c/code\u003e\u003c/em\u003e). It does not copy existing data from the source server. It does not create a replication slot. Instead, it uses the replication slot that was created in a previous step. The subscription is created but it is not enabled yet. The reason is the replication progress must be set to the replication start point before starting the replication.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp\u003eDrop publications on the target server that were replicated because they were created before the replication start location. It has no use on the subscriber.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp\u003eSet the replication progress to the replication start point for each subscription. When the target server starts the recovery process, it catches up to the replication start point. This is the exact LSN to be used as a initial replication location for each subscription. The replication origin name is obtained since the subscription was created. The replication origin name and the replication start point are used in \u003ca class=\"link\" href=\"/docs/18/functions-admin.html#PG-REPLICATION-ORIGIN-ADVANCE\"\u003e\u003ccode class=\"function\"\u003epg_replication_origin_advance()\u003c/code\u003e\u003c/a\u003e to set up the initial replication location.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp\u003eEnable the subscription for each specified database on the target server. The subscription starts applying transactions from the replication start point.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp\u003eIf the standby server was using \u003ca class=\"xref\" href=\"/docs/18/runtime-config-replication.html#GUC-PRIMARY-SLOT-NAME\"\u003eprimary_slot_name\u003c/a\u003e, it has no use from now on so drop it.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp\u003eIf the standby server contains \u003ca class=\"link\" href=\"/docs/18/logicaldecoding-explanation.html#LOGICALDECODING-REPLICATION-SLOTS-SYNCHRONIZATION\" title=\"47.2.3. Replication Slot Synchronization\"\u003efailover replication slots\u003c/a\u003e, they cannot be synchronized anymore, so drop them.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp\u003eUpdate the system identifier on the target server. The \u003ca class=\"xref\" href=\"/docs/18/app-pgresetwal.html\" title=\"pg_resetwal\"\u003e\u003cspan class=\"refentrytitle\"\u003e\u003cspan class=\"application\"\u003epg_resetwal\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e is run to modify the system identifier. The target server is stopped as a \u003ccode class=\"command\"\u003epg_resetwal\u003c/code\u003e requirement.\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ol\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsect1\" id=\"id-1.9.5.7.8\"\u003e\n\u003ch2\u003eExamples\u003c/h2\u003e\n\u003cp\u003eTo create a logical replica for databases \u003ccode class=\"literal\"\u003ehr\u003c/code\u003e and \u003ccode class=\"literal\"\u003efinance\u003c/code\u003e from a physical replica at \u003ccode class=\"literal\"\u003efoo\u003c/code\u003e:\u003c/p\u003e\n\u003cpre class=\"screen\"\u003e\u003ccode class=\"prompt\"\u003e$\u003c/code\u003e \u003cstrong class=\"userinput\"\u003e\u003ccode\u003epg_createsubscriber -D /usr/local/pgsql/data -P \"host=foo\" -d hr -d finance\u003c/code\u003e\u003c/strong\u003e\n\u003c/pre\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsect1\" id=\"id-1.9.5.7.9\"\u003e\n\u003ch2\u003eSee Also\u003c/h2\u003e\u003cspan class=\"simplelist\"\u003e\u003ca class=\"xref\" href=\"/docs/18/app-pgbasebackup.html\" title=\"pg_basebackup\"\u003e\u003cspan class=\"refentrytitle\"\u003e\u003cspan class=\"application\"\u003epg_basebackup\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e\n\u003c/div\u003e\n\u003c/div\u003e\u003c/div\u003e","related":[],"sections":[],"tables":[{"columns":[{"key":"signature","label":"Option and arguments"},{"key":"summary","label":"Description"}],"key":"options","rows":[{"signature":{"text":"-a --all","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"Create one subscription per database on the target server. Exceptions are template databases and databases that don't allow connections. To discover the list of all databases, connect to the source server using the database name specified in the --publisher-server connection string, or if not specified, the postgres database will be used, or if that does not exist, template1 will be used. Automatically generated names for subscriptions, publications, and replication slots are used when this option is specified. This option cannot be used along with --database , --publication , --replication-slot , or --subscription ."},{"signature":{"text":"-d dbname --database= dbname","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"The name of the database in which to create a subscription. Multiple databases can be selected by writing multiple -d switches. This option cannot be used together with -a . If -d option is not provided, the database name will be obtained from -P option. If the database name is not specified in either the -d option, or the -P option, and -a option is not specified, an error will be reported."},{"signature":{"text":"-D directory --pgdata= directory","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"The target directory that contains a cluster directory from a physical replica."},{"signature":{"text":"-n --dry-run","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"Do everything except actually modifying the target directory."},{"signature":{"text":"-p port --subscriber-port= port","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"The port number on which the target server is listening for connections. Defaults to running the target server on port 50432 to avoid unintended client connections."},{"signature":{"text":"-P connstr --publisher-server= connstr","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"The connection string to the publisher. For details see Section 32.1.1 ."},{"signature":{"text":"-s dir --socketdir= dir","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"The directory to use for postmaster sockets on target server. The default is current directory."},{"signature":{"text":"-t seconds --recovery-timeout= seconds","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"The maximum number of seconds to wait for recovery to end. Setting to 0 disables. The default is 0."},{"signature":{"text":"-T --enable-two-phase","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"Enables two_phase commit for the subscription. When multiple databases are specified, this option applies uniformly to all subscriptions created on those databases. The default is false ."},{"signature":{"text":"-U username --subscriber-username= username","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"The user name to connect as on target server. Defaults to the current operating system user name."},{"signature":{"text":"-v --verbose","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"Enables verbose mode. This will cause pg_createsubscriber to output progress messages and detailed information about each step to standard error. Repeating the option causes additional debug-level messages to appear on standard error."},{"signature":{"text":"--clean= objtype","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"Drop all objects of the specified type from specified databases on the target server."},{"signature":{"text":"--config-file= filename","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"Use the specified main server configuration file for the target data directory. pg_createsubscriber internally uses the pg_ctl command to start and stop the target server. It allows you to specify the actual postgresql.conf configuration file if it is stored outside the data directory."},{"signature":{"text":"--publication= name","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"The publication name to set up the logical replication. Multiple publications can be specified by writing multiple --publication switches. The number of publication names must match the number of specified databases, otherwise an error is reported. The order of the multiple publication name switches must match the order of database switches. If this option is not specified, a generated name is assigned to the publication name. This option cannot be used together with --all ."},{"signature":{"text":"--replication-slot= name","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"The replication slot name to set up the logical replication. Multiple replication slots can be specified by writing multiple --replication-slot switches. The number of replication slot names must match the number of specified databases, otherwise an error is reported. The order of the multiple replication slot name switches must match the order of database switches. If this option is not specified, the subscription name is assigned to the replication slot name. This option cannot be used together with --all ."},{"signature":{"text":"--subscription= name","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"The subscription name to set up the logical replication. Multiple subscriptions can be specified by writing multiple --subscription switches. The number of subscription names must match the number of specified databases, otherwise an error is reported. The order of the multiple subscription name switches must match the order of database switches. If this option is not specified, a generated name is assigned to the subscription name. This option cannot be used together with --all ."},{"signature":{"text":"-V --version","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"Print the pg_createsubscriber version and exit."},{"signature":{"text":"-? --help","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"Show help about pg_createsubscriber command line arguments, and exit."}],"title":"Documented options"}]}},"RequestedLocale":"zh-Hans","Fallback":true,"Versions":["17","18","19","20"],"Locales":["en"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
