{"Entry":{"collection":"tool","key":"pg-createsubscriber","name":"pg_createsubscriber","aliases":["pg_createsubscriber"],"metadata":{"aliases":["pg_createsubscriber"],"category":"Server applications","content_hash":"c4b251615b714c289c0c54356896bce5978e2206a711c18be1da52a81af966ee","derived_content_hash":"b2c89044c5034c7213344c9bef15749623d8d9434893d0429ab0302a72cb1bad","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"],"description_zh":"描述 pg_createsubscriber 从物理备库创建新的逻辑副本。指定数据库中的所有表都会包含在 逻辑复制 配置中。每个数据库都会创建一对发布和订阅对象。该工具必须在目标服务器上运行。 成功运行后，目标服务器的状态类似于一个全新的逻辑复制配置。逻辑复制配置与 pg_createsubscriber 之间的主要区别在于数据同步的完成方式。 pg_createsubscriber 不会复制初始表数据。它只执行同步阶段，以确保每个表都达到同步状态。 pg_createsubscriber 主要面向大型数据库系统，因为在逻辑复制配置中，大部分时间都花在复制初始数据上。此外，在数据同步上花费较长时间的一个副作用通常是，会有大量在初始数据复制期间产生的更改需要应用，这会进一步延后逻辑副本可用的时间。对于较小的数据库，建议建立带初始数据同步的逻辑复制。详见 CREATE SUBSCRIPTION 的 copy_data 选项。 选项 pg_createsubscriber 接受以下命令行参数： -a --all 在目标服务器上的每个数据库中创建一个订阅。模板数据库以及不允许连接的数据库除外。为发现所有数据库的列表，工具会使用 --publisher-server 连接字符串中指定的数据库名连接到源服务器；如果未指定，则使用 postgres 数据库；如果该数据库不存在，则使用 template1 。指定此选项时，会使用自动生成的订阅、发布和复制槽名称。此选项不能与 --database 、 --publication 、 --replication-slot 或 --subscription 一起使用。 -d dbname --database= dbname 要在其中创建订阅的数据库名称。通过多次指定 -d 可以选择多个数据库。此选项不能与 -a 一起使用。如果未提供 -d 选项，数据库名将从 -P 选项中获取。如果在 -d 选项或 -P 选项中都未指定数据库名，且又未指定 -a 选项，则会报告错误。 -D directory --pgdata= directory 包含物","description_zh_html":"\u003cp\u003e命令行工具 pg_createsubscriber [ option ...] { -d | --database } dbname { -D | --pgdata } datadir { -P | --publisher-server } connstr。\u003c/p\u003e\u003ch3\u003e同版本中文手册节选\u003c/h3\u003e\u003cdiv class=\"refsect1\"\u003e\u003ch2\u003e描述\u003c/h2\u003e\u003cp\u003e\n\u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e 从物理备库创建新的逻辑副本。指定数据库中的所有表都会包含在\u003ca class=\"link\" href=\"/zh/docs/18/logical-replication.html\"\u003e逻辑复制\u003c/a\u003e配置中。每个数据库都会创建一对发布和订阅对象。该工具必须在目标服务器上运行。\n  \u003c/p\u003e\u003cp\u003e\n   成功运行后，目标服务器的状态类似于一个全新的逻辑复制配置。逻辑复制配置与 \u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e 之间的主要区别在于数据同步的完成方式。\u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e\n   不会复制初始表数据。它只执行同步阶段，以确保每个表都达到同步状态。\n  \u003c/p\u003e\u003cp\u003e\n\u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e 主要面向大型数据库系统，因为在逻辑复制配置中，大部分时间都花在复制初始数据上。此外，在数据同步上花费较长时间的一个副作用通常是，会有大量在初始数据复制期间产生的更改需要应用，这会进一步延后逻辑副本可用的时间。对于较小的数据库，建议建立带初始数据同步的逻辑复制。详见 \u003ccode class=\"command\"\u003eCREATE SUBSCRIPTION\u003c/code\u003e 的\n   \u003ca class=\"link\" href=\"/zh/docs/18/sql-createsubscription.html#SQL-CREATESUBSCRIPTION-PARAMS-WITH-COPY-DATA\"\u003e\n\u003ccode class=\"literal\"\u003ecopy_data\u003c/code\u003e\u003c/a\u003e 选项。\n\n  \u003c/p\u003e\u003c/div\u003e\u003cdiv class=\"refsect1\"\u003e\u003ch2\u003e选项\u003c/h2\u003e\u003cp\u003e\n\u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e 接受以下命令行参数：\n\n   \u003c/p\u003e\u003cdiv class=\"variablelist\"\u003e\u003cdl class=\"variablelist\"\u003e\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\u003cdd\u003e\u003cp\u003e\n       在目标服务器上的每个数据库中创建一个订阅。模板数据库以及不允许连接的数据库除外。为发现所有数据库的列表，工具会使用 \u003ccode class=\"option\"\u003e--publisher-server\u003c/code\u003e\n       连接字符串中指定的数据库名连接到源服务器；如果未指定，则使用\n       \u003ccode class=\"literal\"\u003epostgres\u003c/code\u003e 数据库；如果该数据库不存在，则使用\n       \u003ccode class=\"literal\"\u003etemplate1\u003c/code\u003e。指定此选项时，会使用自动生成的订阅、发布和复制槽名称。此选项不能与 \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 或 \u003ccode class=\"option\"\u003e--subscription\u003c/code\u003e 一起使用。\n      \u003c/p\u003e\u003c/dd\u003e\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\u003cdd\u003e\u003cp\u003e\n       要在其中创建订阅的数据库名称。通过多次指定 \u003ccode class=\"option\"\u003e-d\u003c/code\u003e\n       可以选择多个数据库。此选项不能与 \u003ccode class=\"option\"\u003e-a\u003c/code\u003e 一起使用。如果未提供 \u003ccode class=\"option\"\u003e-d\u003c/code\u003e 选项，数据库名将从 \u003ccode class=\"option\"\u003e-P\u003c/code\u003e\n       选项中获取。如果在 \u003ccode class=\"option\"\u003e-d\u003c/code\u003e 选项或 \u003ccode class=\"option\"\u003e-P\u003c/code\u003e\n       选项中都未指定数据库名，且又未指定 \u003ccode class=\"option\"\u003e-a\u003c/code\u003e 选项，则会报告错误。\n      \u003c/p\u003e\u003c/dd\u003e\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\u003cdd\u003e\u003cp\u003e\n       包含物理副本中的集簇目录的目标目录。\n      \u003c/p\u003e\u003c/dd\u003e\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\u003cdd\u003e\u003cp\u003e\n       执行除实际修改目标目录之外的所有步骤。\n      \u003c/p\u003e\u003c/dd\u003e\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\u003cdd\u003e\u003cp\u003e\n       目标服务器监听连接的端口号。默认为让目标服务器在 50432 端口上运行，以避免意外的客户端连接。\n      \u003c/p\u003e\u003c/dd\u003e\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\u003cdd\u003e\u003cp\u003e\n       到发布者的连接字符串。详情见\u003ca class=\"xref\" href=\"/zh/docs/18/libpq-connect.html#LIBPQ-CONNSTRING\"\u003e第 32.1.1 节\u003c/a\u003e。\n      \u003c/p\u003e\u003c/dd\u003e\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\u003cdd\u003e\u003cp\u003e\n       目标服务器上 postmaster 套接字所使用的目录。默认值为当前目录。\n      \u003c/p\u003e\u003c/dd\u003e\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\u003cdd\u003e\u003cp\u003e\n       等待恢复结束的最大秒数。设为 0 表示禁用超时限制。默认值为 0。\n      \u003c/p\u003e\u003c/dd\u003e\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\u003cdd\u003e\u003cp\u003e\n       为订阅启用\n       \u003ca class=\"link\" href=\"/zh/docs/18/sql-createsubscription.html#SQL-CREATESUBSCRIPTION-PARAMS-WITH-TWO-PHASE\"\u003e\u003ccode class=\"literal\"\u003etwo_phase\u003c/code\u003e\u003c/a\u003e\n       两阶段提交。当指定多个数据库时，此选项会统一应用于在这些数据库上创建的所有订阅。默认值为 \u003ccode class=\"literal\"\u003efalse\u003c/code\u003e。\n      \u003c/p\u003e\u003c/dd\u003e\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\u003cdd\u003e\u003cp\u003e\n       连接目标服务器所使用的用户名。默认是当前操作系统用户名。\n      \u003c/p\u003e\u003c/dd\u003e\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\u003cdd\u003e\u003cp\u003e\n       启用详细模式。这将使\n       \u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e 向标准错误输出进度消息以及每个步骤的详细信息。重复指定该选项会让更多调试级消息出现在标准错误中。\n      \u003c/p\u003e\u003c/dd\u003e\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\u003cdd\u003e\u003cp\u003e\n       从目标服务器上的指定数据库中删除指定类型的所有对象。\n      \u003c/p\u003e\u003cp\u003e\n\u003c/p\u003e\u003cdiv class=\"itemizedlist\"\u003e\u003cul class=\"itemizedlist\"\u003e\u003cli class=\"listitem\"\u003e\u003cp\u003e\n\u003ccode class=\"literal\"\u003epublications\u003c/code\u003e：为该订阅者建立的 \u003ccode class=\"literal\"\u003eFOR ALL TABLES\u003c/code\u003e 发布总是会被删除；指定此对象类型还会删除从源服务器复制过来的其他所有发布。\n         \u003c/p\u003e\u003c/li\u003e\u003c/ul\u003e\u003c/div\u003e\u003cp\u003e\n\u003c/p\u003e\u003cp\u003e\n       被选中要删除的对象都会逐个记录到日志中，包括在 \u003ccode class=\"option\"\u003e--dry-run\u003c/code\u003e\n       期间也是如此。没有机会干预或停止这些对象的删除，因此可以考虑使用\n       \u003cspan class=\"application\"\u003epg_dump\u003c/span\u003e 先对它们进行备份。\n      \u003c/p\u003e\u003c/dd\u003e\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\u003cdd\u003e\u003cp\u003e\n       为目标数据目录使用指定的主配置文件。\u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e 在内部使用\n       \u003cspan class=\"application\"\u003epg_ctl\u003c/span\u003e 命令来启动和停止目标服务器。如果实际的 \u003ccode class=\"filename\"\u003epostgresql.conf\u003c/code\u003e 配置文件存放在数据目录之外，此选项允许你显式指定它。\n      \u003c/p\u003e\u003c/dd\u003e\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\u003cdd\u003e\u003cp\u003e\n       用于建立逻辑复制的发布名称。通过多次指定 \u003ccode class=\"option\"\u003e--publication\u003c/code\u003e\n       可以指定多个发布。发布名称的数量必须与指定的数据库数量一致，否则会报告错误。多个发布名称开关的顺序必须与数据库开关的顺序一致。如果未指定此选项，则会为发布分配一个生成的名称。此选项不能与\n       \u003ccode class=\"option\"\u003e--all\u003c/code\u003e 一起使用。\n      \u003c/p\u003e\u003c/dd\u003e\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\u003cdd\u003e\u003cp\u003e\n       用于建立逻辑复制的复制槽名称。通过多次指定 \u003ccode class=\"option\"\u003e--replication-slot\u003c/code\u003e\n       可以指定多个复制槽。复制槽名称的数量必须与指定的数据库数量一致，否则会报告错误。多个复制槽名称开关的顺序必须与数据库开关的顺序一致。如果未指定此选项，则使用订阅名称作为复制槽名称。此选项不能与\n       \u003ccode class=\"option\"\u003e--all\u003c/code\u003e 一起使用。\n      \u003c/p\u003e\u003c/dd\u003e\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\u003cdd\u003e\u003cp\u003e\n       用于建立逻辑复制的订阅名称。通过多次指定 \u003ccode class=\"option\"\u003e--subscription\u003c/code\u003e\n       可以指定多个订阅。订阅名称的数量必须与指定的数据库数量一致，否则会报告错误。多个订阅名称开关的顺序必须与数据库开关的顺序一致。如果未指定此选项，则会为订阅分配一个生成的名称。此选项不能与\n       \u003ccode class=\"option\"\u003e--all\u003c/code\u003e 一起使用。\n      \u003c/p\u003e\u003c/dd\u003e\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\u003cdd\u003e\u003cp\u003e\n       打印 \u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e 版本并退出。\n      \u003c/p\u003e\u003c/dd\u003e\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\u003cdd\u003e\u003cp\u003e\n       显示 \u003cspan class=\"application\"\u003epg_createsubscriber\u003c/span\u003e 命令行参数的帮助并退出。\n      \u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e\u003cp\u003e\n\u003c/p\u003e\u003c/div\u003e\u003cp\u003e\u003ca href=\"/zh/docs/18/app-pgcreatesubscriber.html\"\u003e查看完整中文手册与上下文\u003c/a\u003e。\u003c/p\u003e","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"}],"facts_zh":[{"label":"手册中的可执行程序","value":"pg_createsubscriber"},{"label":"程序版本","value":"18.6"},{"label":"参考清单","value":"服务端程序"},{"label":"选项定义组","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":[],"sections_zh":[],"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"}],"tables_zh":[{"columns":[{"key":"signature","label":"选项与参数"},{"key":"summary","label":"说明"}],"key":"options","rows":[{"signature":{"text":"-a --all","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"在目标服务器上的每个数据库中创建一个订阅。模板数据库以及不允许连接的数据库除外。为发现所有数据库的列表，工具会使用 --publisher-server 连接字符串中指定的数据库名连接到源服务器；如果未指定，则使用 postgres 数据库；如果该数据库不存在，则使用 template1 。指定此选项时，会使用自动生成的订阅、发布和复制槽名称。此选项不能与 --database 、 --publication 、 --replication-slot 或 --subscription 一起使用。"},{"signature":{"text":"-d dbname --database= dbname","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"要在其中创建订阅的数据库名称。通过多次指定 -d 可以选择多个数据库。此选项不能与 -a 一起使用。如果未提供 -d 选项，数据库名将从 -P 选项中获取。如果在 -d 选项或 -P 选项中都未指定数据库名，且又未指定 -a 选项，则会报告错误。"},{"signature":{"text":"-D directory --pgdata= directory","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"包含物理副本中的集簇目录的目标目录。"},{"signature":{"text":"-n --dry-run","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"执行除实际修改目标目录之外的所有步骤。"},{"signature":{"text":"-p port --subscriber-port= port","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"目标服务器监听连接的端口号。默认为让目标服务器在 50432 端口上运行，以避免意外的客户端连接。"},{"signature":{"text":"-P connstr --publisher-server= connstr","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"到发布者的连接字符串。详情见 第 32.1.1 节 。"},{"signature":{"text":"-s dir --socketdir= dir","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"目标服务器上 postmaster 套接字所使用的目录。默认值为当前目录。"},{"signature":{"text":"-t seconds --recovery-timeout= seconds","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"等待恢复结束的最长时间，单位为秒。设为 0 表示禁用该限制。默认值为 0。"},{"signature":{"text":"-T --enable-two-phase","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"为订阅启用 two_phase 两阶段提交。当指定多个数据库时，此选项会统一应用于在这些数据库上创建的所有订阅。默认值为 false 。"},{"signature":{"text":"-U username --subscriber-username= username","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"连接目标服务器所使用的用户名。默认是当前操作系统用户名。"},{"signature":{"text":"-v --verbose","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"启用详细模式。这将使 pg_createsubscriber 向标准错误输出进度消息以及每个步骤的详细信息。重复指定该选项会让更多调试级消息出现在标准错误中。"},{"signature":{"text":"--clean= objtype","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"从目标服务器上的指定数据库中删除指定类型的所有对象。"},{"signature":{"text":"--config-file= filename","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"为目标数据目录使用指定的主配置文件。 pg_createsubscriber 在内部使用 pg_ctl 命令来启动和停止目标服务器。如果实际的 postgresql.conf 配置文件存放在数据目录之外，此选项允许你显式指定它。"},{"signature":{"text":"--publication= name","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"用于建立逻辑复制的发布名称。通过多次指定 --publication 可以指定多个发布。发布名称的数量必须与指定的数据库数量一致，否则会报告错误。多个发布名称开关的顺序必须与数据库开关的顺序一致。如果未指定此选项，则会为发布分配一个生成的名称。此选项不能与 --all 一起使用。"},{"signature":{"text":"--replication-slot= name","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"用于建立逻辑复制的复制槽名称。通过多次指定 --replication-slot 可以指定多个复制槽。复制槽名称的数量必须与指定的数据库数量一致，否则会报告错误。多个复制槽名称开关的顺序必须与数据库开关的顺序一致。如果未指定此选项，则使用订阅名称作为复制槽名称。此选项不能与 --all 一起使用。"},{"signature":{"text":"--subscription= name","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"用于建立逻辑复制的订阅名称。通过多次指定 --subscription 可以指定多个订阅。订阅名称的数量必须与指定的数据库数量一致，否则会报告错误。多个订阅名称开关的顺序必须与数据库开关的顺序一致。如果未指定此选项，则会为订阅分配一个生成的名称。此选项不能与 --all 一起使用。"},{"signature":{"text":"-V --version","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"打印 pg_createsubscriber 版本并退出。"},{"signature":{"text":"-? --help","url":"/docs/18/app-pgcreatesubscriber.html"},"summary":"显示 pg_createsubscriber 命令行参数的帮助并退出。"}],"title":"手册中的选项"}],"zh_from":{"authored_translation":"source-derived-identity","body_sha256":"e68725256256b667e61a044bec4f1b2deaa9fa362a82325cd91a6ff7a13cc4c1","kind":"same-version-chinese-manual-with-source-derived-identity","manual":{"anchor":"","build_id":107,"extraction":"command-description-and-options","fragment_sha256":"7a7b57cfee5986b5c0fc82a29ae5d4197f26945da6bee82fa8d49c7769286755","locale":"zh-Hans","page_key":"app-pgcreatesubscriber.html","source_hash":"64c80f989aa4429e68c0cd76965bd715c0be65b8db41b603a63c863c17adb22c","source_revision":"unknown:rendered-translation-baseline","translated_from_revision":null,"translation_revision":"git:b1b500221dbe5437cfca004d6b04d3f6e422765d;html-sha256:08e987a66af27b98444a8057c256314eafa13611a3fb9e888214fc436824244b","url":"/zh/docs/18/app-pgcreatesubscriber.html","version":"18"},"runtime_rerun":false,"source_facts_revision":"ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8"}},"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":"en","Fallback":false,"Versions":["17","18","19","20"],"Locales":["en","zh-Hans"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
