pg_createsubscriber
描述 pg_createsubscriber 从物理备库创建新的逻辑副本。指定数据库中的所有表都会包含在 逻辑复制 配置中。每个数据库都会创建一对发布和订阅对象。该工具必须在目标服务器上运行。 成功运行后,目标服务器的状态类似于一个全新的逻辑复制配置。逻辑复制配置与 pg_createsubscriber 之间的主要区别在于数据同步的完成方式。 pg_createsubscriber 不会复制初始表数据。它只执行同步阶段,以确保每个表都达到同步状态。 pg_createsubscriber 主…
当前查看 PostgreSQL 18。
中文定义与说明
命令行工具 pg_createsubscriber [ option ...] { -d | --database } dbname { -D | --pgdata } datadir { -P | --publisher-server } connstr。
同版本中文手册节选
描述
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一起使用。-ddbname--database=dbname要在其中创建订阅的数据库名称。通过多次指定
-d可以选择多个数据库。此选项不能与-a一起使用。如果未提供-d选项,数据库名将从-P选项中获取。如果在-d选项或-P选项中都未指定数据库名,且又未指定-a选项,则会报告错误。-Ddirectory--pgdata=directory包含物理副本中的集簇目录的目标目录。
-n--dry-run执行除实际修改目标目录之外的所有步骤。
-pport--subscriber-port=port目标服务器监听连接的端口号。默认为让目标服务器在 50432 端口上运行,以避免意外的客户端连接。
-Pconnstr--publisher-server=connstr到发布者的连接字符串。详情见第 32.1.1 节。
-sdir--socketdir=dir目标服务器上 postmaster 套接字所使用的目录。默认值为当前目录。
-tseconds--recovery-timeout=seconds等待恢复结束的最大秒数。设为 0 表示禁用超时限制。默认值为 0。
-T--enable-two-phase为订阅启用
two_phase两阶段提交。当指定多个数据库时,此选项会统一应用于在这些数据库上创建的所有订阅。默认值为false。-Uusername--subscriber-username=username连接目标服务器所使用的用户名。默认是当前操作系统用户名。
-v--verbose启用详细模式。这将使 pg_createsubscriber 向标准错误输出进度消息以及每个步骤的详细信息。重复指定该选项会让更多调试级消息出现在标准错误中。
--clean=objtype从目标服务器上的指定数据库中删除指定类型的所有对象。
publications:为该订阅者建立的FOR ALL TABLES发布总是会被删除;指定此对象类型还会删除从源服务器复制过来的其他所有发布。
被选中要删除的对象都会逐个记录到日志中,包括在
--dry-run期间也是如此。没有机会干预或停止这些对象的删除,因此可以考虑使用 pg_dump 先对它们进行备份。--config-file=filename为目标数据目录使用指定的主配置文件。pg_createsubscriber 在内部使用 pg_ctl 命令来启动和停止目标服务器。如果实际的
postgresql.conf配置文件存放在数据目录之外,此选项允许你显式指定它。--publication=name用于建立逻辑复制的发布名称。通过多次指定
--publication可以指定多个发布。发布名称的数量必须与指定的数据库数量一致,否则会报告错误。多个发布名称开关的顺序必须与数据库开关的顺序一致。如果未指定此选项,则会为发布分配一个生成的名称。此选项不能与--all一起使用。--replication-slot=name用于建立逻辑复制的复制槽名称。通过多次指定
--replication-slot可以指定多个复制槽。复制槽名称的数量必须与指定的数据库数量一致,否则会报告错误。多个复制槽名称开关的顺序必须与数据库开关的顺序一致。如果未指定此选项,则使用订阅名称作为复制槽名称。此选项不能与--all一起使用。--subscription=name用于建立逻辑复制的订阅名称。通过多次指定
--subscription可以指定多个订阅。订阅名称的数量必须与指定的数据库数量一致,否则会报告错误。多个订阅名称开关的顺序必须与数据库开关的顺序一致。如果未指定此选项,则会为订阅分配一个生成的名称。此选项不能与--all一起使用。-V--version打印 pg_createsubscriber 版本并退出。
-?--help显示 pg_createsubscriber 命令行参数的帮助并退出。
说明
描述 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 包含物
- 手册中的可执行程序
- pg_createsubscriber
- 程序版本
- 18.6
- 参考清单
- 服务端程序
- 选项定义组
- 18
用法
pg_createsubscriber [ option ...] { -d | --database } dbname { -D | --pgdata } datadir { -P | --publisher-server } connstr手册中的选项
| 选项与参数 | 说明 |
|---|---|
| -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 | 包含物理副本中的集簇目录的目标目录。 |
| -n --dry-run | 执行除实际修改目标目录之外的所有步骤。 |
| -p port --subscriber-port= port | 目标服务器监听连接的端口号。默认为让目标服务器在 50432 端口上运行,以避免意外的客户端连接。 |
| -P connstr --publisher-server= connstr | 到发布者的连接字符串。详情见 第 32.1.1 节 。 |
| -s dir --socketdir= dir | 目标服务器上 postmaster 套接字所使用的目录。默认值为当前目录。 |
| -t seconds --recovery-timeout= seconds | 等待恢复结束的最长时间,单位为秒。设为 0 表示禁用该限制。默认值为 0。 |
| -T --enable-two-phase | 为订阅启用 two_phase 两阶段提交。当指定多个数据库时,此选项会统一应用于在这些数据库上创建的所有订阅。默认值为 false 。 |
| -U username --subscriber-username= username | 连接目标服务器所使用的用户名。默认是当前操作系统用户名。 |
| -v --verbose | 启用详细模式。这将使 pg_createsubscriber 向标准错误输出进度消息以及每个步骤的详细信息。重复指定该选项会让更多调试级消息出现在标准错误中。 |
| --clean= objtype | 从目标服务器上的指定数据库中删除指定类型的所有对象。 |
| --config-file= filename | 为目标数据目录使用指定的主配置文件。 pg_createsubscriber 在内部使用 pg_ctl 命令来启动和停止目标服务器。如果实际的 postgresql.conf 配置文件存放在数据目录之外,此选项允许你显式指定它。 |
| --publication= name | 用于建立逻辑复制的发布名称。通过多次指定 --publication 可以指定多个发布。发布名称的数量必须与指定的数据库数量一致,否则会报告错误。多个发布名称开关的顺序必须与数据库开关的顺序一致。如果未指定此选项,则会为发布分配一个生成的名称。此选项不能与 --all 一起使用。 |
| --replication-slot= name | 用于建立逻辑复制的复制槽名称。通过多次指定 --replication-slot 可以指定多个复制槽。复制槽名称的数量必须与指定的数据库数量一致,否则会报告错误。多个复制槽名称开关的顺序必须与数据库开关的顺序一致。如果未指定此选项,则使用订阅名称作为复制槽名称。此选项不能与 --all 一起使用。 |
| --subscription= name | 用于建立逻辑复制的订阅名称。通过多次指定 --subscription 可以指定多个订阅。订阅名称的数量必须与指定的数据库数量一致,否则会报告错误。多个订阅名称开关的顺序必须与数据库开关的顺序一致。如果未指定此选项,则会为订阅分配一个生成的名称。此选项不能与 --all 一起使用。 |
| -V --version | 打印 pg_createsubscriber 版本并退出。 |
| -? --help | 显示 pg_createsubscriber 命令行参数的帮助并退出。 |
文档与源码
来源构建
- 版本
- 18.6
- 构建
- https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2
- 来源指纹
ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8
版本比较
PostgreSQL 17 → 18: 属性变化。
以下差异保留原始字段名与英文源描述。
--- PostgreSQL 17
+++ PostgreSQL 18
@@ -2,7 +2,15 @@
"environment": [],
"options": [
{
- "description": "The name of the database in which to create a subscription. Multiple databases can be selected by writing multiple -d switches.",
+ "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"
@@ -58,6 +66,14 @@
"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",
@@ -74,6 +90,13 @@
"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"
@@ -81,21 +104,21 @@
"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.",
+ "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.",
+ "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.",
+ "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"
],
比较已记录的接口与属性,排除来源指纹和构建元数据。某个样本中没有记录,不能据此判断实际引入或移除的版本。
相关条目
导出 JSON · 返回命令行工具 · 收录范围为 PostgreSQL 17 至 20;最早采样版本不一定是实际引入版本。