{"kind": "tool", "major": "18", "item": {"slug": "pg-createsubscriber", "name": "pg_createsubscriber", "name_zh": "", "category": "Server applications", "summary": "pg_createsubscriber \u2014 convert a physical replica into a new logical replica", "aliases": ["pg_createsubscriber"], "content_hash": "c4b251615b714c289c0c54356896bce5978e2206a711c18be1da52a81af966ee", "versions": {"17": {"facts": [{"label": "Documented executable", "value": "pg_createsubscriber"}, {"label": "Executable version", "value": "17.11"}, {"label": "Reference inventory", "value": "Server applications"}, {"label": "Option definition groups", "value": "15"}], "tables": [{"key": "options", "rows": [{"summary": "The name of the database in which to create a subscription. Multiple databases can be selected by writing multiple -d switches.", "signature": {"url": "/docs/17/app-pgcreatesubscriber.html", "text": "-d dbname --database= dbname"}}, {"summary": "The target directory that contains a cluster directory from a physical replica.", "signature": {"url": "/docs/17/app-pgcreatesubscriber.html", "text": "-D directory --pgdata= directory"}}, {"summary": "Do everything except actually modifying the target directory.", "signature": {"url": "/docs/17/app-pgcreatesubscriber.html", "text": "-n --dry-run"}}, {"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": {"url": "/docs/17/app-pgcreatesubscriber.html", "text": "-p port --subscriber-port= port"}}, {"summary": "The connection string to the publisher. For details see Section 32.1.1 .", "signature": {"url": "/docs/17/app-pgcreatesubscriber.html", "text": "-P connstr --publisher-server= connstr"}}, {"summary": "The directory to use for postmaster sockets on target server. The default is current directory.", "signature": {"url": "/docs/17/app-pgcreatesubscriber.html", "text": "-s dir --socketdir= dir"}}, {"summary": "The maximum number of seconds to wait for recovery to end. Setting to 0 disables. The default is 0.", "signature": {"url": "/docs/17/app-pgcreatesubscriber.html", "text": "-t seconds --recovery-timeout= seconds"}}, {"summary": "The user name to connect as on target server. Defaults to the current operating system user name.", "signature": {"url": "/docs/17/app-pgcreatesubscriber.html", "text": "-U username --subscriber-username= username"}}, {"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": {"url": "/docs/17/app-pgcreatesubscriber.html", "text": "-v --verbose"}}, {"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": {"url": "/docs/17/app-pgcreatesubscriber.html", "text": "--config-file= filename"}}, {"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.", "signature": {"url": "/docs/17/app-pgcreatesubscriber.html", "text": "--publication= name"}}, {"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.", "signature": {"url": "/docs/17/app-pgcreatesubscriber.html", "text": "--replication-slot= name"}}, {"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.", "signature": {"url": "/docs/17/app-pgcreatesubscriber.html", "text": "--subscription= name"}}, {"summary": "Print the pg_createsubscriber version and exit.", "signature": {"url": "/docs/17/app-pgcreatesubscriber.html", "text": "-V --version"}}, {"summary": "Show help about pg_createsubscriber command line arguments, and exit.", "signature": {"url": "/docs/17/app-pgcreatesubscriber.html", "text": "-? --help"}}], "title": "Documented options", "columns": [{"key": "signature", "label": "Option and arguments"}, {"key": "summary", "label": "Description"}]}], "options": [{"names": ["-d dbname", "--database= dbname"], "summary": "The name of the database in which to create a subscription. Multiple databases can be selected by writing multiple -d switches.", "signature": "-d dbname --database= dbname", "source_url": "/docs/17/app-pgcreatesubscriber.html", "description": "The name of the database in which to create a subscription. Multiple databases can be selected by writing multiple -d switches."}, {"names": ["-D directory", "--pgdata= directory"], "summary": "The target directory that contains a cluster directory from a physical replica.", "signature": "-D directory --pgdata= directory", "source_url": "/docs/17/app-pgcreatesubscriber.html", "description": "The target directory that contains a cluster directory from a physical replica."}, {"names": ["-n", "--dry-run"], "summary": "Do everything except actually modifying the target directory.", "signature": "-n --dry-run", "source_url": "/docs/17/app-pgcreatesubscriber.html", "description": "Do everything except actually modifying the target directory."}, {"names": ["-p port", "--subscriber-port= port"], "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": "-p port --subscriber-port= port", "source_url": "/docs/17/app-pgcreatesubscriber.html", "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 connstr", "--publisher-server= connstr"], "summary": "The connection string to the publisher. For details see Section 32.1.1 .", "signature": "-P connstr --publisher-server= connstr", "source_url": "/docs/17/app-pgcreatesubscriber.html", "description": "The connection string to the publisher. For details see Section 32.1.1 ."}, {"names": ["-s dir", "--socketdir= dir"], "summary": "The directory to use for postmaster sockets on target server. The default is current directory.", "signature": "-s dir --socketdir= dir", "source_url": "/docs/17/app-pgcreatesubscriber.html", "description": "The directory to use for postmaster sockets on target server. The default is current directory."}, {"names": ["-t seconds", "--recovery-timeout= seconds"], "summary": "The maximum number of seconds to wait for recovery to end. Setting to 0 disables. The default is 0.", "signature": "-t seconds --recovery-timeout= seconds", "source_url": "/docs/17/app-pgcreatesubscriber.html", "description": "The maximum number of seconds to wait for recovery to end. Setting to 0 disables. The default is 0."}, {"names": ["-U username", "--subscriber-username= username"], "summary": "The user name to connect as on target server. Defaults to the current operating system user name.", "signature": "-U username --subscriber-username= username", "source_url": "/docs/17/app-pgcreatesubscriber.html", "description": "The user name to connect as on target server. Defaults to the current operating system user name."}, {"names": ["-v", "--verbose"], "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": "-v --verbose", "source_url": "/docs/17/app-pgcreatesubscriber.html", "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": ["--config-file= filename"], "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": "--config-file= filename", "source_url": "/docs/17/app-pgcreatesubscriber.html", "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": ["--publication= name"], "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.", "signature": "--publication= name", "source_url": "/docs/17/app-pgcreatesubscriber.html", "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."}, {"names": ["--replication-slot= name"], "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.", "signature": "--replication-slot= name", "source_url": "/docs/17/app-pgcreatesubscriber.html", "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."}, {"names": ["--subscription= name"], "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.", "signature": "--subscription= name", "source_url": "/docs/17/app-pgcreatesubscriber.html", "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."}, {"names": ["-V", "--version"], "summary": "Print the pg_createsubscriber version and exit.", "signature": "-V --version", "source_url": "/docs/17/app-pgcreatesubscriber.html", "description": "Print the pg_createsubscriber version and exit."}, {"names": ["-?", "--help"], "summary": "Show help about pg_createsubscriber command line arguments, and exit.", "signature": "-? --help", "source_url": "/docs/17/app-pgcreatesubscriber.html", "description": "Show help about pg_createsubscriber command line arguments, and exit."}], "related": [], "release": {"ref": "https://ftp.postgresql.org/pub/source/v17.11/postgresql-17.11.tar.bz2", "label": "17.11", "major": "17", "channel": "stable", "manifest": {"pdf": {"A4": {"url": "/files/documentation/pdf/17/postgresql-17-A4.pdf", "bytes": 15521293, "pages": 3099, "sha256": "1991354df0dc89e70ec39328c28988ef8b19c6a93671dab3893650b63e9f4e36", "built_at": "2026-09-26"}, "US": {"url": "/files/documentation/pdf/17/postgresql-17-US.pdf", "bytes": 15398150, "pages": 3270, "sha256": "07696c8f38abf31babf22d2db337093936e7c472d2af36d050b000c49bbcf52c", "built_at": "2026-09-26"}}, "tree": "17", "index": "index.html", "major": "17", "pages": 1143, "release": "17.11", "source_url": "https://ftp.postgresql.org/pub/source/v17.11/postgresql-17.11.tar.bz2", "svg_assets": 3, "source_mode": "en SGML built with pinned official archive", "source_sha256": "dd27f2b3c59e73ed14aa3324901242bf69a032a6347805f274e6260322d42979"}, "revision": "58419c9b0dd42cb34c8d53695bb025a7e582edf55ccd4c5bcb1c2c7c71a37487", "evidence_kind": "English manual and source declarations", "source_sha256": "dd27f2b3c59e73ed14aa3324901242bf69a032a6347805f274e6260322d42979"}, "sources": [{"url": "/docs/17/app-pgcreatesubscriber.html", "file": "app-pgcreatesubscriber.html", "label": "17.11 English manual \u00b7 app-pgcreatesubscriber.html", "anchor": "", "sha256": "acc0ccb21b3ea99df91f6bcf9db0e12b9e2b582391e36ac1f3f06ee2c7411337"}, {"url": "/docs/17/reference-server.html", "file": "reference-server.html", "label": "Server applications inventory", "anchor": "", "sha256": "01f07993ff020684f4c290d17cdafa26fb17ea5c1d476bc3a5efc68bf8ddd9b9"}], "sections": [], "synopsis": ["pg_createsubscriber [ option ...] { -d | --database } dbname { -D | --pgdata } datadir { -P | --publisher-server } connstr"], "signature": "pg_createsubscriber [ option ...] { -d | --database } dbname { -D | --pgdata } datadir { -P | --publisher-server } connstr", "description": ["pg_createsubscriber \u2014 convert a physical replica into a new logical replica"], "environment": [], "manual_html": "<div><div class=\"refentry\" id=\"APP-PGCREATESUBSCRIBER\">\n<div class=\"titlepage\"></div>\n<div class=\"refnamediv\">\n<h2><span class=\"refentrytitle\"><span class=\"application\">pg_createsubscriber</span></span></h2>\n<p>pg_createsubscriber \u2014 convert a physical replica into a new logical replica</p>\n</div>\n<div class=\"refsynopsisdiv\">\n<h2>Synopsis</h2>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.5.7.4.1\"><code class=\"command\">pg_createsubscriber</code> [<em class=\"replaceable\"><code>option</code></em>...] { <code class=\"option\">-d</code> | <code class=\"option\">--database</code> }<em class=\"replaceable\"><code>dbname</code></em> { <code class=\"option\">-D</code> | <code class=\"option\">--pgdata</code> }<em class=\"replaceable\"><code>datadir</code></em> { <code class=\"option\">-P</code> | <code class=\"option\">--publisher-server</code> }<em class=\"replaceable\"><code>connstr</code></em></p>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.5.7.5\">\n<h2>Description</h2>\n<p><span class=\"application\">pg_createsubscriber</span> creates a new logical replica from a physical standby server. All tables in the specified database are included in the <a class=\"link\" href=\"/docs/17/logical-replication.html\" title=\"Chapter\u00a029.\u00a0Logical Replication\">logical replication</a> setup. A pair of publication and subscription objects are created for each database. It must be run at the target server.</p>\n<p>After 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 <span class=\"application\">pg_createsubscriber</span> is how the data synchronization is done. <span class=\"application\">pg_createsubscriber</span> does not copy the initial table data. It does only the synchronization phase, which ensures each table is brought up to a synchronized state.</p>\n<p><span class=\"application\">pg_createsubscriber</span> 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 <code class=\"command\">CREATE SUBSCRIPTION</code> <a class=\"link\" href=\"/docs/17/sql-createsubscription.html#SQL-CREATESUBSCRIPTION-PARAMS-WITH-COPY-DATA\"><code class=\"literal\">copy_data</code></a> option.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.5.7.6\">\n<h2>Options</h2>\n<p><span class=\"application\">pg_createsubscriber</span> accepts the following command-line arguments:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-d <em class=\"replaceable\"><code>dbname</code></em></code><br></span><span class=\"term\"><code class=\"option\">--database=<em class=\"replaceable\"><code>dbname</code></em></code></span></dt>\n<dd>\n<p>The name of the database in which to create a subscription. Multiple databases can be selected by writing multiple <code class=\"option\">-d</code> switches.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-D <em class=\"replaceable\"><code>directory</code></em></code><br></span><span class=\"term\"><code class=\"option\">--pgdata=<em class=\"replaceable\"><code>directory</code></em></code></span></dt>\n<dd>\n<p>The target directory that contains a cluster directory from a physical replica.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--dry-run</code></span></dt>\n<dd>\n<p>Do everything except actually modifying the target directory.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-p <em class=\"replaceable\"><code>port</code></em></code><br></span><span class=\"term\"><code class=\"option\">--subscriber-port=<em class=\"replaceable\"><code>port</code></em></code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-P <em class=\"replaceable\"><code>connstr</code></em></code><br></span><span class=\"term\"><code class=\"option\">--publisher-server=<em class=\"replaceable\"><code>connstr</code></em></code></span></dt>\n<dd>\n<p>The connection string to the publisher. For details see <a class=\"xref\" href=\"/docs/17/libpq-connect.html#LIBPQ-CONNSTRING\" title=\"32.1.1.\u00a0Connection Strings\">Section\u00a032.1.1</a>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-s <em class=\"replaceable\"><code>dir</code></em></code><br></span><span class=\"term\"><code class=\"option\">--socketdir=<em class=\"replaceable\"><code>dir</code></em></code></span></dt>\n<dd>\n<p>The directory to use for postmaster sockets on target server. The default is current directory.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-t <em class=\"replaceable\"><code>seconds</code></em></code><br></span><span class=\"term\"><code class=\"option\">--recovery-timeout=<em class=\"replaceable\"><code>seconds</code></em></code></span></dt>\n<dd>\n<p>The maximum number of seconds to wait for recovery to end. Setting to 0 disables. The default is 0.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-U <em class=\"replaceable\"><code>username</code></em></code><br></span><span class=\"term\"><code class=\"option\">--subscriber-username=<em class=\"replaceable\"><code>username</code></em></code></span></dt>\n<dd>\n<p>The user name to connect as on target server. Defaults to the current operating system user name.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-v</code><br></span><span class=\"term\"><code class=\"option\">--verbose</code></span></dt>\n<dd>\n<p>Enables verbose mode. This will cause <span class=\"application\">pg_createsubscriber</span> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--config-file=<em class=\"replaceable\"><code>filename</code></em></code></span></dt>\n<dd>\n<p>Use the specified main server configuration file for the target data directory. <span class=\"application\">pg_createsubscriber</span> internally uses the <span class=\"application\">pg_ctl</span> command to start and stop the target server. It allows you to specify the actual <code class=\"filename\">postgresql.conf</code> configuration file if it is stored outside the data directory.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--publication=<em class=\"replaceable\"><code>name</code></em></code></span></dt>\n<dd>\n<p>The publication name to set up the logical replication. Multiple publications can be specified by writing multiple <code class=\"option\">--publication</code> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--replication-slot=<em class=\"replaceable\"><code>name</code></em></code></span></dt>\n<dd>\n<p>The replication slot name to set up the logical replication. Multiple replication slots can be specified by writing multiple <code class=\"option\">--replication-slot</code> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--subscription=<em class=\"replaceable\"><code>name</code></em></code></span></dt>\n<dd>\n<p>The subscription name to set up the logical replication. Multiple subscriptions can be specified by writing multiple <code class=\"option\">--subscription</code> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-V</code><br></span><span class=\"term\"><code class=\"option\">--version</code></span></dt>\n<dd>\n<p>Print the <span class=\"application\">pg_createsubscriber</span> version and exit.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-?</code><br></span><span class=\"term\"><code class=\"option\">--help</code></span></dt>\n<dd>\n<p>Show help about <span class=\"application\">pg_createsubscriber</span> command line arguments, and exit.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.5.7.7\">\n<h2>Notes</h2>\n<div class=\"refsect2\" id=\"id-1.9.5.7.7.2\">\n<h3>Prerequisites</h3>\n<p>There are some prerequisites for <span class=\"application\">pg_createsubscriber</span> 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 <span class=\"application\">pg_createsubscriber</span>. 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 <a class=\"link\" href=\"/docs/17/sql-createsubscription.html\" title=\"CREATE SUBSCRIPTION\">subscriptions</a> and using <a class=\"link\" href=\"/docs/17/functions-admin.html#PG-REPLICATION-ORIGIN-ADVANCE\"><code class=\"function\">pg_replication_origin_advance()</code></a>.</p>\n<p>The target server must be used as a physical standby. The target server must have <a class=\"xref\" href=\"/docs/17/runtime-config-replication.html#GUC-MAX-REPLICATION-SLOTS\">max_replication_slots</a> and <a class=\"xref\" href=\"/docs/17/runtime-config-replication.html#GUC-MAX-LOGICAL-REPLICATION-WORKERS\">max_logical_replication_workers</a> configured to a value greater than or equal to the number of specified databases. The target server must have <a class=\"xref\" href=\"/docs/17/runtime-config-resource.html#GUC-MAX-WORKER-PROCESSES\">max_worker_processes</a> configured to a value greater than the number of specified databases. The target server must accept local connections.</p>\n<p>The source server must accept connections from the target server. The source server must not be in recovery. The source server must have <a class=\"xref\" href=\"/docs/17/runtime-config-wal.html#GUC-WAL-LEVEL\">wal_level</a> as <code class=\"literal\">logical</code>. The source server must have <a class=\"xref\" href=\"/docs/17/runtime-config-replication.html#GUC-MAX-REPLICATION-SLOTS\">max_replication_slots</a> configured to a value greater than or equal to the number of specified databases plus existing replication slots. The source server must have <a class=\"xref\" href=\"/docs/17/runtime-config-replication.html#GUC-MAX-WAL-SENDERS\">max_wal_senders</a> configured to a value greater than or equal to the number of specified databases and existing WAL sender processes.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.5.7.7.3\">\n<h3>Warnings</h3>\n<p>If <span class=\"application\">pg_createsubscriber</span> 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.</p>\n<p><span class=\"application\">pg_createsubscriber</span> usually starts the target server with different connection settings during transformation. Hence, connections to the target server should fail.</p>\n<p>Since DDL commands are not replicated by logical replication, avoid executing DDL commands that change the database schema while running <span class=\"application\">pg_createsubscriber</span>. If the target server has already been converted to logical replica, the DDL commands might not be replicated, which might cause an error.</p>\n<p>If <span class=\"application\">pg_createsubscriber</span> 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.</p>\n<p>If the replication is using <a class=\"xref\" href=\"/docs/17/runtime-config-replication.html#GUC-PRIMARY-SLOT-NAME\">primary_slot_name</a>, it will be removed from the source server after the logical replication setup.</p>\n<p>If the target server is a synchronous replica, transaction commits on the primary might wait for replication while running <span class=\"application\">pg_createsubscriber</span>.</p>\n<p><span class=\"application\">pg_createsubscriber</span> sets up logical replication with two-phase commit disabled. This means that any prepared transactions will be replicated at the time of <code class=\"command\">COMMIT PREPARED</code>, without advance preparation. Once setup is complete, you can manually drop and re-create the subscription(s) with the <a class=\"link\" href=\"/docs/17/sql-createsubscription.html#SQL-CREATESUBSCRIPTION-PARAMS-WITH-TWO-PHASE\"><code class=\"literal\">two_phase</code></a> option enabled.</p>\n<p><span class=\"application\">pg_createsubscriber</span> changes the system identifier using <span class=\"application\">pg_resetwal</span>. 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.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.5.7.7.4\">\n<h3>How It Works</h3>\n<p>The basic idea is to have a replication start point from the source server and set up a logical replication to start from this point:</p>\n<div class=\"procedure\">\n<ol class=\"procedure\">\n<li class=\"step\">\n<p>Start the target server with the specified command-line options. If the target server is already running, <span class=\"application\">pg_createsubscriber</span> will terminate with an error.</p>\n</li>\n<li class=\"step\">\n<p>Check 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, <span class=\"application\">pg_createsubscriber</span> will terminate with an error.</p>\n</li>\n<li class=\"step\">\n<p>Create a publication and replication slot for each specified database on the source server. Each publication is created using <a class=\"link\" href=\"/docs/17/sql-createpublication.html#SQL-CREATEPUBLICATION-PARAMS-FOR-ALL-TABLES\"><code class=\"literal\">FOR ALL TABLES</code></a>. If the <code class=\"option\">--publication</code> option is not specified, the publication has the following name pattern: <span class=\"quote\">\u201c<span class=\"quote\"><code class=\"literal\">pg_createsubscriber_%u_%x</code></span>\u201d</span> (parameter: database <em class=\"parameter\"><code>oid</code></em>, random <em class=\"parameter\"><code>int</code></em>). If the <code class=\"option\">--replication-slot</code> option is not specified, the replication slot has the following name pattern: <span class=\"quote\">\u201c<span class=\"quote\"><code class=\"literal\">pg_createsubscriber_%u_%x</code></span>\u201d</span> (parameters: database <em class=\"parameter\"><code>oid</code></em>, random <em class=\"parameter\"><code>int</code></em>). 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 <a class=\"xref\" href=\"/docs/17/runtime-config-wal.html#GUC-RECOVERY-TARGET-LSN\">recovery_target_lsn</a> parameter and by the subscriptions as a replication start point. It guarantees that no transaction will be lost.</p>\n</li>\n<li class=\"step\">\n<p>Write recovery parameters into the target data directory and restart the target server. It specifies an LSN (<a class=\"xref\" href=\"/docs/17/runtime-config-wal.html#GUC-RECOVERY-TARGET-LSN\">recovery_target_lsn</a>) of the write-ahead log location up to which recovery will proceed. It also specifies <code class=\"literal\">promote</code> as the action that the server should take once the recovery target is reached. Additional <a class=\"link\" href=\"/docs/17/runtime-config-wal.html#RUNTIME-CONFIG-WAL-RECOVERY-TARGET\" title=\"19.5.6.\u00a0Recovery Target\">recovery parameters</a> 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 <code class=\"option\">--recovery-timeout</code> option is set, <span class=\"application\">pg_createsubscriber</span> terminates if recovery does not end until the given number of seconds.</p>\n</li>\n<li class=\"step\">\n<p>Create a subscription for each specified database on the target server. If the <code class=\"option\">--subscription</code> option is not specified, the subscription has the following name pattern: <span class=\"quote\">\u201c<span class=\"quote\"><code class=\"literal\">pg_createsubscriber_%u_%x</code></span>\u201d</span> (parameters: database <em class=\"parameter\"><code>oid</code></em>, random <em class=\"parameter\"><code>int</code></em>). 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.</p>\n</li>\n<li class=\"step\">\n<p>Drop publications on the target server that were replicated because they were created before the replication start location. It has no use on the subscriber.</p>\n</li>\n<li class=\"step\">\n<p>Set 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 <a class=\"link\" href=\"/docs/17/functions-admin.html#PG-REPLICATION-ORIGIN-ADVANCE\"><code class=\"function\">pg_replication_origin_advance()</code></a> to set up the initial replication location.</p>\n</li>\n<li class=\"step\">\n<p>Enable the subscription for each specified database on the target server. The subscription starts applying transactions from the replication start point.</p>\n</li>\n<li class=\"step\">\n<p>If the standby server was using <a class=\"xref\" href=\"/docs/17/runtime-config-replication.html#GUC-PRIMARY-SLOT-NAME\">primary_slot_name</a>, it has no use from now on so drop it.</p>\n</li>\n<li class=\"step\">\n<p>If the standby server contains <a class=\"link\" href=\"/docs/17/logicaldecoding-explanation.html#LOGICALDECODING-REPLICATION-SLOTS-SYNCHRONIZATION\" title=\"47.2.3.\u00a0Replication Slot Synchronization\">failover replication slots</a>, they cannot be synchronized anymore, so drop them.</p>\n</li>\n<li class=\"step\">\n<p>Update the system identifier on the target server. The <a class=\"xref\" href=\"/docs/17/app-pgresetwal.html\" title=\"pg_resetwal\"><span class=\"refentrytitle\"><span class=\"application\">pg_resetwal</span></span></a> is run to modify the system identifier. The target server is stopped as a <code class=\"command\">pg_resetwal</code> requirement.</p>\n</li>\n</ol>\n</div>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.5.7.8\">\n<h2>Examples</h2>\n<p>To create a logical replica for databases <code class=\"literal\">hr</code> and <code class=\"literal\">finance</code> from a physical replica at <code class=\"literal\">foo</code>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_createsubscriber -D /usr/local/pgsql/data -P \"host=foo\" -d hr -d finance</code></strong>\n</pre>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.5.7.9\">\n<h2>See Also</h2><span class=\"simplelist\"><a class=\"xref\" href=\"/docs/17/app-pgbasebackup.html\" title=\"pg_basebackup\"><span class=\"refentrytitle\"><span class=\"application\">pg_basebackup</span></span></a></span>\n</div>\n</div></div>", "manual_path": "app-pgcreatesubscriber.html", "comparison_data": {"options": [{"names": ["-d dbname", "--database= dbname"], "signature": "-d dbname --database= dbname", "description": "The name of the database in which to create a subscription. Multiple databases can be selected by writing multiple -d switches."}, {"names": ["-D directory", "--pgdata= directory"], "signature": "-D directory --pgdata= directory", "description": "The target directory that contains a cluster directory from a physical replica."}, {"names": ["-n", "--dry-run"], "signature": "-n --dry-run", "description": "Do everything except actually modifying the target directory."}, {"names": ["-p port", "--subscriber-port= port"], "signature": "-p port --subscriber-port= port", "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 connstr", "--publisher-server= connstr"], "signature": "-P connstr --publisher-server= connstr", "description": "The connection string to the publisher. For details see Section 32.1.1 ."}, {"names": ["-s dir", "--socketdir= dir"], "signature": "-s dir --socketdir= dir", "description": "The directory to use for postmaster sockets on target server. The default is current directory."}, {"names": ["-t seconds", "--recovery-timeout= seconds"], "signature": "-t seconds --recovery-timeout= seconds", "description": "The maximum number of seconds to wait for recovery to end. Setting to 0 disables. The default is 0."}, {"names": ["-U username", "--subscriber-username= username"], "signature": "-U username --subscriber-username= username", "description": "The user name to connect as on target server. Defaults to the current operating system user name."}, {"names": ["-v", "--verbose"], "signature": "-v --verbose", "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": ["--config-file= filename"], "signature": "--config-file= filename", "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": ["--publication= name"], "signature": "--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."}, {"names": ["--replication-slot= name"], "signature": "--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."}, {"names": ["--subscription= name"], "signature": "--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."}, {"names": ["-V", "--version"], "signature": "-V --version", "description": "Print the pg_createsubscriber version and exit."}, {"names": ["-?", "--help"], "signature": "-? --help", "description": "Show help about pg_createsubscriber command line arguments, and exit."}], "synopsis": ["pg_createsubscriber [ option ...] { -d | --database } dbname { -D | --pgdata } datadir { -P | --publisher-server } connstr"], "environment": []}, "comparison_hash": "104b1091aa60e86021ca6825e5d2414d196b482450979f525b6f54db62c8b4dd"}, "18": {"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"}], "tables": [{"key": "options", "rows": [{"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": {"url": "/docs/18/app-pgcreatesubscriber.html", "text": "-a --all"}}, {"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": {"url": "/docs/18/app-pgcreatesubscriber.html", "text": "-d dbname --database= dbname"}}, {"summary": "The target directory that contains a cluster directory from a physical replica.", "signature": {"url": "/docs/18/app-pgcreatesubscriber.html", "text": "-D directory --pgdata= directory"}}, {"summary": "Do everything except actually modifying the target directory.", "signature": {"url": "/docs/18/app-pgcreatesubscriber.html", "text": "-n --dry-run"}}, {"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": {"url": "/docs/18/app-pgcreatesubscriber.html", "text": "-p port --subscriber-port= port"}}, {"summary": "The connection string to the publisher. For details see Section 32.1.1 .", "signature": {"url": "/docs/18/app-pgcreatesubscriber.html", "text": "-P connstr --publisher-server= connstr"}}, {"summary": "The directory to use for postmaster sockets on target server. The default is current directory.", "signature": {"url": "/docs/18/app-pgcreatesubscriber.html", "text": "-s dir --socketdir= dir"}}, {"summary": "The maximum number of seconds to wait for recovery to end. Setting to 0 disables. The default is 0.", "signature": {"url": "/docs/18/app-pgcreatesubscriber.html", "text": "-t seconds --recovery-timeout= seconds"}}, {"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": {"url": "/docs/18/app-pgcreatesubscriber.html", "text": "-T --enable-two-phase"}}, {"summary": "The user name to connect as on target server. Defaults to the current operating system user name.", "signature": {"url": "/docs/18/app-pgcreatesubscriber.html", "text": "-U username --subscriber-username= username"}}, {"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": {"url": "/docs/18/app-pgcreatesubscriber.html", "text": "-v --verbose"}}, {"summary": "Drop all objects of the specified type from specified databases on the target server.", "signature": {"url": "/docs/18/app-pgcreatesubscriber.html", "text": "--clean= objtype"}}, {"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": {"url": "/docs/18/app-pgcreatesubscriber.html", "text": "--config-file= filename"}}, {"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": {"url": "/docs/18/app-pgcreatesubscriber.html", "text": "--publication= name"}}, {"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": {"url": "/docs/18/app-pgcreatesubscriber.html", "text": "--replication-slot= name"}}, {"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": {"url": "/docs/18/app-pgcreatesubscriber.html", "text": "--subscription= name"}}, {"summary": "Print the pg_createsubscriber version and exit.", "signature": {"url": "/docs/18/app-pgcreatesubscriber.html", "text": "-V --version"}}, {"summary": "Show help about pg_createsubscriber command line arguments, and exit.", "signature": {"url": "/docs/18/app-pgcreatesubscriber.html", "text": "-? --help"}}], "title": "Documented options", "columns": [{"key": "signature", "label": "Option and arguments"}, {"key": "summary", "label": "Description"}]}], "options": [{"names": ["-a", "--all"], "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": "-a --all", "source_url": "/docs/18/app-pgcreatesubscriber.html", "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": ["-d dbname", "--database= dbname"], "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": "-d dbname --database= dbname", "source_url": "/docs/18/app-pgcreatesubscriber.html", "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 directory", "--pgdata= directory"], "summary": "The target directory that contains a cluster directory from a physical replica.", "signature": "-D directory --pgdata= directory", "source_url": "/docs/18/app-pgcreatesubscriber.html", "description": "The target directory that contains a cluster directory from a physical replica."}, {"names": ["-n", "--dry-run"], "summary": "Do everything except actually modifying the target directory.", "signature": "-n --dry-run", "source_url": "/docs/18/app-pgcreatesubscriber.html", "description": "Do everything except actually modifying the target directory."}, {"names": ["-p port", "--subscriber-port= port"], "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": "-p port --subscriber-port= port", "source_url": "/docs/18/app-pgcreatesubscriber.html", "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 connstr", "--publisher-server= connstr"], "summary": "The connection string to the publisher. For details see Section 32.1.1 .", "signature": "-P connstr --publisher-server= connstr", "source_url": "/docs/18/app-pgcreatesubscriber.html", "description": "The connection string to the publisher. For details see Section 32.1.1 ."}, {"names": ["-s dir", "--socketdir= dir"], "summary": "The directory to use for postmaster sockets on target server. The default is current directory.", "signature": "-s dir --socketdir= dir", "source_url": "/docs/18/app-pgcreatesubscriber.html", "description": "The directory to use for postmaster sockets on target server. The default is current directory."}, {"names": ["-t seconds", "--recovery-timeout= seconds"], "summary": "The maximum number of seconds to wait for recovery to end. Setting to 0 disables. The default is 0.", "signature": "-t seconds --recovery-timeout= seconds", "source_url": "/docs/18/app-pgcreatesubscriber.html", "description": "The maximum number of seconds to wait for recovery to end. Setting to 0 disables. The default is 0."}, {"names": ["-T", "--enable-two-phase"], "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": "-T --enable-two-phase", "source_url": "/docs/18/app-pgcreatesubscriber.html", "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": ["-U username", "--subscriber-username= username"], "summary": "The user name to connect as on target server. Defaults to the current operating system user name.", "signature": "-U username --subscriber-username= username", "source_url": "/docs/18/app-pgcreatesubscriber.html", "description": "The user name to connect as on target server. Defaults to the current operating system user name."}, {"names": ["-v", "--verbose"], "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": "-v --verbose", "source_url": "/docs/18/app-pgcreatesubscriber.html", "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": ["--clean= objtype"], "summary": "Drop all objects of the specified type from specified databases on the target server.", "signature": "--clean= objtype", "source_url": "/docs/18/app-pgcreatesubscriber.html", "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": ["--config-file= filename"], "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": "--config-file= filename", "source_url": "/docs/18/app-pgcreatesubscriber.html", "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": ["--publication= name"], "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": "--publication= name", "source_url": "/docs/18/app-pgcreatesubscriber.html", "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": ["--replication-slot= name"], "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": "--replication-slot= name", "source_url": "/docs/18/app-pgcreatesubscriber.html", "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": ["--subscription= name"], "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": "--subscription= name", "source_url": "/docs/18/app-pgcreatesubscriber.html", "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": ["-V", "--version"], "summary": "Print the pg_createsubscriber version and exit.", "signature": "-V --version", "source_url": "/docs/18/app-pgcreatesubscriber.html", "description": "Print the pg_createsubscriber version and exit."}, {"names": ["-?", "--help"], "summary": "Show help about pg_createsubscriber command line arguments, and exit.", "signature": "-? --help", "source_url": "/docs/18/app-pgcreatesubscriber.html", "description": "Show help about pg_createsubscriber command line arguments, and exit."}], "related": [], "release": {"ref": "https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2", "label": "18.6", "major": "18", "channel": "stable", "manifest": {"pdf": {"A4": {"url": "/files/documentation/pdf/18/postgresql-18-A4.pdf", "bytes": 15865106, "pages": 3154, "sha256": "19512c405da53f9f7fcf0abba359223aa65f021be025bf3411381918f92e3190", "built_at": "2026-09-26"}, "US": {"url": "/files/documentation/pdf/18/postgresql-18-US.pdf", "bytes": 15748059, "pages": 3328, "sha256": "facbe6c229e598b872d3d98bef53308f46e06746006fa4590de9a7de9dd46319", "built_at": "2026-09-26"}}, "tree": "18", "index": "index.html", "major": "18", "pages": 1148, "release": "18.6", "source_url": "https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2", "svg_assets": 3, "source_mode": "en SGML built with pinned official archive", "source_sha256": "555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f"}, "revision": "ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8", "evidence_kind": "English manual and source declarations", "source_sha256": "555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f"}, "sources": [{"url": "/docs/18/app-pgcreatesubscriber.html", "file": "app-pgcreatesubscriber.html", "label": "18.6 English manual \u00b7 app-pgcreatesubscriber.html", "anchor": "", "sha256": "fb0e5cd7f37044410e06deb436d7b70a1bceffbd849ce10f468351d9cf11d385"}, {"url": "/docs/18/reference-server.html", "file": "reference-server.html", "label": "Server applications inventory", "anchor": "", "sha256": "e9f8bbcc8e3641fadd1d20991e8aad6b532155b786ba5a1b7b364ec4f1a5bef3"}], "sections": [], "synopsis": ["pg_createsubscriber [ option ...] { -d | --database } dbname { -D | --pgdata } datadir { -P | --publisher-server } connstr"], "signature": "pg_createsubscriber [ option ...] { -d | --database } dbname { -D | --pgdata } datadir { -P | --publisher-server } connstr", "description": ["pg_createsubscriber \u2014 convert a physical replica into a new logical replica"], "environment": [], "manual_html": "<div><div class=\"refentry\" id=\"APP-PGCREATESUBSCRIBER\">\n<div class=\"titlepage\"></div>\n<div class=\"refnamediv\">\n<h2><span class=\"refentrytitle\"><span class=\"application\">pg_createsubscriber</span></span></h2>\n<p>pg_createsubscriber \u2014 convert a physical replica into a new logical replica</p>\n</div>\n<div class=\"refsynopsisdiv\">\n<h2>Synopsis</h2>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.5.7.4.1\"><code class=\"command\">pg_createsubscriber</code> [<em class=\"replaceable\"><code>option</code></em>...] { <code class=\"option\">-d</code> | <code class=\"option\">--database</code> }<em class=\"replaceable\"><code>dbname</code></em> { <code class=\"option\">-D</code> | <code class=\"option\">--pgdata</code> }<em class=\"replaceable\"><code>datadir</code></em> { <code class=\"option\">-P</code> | <code class=\"option\">--publisher-server</code> }<em class=\"replaceable\"><code>connstr</code></em></p>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.5.7.5\">\n<h2>Description</h2>\n<p><span class=\"application\">pg_createsubscriber</span> creates a new logical replica from a physical standby server. All tables in the specified database are included in the <a class=\"link\" href=\"/docs/18/logical-replication.html\" title=\"Chapter\u00a029.\u00a0Logical Replication\">logical replication</a> setup. A pair of publication and subscription objects are created for each database. It must be run at the target server.</p>\n<p>After 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 <span class=\"application\">pg_createsubscriber</span> is how the data synchronization is done. <span class=\"application\">pg_createsubscriber</span> does not copy the initial table data. It does only the synchronization phase, which ensures each table is brought up to a synchronized state.</p>\n<p><span class=\"application\">pg_createsubscriber</span> 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 <code class=\"command\">CREATE SUBSCRIPTION</code> <a class=\"link\" href=\"/docs/18/sql-createsubscription.html#SQL-CREATESUBSCRIPTION-PARAMS-WITH-COPY-DATA\"><code class=\"literal\">copy_data</code></a> option.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.5.7.6\">\n<h2>Options</h2>\n<p><span class=\"application\">pg_createsubscriber</span> accepts the following command-line arguments:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-a</code><br></span><span class=\"term\"><code class=\"option\">--all</code></span></dt>\n<dd>\n<p>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 <code class=\"option\">--publisher-server</code> connection string, or if not specified, the <code class=\"literal\">postgres</code> database will be used, or if that does not exist, <code class=\"literal\">template1</code> 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 <code class=\"option\">--database</code>, <code class=\"option\">--publication</code>, <code class=\"option\">--replication-slot</code>, or <code class=\"option\">--subscription</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-d <em class=\"replaceable\"><code>dbname</code></em></code><br></span><span class=\"term\"><code class=\"option\">--database=<em class=\"replaceable\"><code>dbname</code></em></code></span></dt>\n<dd>\n<p>The name of the database in which to create a subscription. Multiple databases can be selected by writing multiple <code class=\"option\">-d</code> switches. This option cannot be used together with <code class=\"option\">-a</code>. If <code class=\"option\">-d</code> option is not provided, the database name will be obtained from <code class=\"option\">-P</code> option. If the database name is not specified in either the <code class=\"option\">-d</code> option, or the <code class=\"option\">-P</code> option, and <code class=\"option\">-a</code> option is not specified, an error will be reported.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-D <em class=\"replaceable\"><code>directory</code></em></code><br></span><span class=\"term\"><code class=\"option\">--pgdata=<em class=\"replaceable\"><code>directory</code></em></code></span></dt>\n<dd>\n<p>The target directory that contains a cluster directory from a physical replica.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--dry-run</code></span></dt>\n<dd>\n<p>Do everything except actually modifying the target directory.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-p <em class=\"replaceable\"><code>port</code></em></code><br></span><span class=\"term\"><code class=\"option\">--subscriber-port=<em class=\"replaceable\"><code>port</code></em></code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-P <em class=\"replaceable\"><code>connstr</code></em></code><br></span><span class=\"term\"><code class=\"option\">--publisher-server=<em class=\"replaceable\"><code>connstr</code></em></code></span></dt>\n<dd>\n<p>The connection string to the publisher. For details see <a class=\"xref\" href=\"/docs/18/libpq-connect.html#LIBPQ-CONNSTRING\" title=\"32.1.1.\u00a0Connection Strings\">Section\u00a032.1.1</a>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-s <em class=\"replaceable\"><code>dir</code></em></code><br></span><span class=\"term\"><code class=\"option\">--socketdir=<em class=\"replaceable\"><code>dir</code></em></code></span></dt>\n<dd>\n<p>The directory to use for postmaster sockets on target server. The default is current directory.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-t <em class=\"replaceable\"><code>seconds</code></em></code><br></span><span class=\"term\"><code class=\"option\">--recovery-timeout=<em class=\"replaceable\"><code>seconds</code></em></code></span></dt>\n<dd>\n<p>The maximum number of seconds to wait for recovery to end. Setting to 0 disables. The default is 0.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-T</code><br></span><span class=\"term\"><code class=\"option\">--enable-two-phase</code></span></dt>\n<dd>\n<p>Enables <a class=\"link\" href=\"/docs/18/sql-createsubscription.html#SQL-CREATESUBSCRIPTION-PARAMS-WITH-TWO-PHASE\"><code class=\"literal\">two_phase</code></a> commit for the subscription. When multiple databases are specified, this option applies uniformly to all subscriptions created on those databases. The default is <code class=\"literal\">false</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-U <em class=\"replaceable\"><code>username</code></em></code><br></span><span class=\"term\"><code class=\"option\">--subscriber-username=<em class=\"replaceable\"><code>username</code></em></code></span></dt>\n<dd>\n<p>The user name to connect as on target server. Defaults to the current operating system user name.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-v</code><br></span><span class=\"term\"><code class=\"option\">--verbose</code></span></dt>\n<dd>\n<p>Enables verbose mode. This will cause <span class=\"application\">pg_createsubscriber</span> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--clean=<em class=\"replaceable\"><code>objtype</code></em></code></span></dt>\n<dd>\n<p>Drop all objects of the specified type from specified databases on the target server.</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p><code class=\"literal\">publications</code>: The <code class=\"literal\">FOR ALL TABLES</code> 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.</p>\n</li>\n</ul>\n</div>\n<p>The objects selected to be dropped are individually logged, including during a <code class=\"option\">--dry-run</code>. There is no opportunity to affect or stop the dropping of the selected objects, so consider taking a backup of them using <span class=\"application\">pg_dump</span>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--config-file=<em class=\"replaceable\"><code>filename</code></em></code></span></dt>\n<dd>\n<p>Use the specified main server configuration file for the target data directory. <span class=\"application\">pg_createsubscriber</span> internally uses the <span class=\"application\">pg_ctl</span> command to start and stop the target server. It allows you to specify the actual <code class=\"filename\">postgresql.conf</code> configuration file if it is stored outside the data directory.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--publication=<em class=\"replaceable\"><code>name</code></em></code></span></dt>\n<dd>\n<p>The publication name to set up the logical replication. Multiple publications can be specified by writing multiple <code class=\"option\">--publication</code> 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 <code class=\"option\">--all</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--replication-slot=<em class=\"replaceable\"><code>name</code></em></code></span></dt>\n<dd>\n<p>The replication slot name to set up the logical replication. Multiple replication slots can be specified by writing multiple <code class=\"option\">--replication-slot</code> 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 <code class=\"option\">--all</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--subscription=<em class=\"replaceable\"><code>name</code></em></code></span></dt>\n<dd>\n<p>The subscription name to set up the logical replication. Multiple subscriptions can be specified by writing multiple <code class=\"option\">--subscription</code> 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 <code class=\"option\">--all</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-V</code><br></span><span class=\"term\"><code class=\"option\">--version</code></span></dt>\n<dd>\n<p>Print the <span class=\"application\">pg_createsubscriber</span> version and exit.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-?</code><br></span><span class=\"term\"><code class=\"option\">--help</code></span></dt>\n<dd>\n<p>Show help about <span class=\"application\">pg_createsubscriber</span> command line arguments, and exit.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.5.7.7\">\n<h2>Notes</h2>\n<div class=\"refsect2\" id=\"id-1.9.5.7.7.2\">\n<h3>Prerequisites</h3>\n<p>There are some prerequisites for <span class=\"application\">pg_createsubscriber</span> 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 <span class=\"application\">pg_createsubscriber</span>. 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 <a class=\"link\" href=\"/docs/18/sql-createsubscription.html\" title=\"CREATE SUBSCRIPTION\">subscriptions</a> and using <a class=\"link\" href=\"/docs/18/functions-admin.html#PG-REPLICATION-ORIGIN-ADVANCE\"><code class=\"function\">pg_replication_origin_advance()</code></a>.</p>\n<p>The target server must be used as a physical standby. The target server must have <a class=\"xref\" href=\"/docs/18/runtime-config-replication.html#GUC-MAX-ACTIVE-REPLICATION-ORIGINS\">max_active_replication_origins</a> and <a class=\"xref\" href=\"/docs/18/runtime-config-replication.html#GUC-MAX-LOGICAL-REPLICATION-WORKERS\">max_logical_replication_workers</a> configured to a value greater than or equal to the number of specified databases. The target server must have <a class=\"xref\" href=\"/docs/18/runtime-config-resource.html#GUC-MAX-WORKER-PROCESSES\">max_worker_processes</a> 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 <code class=\"option\">--enable-two-phase</code> switch then you will also need to set the <a class=\"xref\" href=\"/docs/18/runtime-config-resource.html#GUC-MAX-PREPARED-TRANSACTIONS\">max_prepared_transactions</a> appropriately.</p>\n<p>The source server must accept connections from the target server. The source server must not be in recovery. The source server must have <a class=\"xref\" href=\"/docs/18/runtime-config-wal.html#GUC-WAL-LEVEL\">wal_level</a> as <code class=\"literal\">logical</code>. The source server must have <a class=\"xref\" href=\"/docs/18/runtime-config-replication.html#GUC-MAX-REPLICATION-SLOTS\">max_replication_slots</a> configured to a value greater than or equal to the number of specified databases plus existing replication slots. The source server must have <a class=\"xref\" href=\"/docs/18/runtime-config-replication.html#GUC-MAX-WAL-SENDERS\">max_wal_senders</a> configured to a value greater than or equal to the number of specified databases and existing WAL sender processes.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.5.7.7.3\">\n<h3>Warnings</h3>\n<p>If <span class=\"application\">pg_createsubscriber</span> 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.</p>\n<p><span class=\"application\">pg_createsubscriber</span> usually starts the target server with different connection settings during transformation. Hence, connections to the target server should fail.</p>\n<p>Since DDL commands are not replicated by logical replication, avoid executing DDL commands that change the database schema while running <span class=\"application\">pg_createsubscriber</span>. If the target server has already been converted to logical replica, the DDL commands might not be replicated, which might cause an error.</p>\n<p>If <span class=\"application\">pg_createsubscriber</span> 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.</p>\n<p>If the replication is using <a class=\"xref\" href=\"/docs/18/runtime-config-replication.html#GUC-PRIMARY-SLOT-NAME\">primary_slot_name</a>, it will be removed from the source server after the logical replication setup.</p>\n<p>If the target server is a synchronous replica, transaction commits on the primary might wait for replication while running <span class=\"application\">pg_createsubscriber</span>.</p>\n<p>Unless the <code class=\"option\">--enable-two-phase</code> switch is specified, <span class=\"application\">pg_createsubscriber</span> sets up logical replication with two-phase commit disabled. This means that any prepared transactions will be replicated at the time of <code class=\"command\">COMMIT PREPARED</code>, without advance preparation. Once setup is complete, you can manually drop and re-create the subscription(s) with the <a class=\"link\" href=\"/docs/18/sql-createsubscription.html#SQL-CREATESUBSCRIPTION-PARAMS-WITH-TWO-PHASE\"><code class=\"literal\">two_phase</code></a> option enabled.</p>\n<p><span class=\"application\">pg_createsubscriber</span> changes the system identifier using <span class=\"application\">pg_resetwal</span>. 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.</p>\n<p>Replication failures can occur if required WAL files are missing. To prevent this, the source server must set <a class=\"xref\" href=\"/docs/18/runtime-config-replication.html#GUC-MAX-SLOT-WAL-KEEP-SIZE\">max_slot_wal_keep_size</a> to <code class=\"literal\">-1</code> to ensure that required WAL files are not prematurely removed.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.5.7.7.4\">\n<h3>How It Works</h3>\n<p>The basic idea is to have a replication start point from the source server and set up a logical replication to start from this point:</p>\n<div class=\"procedure\">\n<ol class=\"procedure\">\n<li class=\"step\">\n<p>Start the target server with the specified command-line options. If the target server is already running, <span class=\"application\">pg_createsubscriber</span> will terminate with an error.</p>\n</li>\n<li class=\"step\">\n<p>Check 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, <span class=\"application\">pg_createsubscriber</span> will terminate with an error.</p>\n</li>\n<li class=\"step\">\n<p>Create a publication and replication slot for each specified database on the source server. Each publication is created using <a class=\"link\" href=\"/docs/18/sql-createpublication.html#SQL-CREATEPUBLICATION-PARAMS-FOR-ALL-TABLES\"><code class=\"literal\">FOR ALL TABLES</code></a>. If the <code class=\"option\">--publication</code> option is not specified, the publication has the following name pattern: <span class=\"quote\">\u201c<span class=\"quote\"><code class=\"literal\">pg_createsubscriber_%u_%x</code></span>\u201d</span> (parameter: database <em class=\"parameter\"><code>oid</code></em>, random <em class=\"parameter\"><code>int</code></em>). If the <code class=\"option\">--replication-slot</code> option is not specified, the replication slot has the following name pattern: <span class=\"quote\">\u201c<span class=\"quote\"><code class=\"literal\">pg_createsubscriber_%u_%x</code></span>\u201d</span> (parameters: database <em class=\"parameter\"><code>oid</code></em>, random <em class=\"parameter\"><code>int</code></em>). 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 <a class=\"xref\" href=\"/docs/18/runtime-config-wal.html#GUC-RECOVERY-TARGET-LSN\">recovery_target_lsn</a> parameter and by the subscriptions as a replication start point. It guarantees that no transaction will be lost.</p>\n</li>\n<li class=\"step\">\n<p>Write recovery parameters into the target data directory and restart the target server. It specifies an LSN (<a class=\"xref\" href=\"/docs/18/runtime-config-wal.html#GUC-RECOVERY-TARGET-LSN\">recovery_target_lsn</a>) of the write-ahead log location up to which recovery will proceed. It also specifies <code class=\"literal\">promote</code> as the action that the server should take once the recovery target is reached. Additional <a class=\"link\" href=\"/docs/18/runtime-config-wal.html#RUNTIME-CONFIG-WAL-RECOVERY-TARGET\" title=\"19.5.6.\u00a0Recovery Target\">recovery parameters</a> 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 <code class=\"option\">--recovery-timeout</code> option is set, <span class=\"application\">pg_createsubscriber</span> terminates if recovery does not end until the given number of seconds.</p>\n</li>\n<li class=\"step\">\n<p>Create a subscription for each specified database on the target server. If the <code class=\"option\">--subscription</code> option is not specified, the subscription has the following name pattern: <span class=\"quote\">\u201c<span class=\"quote\"><code class=\"literal\">pg_createsubscriber_%u_%x</code></span>\u201d</span> (parameters: database <em class=\"parameter\"><code>oid</code></em>, random <em class=\"parameter\"><code>int</code></em>). 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.</p>\n</li>\n<li class=\"step\">\n<p>Drop publications on the target server that were replicated because they were created before the replication start location. It has no use on the subscriber.</p>\n</li>\n<li class=\"step\">\n<p>Set 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 <a class=\"link\" href=\"/docs/18/functions-admin.html#PG-REPLICATION-ORIGIN-ADVANCE\"><code class=\"function\">pg_replication_origin_advance()</code></a> to set up the initial replication location.</p>\n</li>\n<li class=\"step\">\n<p>Enable the subscription for each specified database on the target server. The subscription starts applying transactions from the replication start point.</p>\n</li>\n<li class=\"step\">\n<p>If the standby server was using <a class=\"xref\" href=\"/docs/18/runtime-config-replication.html#GUC-PRIMARY-SLOT-NAME\">primary_slot_name</a>, it has no use from now on so drop it.</p>\n</li>\n<li class=\"step\">\n<p>If the standby server contains <a class=\"link\" href=\"/docs/18/logicaldecoding-explanation.html#LOGICALDECODING-REPLICATION-SLOTS-SYNCHRONIZATION\" title=\"47.2.3.\u00a0Replication Slot Synchronization\">failover replication slots</a>, they cannot be synchronized anymore, so drop them.</p>\n</li>\n<li class=\"step\">\n<p>Update the system identifier on the target server. The <a class=\"xref\" href=\"/docs/18/app-pgresetwal.html\" title=\"pg_resetwal\"><span class=\"refentrytitle\"><span class=\"application\">pg_resetwal</span></span></a> is run to modify the system identifier. The target server is stopped as a <code class=\"command\">pg_resetwal</code> requirement.</p>\n</li>\n</ol>\n</div>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.5.7.8\">\n<h2>Examples</h2>\n<p>To create a logical replica for databases <code class=\"literal\">hr</code> and <code class=\"literal\">finance</code> from a physical replica at <code class=\"literal\">foo</code>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_createsubscriber -D /usr/local/pgsql/data -P \"host=foo\" -d hr -d finance</code></strong>\n</pre>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.5.7.9\">\n<h2>See Also</h2><span class=\"simplelist\"><a class=\"xref\" href=\"/docs/18/app-pgbasebackup.html\" title=\"pg_basebackup\"><span class=\"refentrytitle\"><span class=\"application\">pg_basebackup</span></span></a></span>\n</div>\n</div></div>", "manual_path": "app-pgcreatesubscriber.html", "comparison_data": {"options": [{"names": ["-a", "--all"], "signature": "-a --all", "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": ["-d dbname", "--database= dbname"], "signature": "-d dbname --database= dbname", "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 directory", "--pgdata= directory"], "signature": "-D directory --pgdata= directory", "description": "The target directory that contains a cluster directory from a physical replica."}, {"names": ["-n", "--dry-run"], "signature": "-n --dry-run", "description": "Do everything except actually modifying the target directory."}, {"names": ["-p port", "--subscriber-port= port"], "signature": "-p port --subscriber-port= port", "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 connstr", "--publisher-server= connstr"], "signature": "-P connstr --publisher-server= connstr", "description": "The connection string to the publisher. For details see Section 32.1.1 ."}, {"names": ["-s dir", "--socketdir= dir"], "signature": "-s dir --socketdir= dir", "description": "The directory to use for postmaster sockets on target server. The default is current directory."}, {"names": ["-t seconds", "--recovery-timeout= seconds"], "signature": "-t seconds --recovery-timeout= seconds", "description": "The maximum number of seconds to wait for recovery to end. Setting to 0 disables. The default is 0."}, {"names": ["-T", "--enable-two-phase"], "signature": "-T --enable-two-phase", "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": ["-U username", "--subscriber-username= username"], "signature": "-U username --subscriber-username= username", "description": "The user name to connect as on target server. Defaults to the current operating system user name."}, {"names": ["-v", "--verbose"], "signature": "-v --verbose", "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": ["--clean= objtype"], "signature": "--clean= objtype", "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": ["--config-file= filename"], "signature": "--config-file= filename", "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": ["--publication= name"], "signature": "--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": ["--replication-slot= name"], "signature": "--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": ["--subscription= name"], "signature": "--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": ["-V", "--version"], "signature": "-V --version", "description": "Print the pg_createsubscriber version and exit."}, {"names": ["-?", "--help"], "signature": "-? --help", "description": "Show help about pg_createsubscriber command line arguments, and exit."}], "synopsis": ["pg_createsubscriber [ option ...] { -d | --database } dbname { -D | --pgdata } datadir { -P | --publisher-server } connstr"], "environment": []}, "comparison_hash": "ab2f9ba9dc71a377cdb3a682c66b1a84f3cb3ae29cb8c1b178c5acc418bc4441"}, "19": {"facts": [{"label": "Documented executable", "value": "pg_createsubscriber"}, {"label": "Executable version", "value": "19beta4"}, {"label": "Reference inventory", "value": "Server applications"}, {"label": "Option definition groups", "value": "19"}], "tables": [{"key": "options", "rows": [{"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": {"url": "/docs/19/app-pgcreatesubscriber.html", "text": "-a --all"}}, {"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": {"url": "/docs/19/app-pgcreatesubscriber.html", "text": "-d dbname --database= dbname"}}, {"summary": "The target directory that contains a cluster directory from a physical replica.", "signature": {"url": "/docs/19/app-pgcreatesubscriber.html", "text": "-D datadir --pgdata= datadir"}}, {"summary": "Specify the name of the log directory. A new directory is created with this name if it does not exist. A subdirectory with a timestamp indicating the time at which pg_createsubscriber was run will be created. The following two log files will be created in the subdirectory.", "signature": {"url": "/docs/19/app-pgcreatesubscriber.html", "text": "-l directory --logdir= directory"}}, {"summary": "Do everything except actually modifying the target directory.", "signature": {"url": "/docs/19/app-pgcreatesubscriber.html", "text": "-n --dry-run"}}, {"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": {"url": "/docs/19/app-pgcreatesubscriber.html", "text": "-p port --subscriber-port= port"}}, {"summary": "The connection string to the publisher. For details see Section 32.1.1 .", "signature": {"url": "/docs/19/app-pgcreatesubscriber.html", "text": "-P connstr --publisher-server= connstr"}}, {"summary": "The directory to use for postmaster sockets on target server. The default is current directory.", "signature": {"url": "/docs/19/app-pgcreatesubscriber.html", "text": "-s dir --socketdir= dir"}}, {"summary": "The maximum number of seconds to wait for recovery to end. Setting to 0 disables. The default is 0.", "signature": {"url": "/docs/19/app-pgcreatesubscriber.html", "text": "-t seconds --recovery-timeout= seconds"}}, {"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": {"url": "/docs/19/app-pgcreatesubscriber.html", "text": "-T --enable-two-phase"}}, {"summary": "The user name to connect as on target server. Defaults to the current operating system user name.", "signature": {"url": "/docs/19/app-pgcreatesubscriber.html", "text": "-U username --subscriber-username= username"}}, {"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": {"url": "/docs/19/app-pgcreatesubscriber.html", "text": "-v --verbose"}}, {"summary": "Drop all objects of the specified type from specified databases on the target server.", "signature": {"url": "/docs/19/app-pgcreatesubscriber.html", "text": "--clean= objtype"}}, {"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": {"url": "/docs/19/app-pgcreatesubscriber.html", "text": "--config-file= filename"}}, {"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": {"url": "/docs/19/app-pgcreatesubscriber.html", "text": "--publication= name"}}, {"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": {"url": "/docs/19/app-pgcreatesubscriber.html", "text": "--replication-slot= name"}}, {"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": {"url": "/docs/19/app-pgcreatesubscriber.html", "text": "--subscription= name"}}, {"summary": "Print the pg_createsubscriber version and exit.", "signature": {"url": "/docs/19/app-pgcreatesubscriber.html", "text": "-V --version"}}, {"summary": "Show help about pg_createsubscriber command line arguments, and exit.", "signature": {"url": "/docs/19/app-pgcreatesubscriber.html", "text": "-? --help"}}], "title": "Documented options", "columns": [{"key": "signature", "label": "Option and arguments"}, {"key": "summary", "label": "Description"}]}], "options": [{"names": ["-a", "--all"], "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": "-a --all", "source_url": "/docs/19/app-pgcreatesubscriber.html", "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": ["-d dbname", "--database= dbname"], "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": "-d dbname --database= dbname", "source_url": "/docs/19/app-pgcreatesubscriber.html", "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 datadir", "--pgdata= datadir"], "summary": "The target directory that contains a cluster directory from a physical replica.", "signature": "-D datadir --pgdata= datadir", "source_url": "/docs/19/app-pgcreatesubscriber.html", "description": "The target directory that contains a cluster directory from a physical replica."}, {"names": ["-l directory", "--logdir= directory"], "summary": "Specify the name of the log directory. A new directory is created with this name if it does not exist. A subdirectory with a timestamp indicating the time at which pg_createsubscriber was run will be created. The following two log files will be created in the subdirectory.", "signature": "-l directory --logdir= directory", "source_url": "/docs/19/app-pgcreatesubscriber.html", "description": "Specify the name of the log directory. A new directory is created with this name if it does not exist. A subdirectory with a timestamp indicating the time at which pg_createsubscriber was run will be created. The following two log files will be created in the subdirectory. pg_createsubscriber_server.log which captures logs related to stopping and starting the standby server, pg_createsubscriber_internal.log which captures internal diagnostic output (validations, checks, etc.) By default, the umask is set to 077 so that the log files are only readable by the user running the command. However, if the target data directory is configured to allow group-read access, pg_createsubscriber will adjust the log file permissions to match. This ensures that the log file security remains consistent with the database cluster itself."}, {"names": ["-n", "--dry-run"], "summary": "Do everything except actually modifying the target directory.", "signature": "-n --dry-run", "source_url": "/docs/19/app-pgcreatesubscriber.html", "description": "Do everything except actually modifying the target directory."}, {"names": ["-p port", "--subscriber-port= port"], "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": "-p port --subscriber-port= port", "source_url": "/docs/19/app-pgcreatesubscriber.html", "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 connstr", "--publisher-server= connstr"], "summary": "The connection string to the publisher. For details see Section 32.1.1 .", "signature": "-P connstr --publisher-server= connstr", "source_url": "/docs/19/app-pgcreatesubscriber.html", "description": "The connection string to the publisher. For details see Section 32.1.1 ."}, {"names": ["-s dir", "--socketdir= dir"], "summary": "The directory to use for postmaster sockets on target server. The default is current directory.", "signature": "-s dir --socketdir= dir", "source_url": "/docs/19/app-pgcreatesubscriber.html", "description": "The directory to use for postmaster sockets on target server. The default is current directory."}, {"names": ["-t seconds", "--recovery-timeout= seconds"], "summary": "The maximum number of seconds to wait for recovery to end. Setting to 0 disables. The default is 0.", "signature": "-t seconds --recovery-timeout= seconds", "source_url": "/docs/19/app-pgcreatesubscriber.html", "description": "The maximum number of seconds to wait for recovery to end. Setting to 0 disables. The default is 0."}, {"names": ["-T", "--enable-two-phase"], "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": "-T --enable-two-phase", "source_url": "/docs/19/app-pgcreatesubscriber.html", "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": ["-U username", "--subscriber-username= username"], "summary": "The user name to connect as on target server. Defaults to the current operating system user name.", "signature": "-U username --subscriber-username= username", "source_url": "/docs/19/app-pgcreatesubscriber.html", "description": "The user name to connect as on target server. Defaults to the current operating system user name."}, {"names": ["-v", "--verbose"], "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": "-v --verbose", "source_url": "/docs/19/app-pgcreatesubscriber.html", "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": ["--clean= objtype"], "summary": "Drop all objects of the specified type from specified databases on the target server.", "signature": "--clean= objtype", "source_url": "/docs/19/app-pgcreatesubscriber.html", "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": ["--config-file= filename"], "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": "--config-file= filename", "source_url": "/docs/19/app-pgcreatesubscriber.html", "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": ["--publication= name"], "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": "--publication= name", "source_url": "/docs/19/app-pgcreatesubscriber.html", "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 . If a specified publication already exists on the publisher, it is reused. It is useful to partially replicate the database if the specified publication includes a list of tables. If the publication does not exist, it is automatically created with FOR ALL TABLES . Use --dry-run option to preview which publications will be reused and which will be created."}, {"names": ["--replication-slot= name"], "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": "--replication-slot= name", "source_url": "/docs/19/app-pgcreatesubscriber.html", "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": ["--subscription= name"], "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": "--subscription= name", "source_url": "/docs/19/app-pgcreatesubscriber.html", "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": ["-V", "--version"], "summary": "Print the pg_createsubscriber version and exit.", "signature": "-V --version", "source_url": "/docs/19/app-pgcreatesubscriber.html", "description": "Print the pg_createsubscriber version and exit."}, {"names": ["-?", "--help"], "summary": "Show help about pg_createsubscriber command line arguments, and exit.", "signature": "-? --help", "source_url": "/docs/19/app-pgcreatesubscriber.html", "description": "Show help about pg_createsubscriber command line arguments, and exit."}], "related": [], "release": {"ref": "https://ftp.postgresql.org/pub/source/v19beta4/postgresql-19beta4.tar.bz2", "label": "19beta4", "major": "19", "channel": "preview", "manifest": {"pdf": {"A4": {"url": "/files/documentation/pdf/19/postgresql-19-A4.pdf", "bytes": 16064841, "pages": 3052, "sha256": "4dd099e4125c591128fc5f3ebd02178dc24781f9e5ae629f96d67c4c8547427b", "built_at": "2026-09-26"}, "US": {"url": "/files/documentation/pdf/19/postgresql-19-US.pdf", "bytes": 15974616, "pages": 3225, "sha256": "61971fa857f0956d47341a0388fa6af9ae10acf691d4b2fc009007d384b0342b", "built_at": "2026-09-26"}}, "tree": "19", "index": "index.html", "major": "19", "pages": 1155, "release": "19beta4", "source_url": "https://ftp.postgresql.org/pub/source/v19beta4/postgresql-19beta4.tar.bz2", "svg_assets": 5, "source_mode": "en SGML built with pinned official archive", "source_sha256": "83157ee9c599d03b2f7a3d73ef3a56ec24e0e79cc2b3501a64d1364f56398c86"}, "revision": "1bbbbf4133d426f0e4304010688d2984c30fb67df0cc3a61b3e37eb3f6f37833", "evidence_kind": "English manual and source declarations", "source_sha256": "83157ee9c599d03b2f7a3d73ef3a56ec24e0e79cc2b3501a64d1364f56398c86"}, "sources": [{"url": "/docs/19/app-pgcreatesubscriber.html", "file": "app-pgcreatesubscriber.html", "label": "19beta4 English manual \u00b7 app-pgcreatesubscriber.html", "anchor": "", "sha256": "b80fa11097ac7787e12ec63969d98dbf47c367fddcc5edc87271f213dd4a07df"}, {"url": "/docs/19/reference-server.html", "file": "reference-server.html", "label": "Server applications inventory", "anchor": "", "sha256": "425b070323b448b5516d2cb4e9e4ac77efb5d19dd4e8005d0ae1c61db9ec78e6"}], "sections": [], "synopsis": ["pg_createsubscriber [ option ...] { -d | --database } dbname { -D | --pgdata } datadir { -P | --publisher-server } connstr"], "signature": "pg_createsubscriber [ option ...] { -d | --database } dbname { -D | --pgdata } datadir { -P | --publisher-server } connstr", "description": ["pg_createsubscriber \u2014 convert a physical replica into a new logical replica"], "environment": [], "manual_html": "<div><div class=\"refentry\" id=\"APP-PGCREATESUBSCRIBER\">\n<div class=\"titlepage\"></div>\n<div class=\"refnamediv\">\n<h2><span class=\"refentrytitle\"><span class=\"application\">pg_createsubscriber</span></span></h2>\n<p>pg_createsubscriber \u2014 convert a physical replica into a new logical replica</p>\n</div>\n<div class=\"refsynopsisdiv\">\n<h2>Synopsis</h2>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.5.7.4.1\"><code class=\"command\">pg_createsubscriber</code> [<em class=\"replaceable\"><code>option</code></em>...] { <code class=\"option\">-d</code> | <code class=\"option\">--database</code> } <em class=\"replaceable\"><code>dbname</code></em> { <code class=\"option\">-D</code> | <code class=\"option\">--pgdata</code> } <em class=\"replaceable\"><code>datadir</code></em> { <code class=\"option\">-P</code> | <code class=\"option\">--publisher-server</code> } <em class=\"replaceable\"><code>connstr</code></em></p>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.5.7.5\">\n<h2>Description</h2>\n<p><span class=\"application\">pg_createsubscriber</span> creates a new logical replica from a physical standby server. All tables in the specified database are included in the <a class=\"link\" href=\"/docs/19/logical-replication.html\" title=\"Chapter\u00a029.\u00a0Logical Replication\">logical replication</a> setup. A pair of publication and subscription objects are created for each database. It must be run at the target server.</p>\n<p>After 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 <span class=\"application\">pg_createsubscriber</span> is how the data synchronization is done. <span class=\"application\">pg_createsubscriber</span> does not copy the initial table data. It does only the synchronization phase, which ensures each table is brought up to a synchronized state.</p>\n<p><span class=\"application\">pg_createsubscriber</span> 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 <code class=\"command\">CREATE SUBSCRIPTION</code> <a class=\"link\" href=\"/docs/19/sql-createsubscription.html#SQL-CREATESUBSCRIPTION-PARAMS-WITH-COPY-DATA\"><code class=\"literal\">copy_data</code></a> option.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.5.7.6\">\n<h2>Options</h2>\n<p><span class=\"application\">pg_createsubscriber</span> accepts the following command-line arguments:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-a</code><br></span><span class=\"term\"><code class=\"option\">--all</code></span></dt>\n<dd>\n<p>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 <code class=\"option\">--publisher-server</code> connection string, or if not specified, the <code class=\"literal\">postgres</code> database will be used, or if that does not exist, <code class=\"literal\">template1</code> 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 <code class=\"option\">--database</code>, <code class=\"option\">--publication</code>, <code class=\"option\">--replication-slot</code>, or <code class=\"option\">--subscription</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-d <em class=\"replaceable\"><code>dbname</code></em></code><br></span><span class=\"term\"><code class=\"option\">--database=<em class=\"replaceable\"><code>dbname</code></em></code></span></dt>\n<dd>\n<p>The name of the database in which to create a subscription. Multiple databases can be selected by writing multiple <code class=\"option\">-d</code> switches. This option cannot be used together with <code class=\"option\">-a</code>. If <code class=\"option\">-d</code> option is not provided, the database name will be obtained from <code class=\"option\">-P</code> option. If the database name is not specified in either the <code class=\"option\">-d</code> option, or the <code class=\"option\">-P</code> option, and <code class=\"option\">-a</code> option is not specified, an error will be reported.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-D <em class=\"replaceable\"><code>datadir</code></em></code><br></span><span class=\"term\"><code class=\"option\">--pgdata=<em class=\"replaceable\"><code>datadir</code></em></code></span></dt>\n<dd>\n<p>The target directory that contains a cluster directory from a physical replica.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-l <em class=\"replaceable\"><code>directory</code></em></code><br></span><span class=\"term\"><code class=\"option\">--logdir=<em class=\"replaceable\"><code>directory</code></em></code></span></dt>\n<dd>\n<p>Specify the name of the log directory. A new directory is created with this name if it does not exist. A subdirectory with a timestamp indicating the time at which <span class=\"application\">pg_createsubscriber</span> was run will be created. The following two log files will be created in the subdirectory.</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p><code class=\"filename\">pg_createsubscriber_server.log</code> which captures logs related to stopping and starting the standby server,</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"filename\">pg_createsubscriber_internal.log</code> which captures internal diagnostic output (validations, checks, etc.)</p>\n</li>\n</ul>\n</div>\n<p>By default, the <span class=\"systemitem\">umask</span> is set to 077 so that the log files are only readable by the user running the command. However, if the target data directory is configured to allow group-read access, <span class=\"application\">pg_createsubscriber</span> will adjust the log file permissions to match. This ensures that the log file security remains consistent with the database cluster itself.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--dry-run</code></span></dt>\n<dd>\n<p>Do everything except actually modifying the target directory.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-p <em class=\"replaceable\"><code>port</code></em></code><br></span><span class=\"term\"><code class=\"option\">--subscriber-port=<em class=\"replaceable\"><code>port</code></em></code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-P <em class=\"replaceable\"><code>connstr</code></em></code><br></span><span class=\"term\"><code class=\"option\">--publisher-server=<em class=\"replaceable\"><code>connstr</code></em></code></span></dt>\n<dd>\n<p>The connection string to the publisher. For details see <a class=\"xref\" href=\"/docs/19/libpq-connect.html#LIBPQ-CONNSTRING\" title=\"32.1.1.\u00a0Connection Strings\">Section\u00a032.1.1</a>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-s <em class=\"replaceable\"><code>dir</code></em></code><br></span><span class=\"term\"><code class=\"option\">--socketdir=<em class=\"replaceable\"><code>dir</code></em></code></span></dt>\n<dd>\n<p>The directory to use for postmaster sockets on target server. The default is current directory.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-t <em class=\"replaceable\"><code>seconds</code></em></code><br></span><span class=\"term\"><code class=\"option\">--recovery-timeout=<em class=\"replaceable\"><code>seconds</code></em></code></span></dt>\n<dd>\n<p>The maximum number of seconds to wait for recovery to end. Setting to 0 disables. The default is 0.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-T</code><br></span><span class=\"term\"><code class=\"option\">--enable-two-phase</code></span></dt>\n<dd>\n<p>Enables <a class=\"link\" href=\"/docs/19/sql-createsubscription.html#SQL-CREATESUBSCRIPTION-PARAMS-WITH-TWO-PHASE\"><code class=\"literal\">two_phase</code></a> commit for the subscription. When multiple databases are specified, this option applies uniformly to all subscriptions created on those databases. The default is <code class=\"literal\">false</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-U <em class=\"replaceable\"><code>username</code></em></code><br></span><span class=\"term\"><code class=\"option\">--subscriber-username=<em class=\"replaceable\"><code>username</code></em></code></span></dt>\n<dd>\n<p>The user name to connect as on target server. Defaults to the current operating system user name.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-v</code><br></span><span class=\"term\"><code class=\"option\">--verbose</code></span></dt>\n<dd>\n<p>Enables verbose mode. This will cause <span class=\"application\">pg_createsubscriber</span> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--clean=<em class=\"replaceable\"><code>objtype</code></em></code></span></dt>\n<dd>\n<p>Drop all objects of the specified type from specified databases on the target server.</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p><code class=\"literal\">publications</code>: The <code class=\"literal\">FOR ALL TABLES</code> 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.</p>\n</li>\n</ul>\n</div>\n<p>The objects selected to be dropped are individually logged, including during a <code class=\"option\">--dry-run</code>. There is no opportunity to affect or stop the dropping of the selected objects, so consider taking a backup of them using <span class=\"application\">pg_dump</span>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--config-file=<em class=\"replaceable\"><code>filename</code></em></code></span></dt>\n<dd>\n<p>Use the specified main server configuration file for the target data directory. <span class=\"application\">pg_createsubscriber</span> internally uses the <span class=\"application\">pg_ctl</span> command to start and stop the target server. It allows you to specify the actual <code class=\"filename\">postgresql.conf</code> configuration file if it is stored outside the data directory.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--publication=<em class=\"replaceable\"><code>name</code></em></code></span></dt>\n<dd>\n<p>The publication name to set up the logical replication. Multiple publications can be specified by writing multiple <code class=\"option\">--publication</code> 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 <code class=\"option\">--all</code>.</p>\n<p>If a specified publication already exists on the publisher, it is reused. It is useful to partially replicate the database if the specified publication includes a list of tables. If the publication does not exist, it is automatically created with <code class=\"literal\">FOR ALL TABLES</code>. Use <code class=\"option\">--dry-run</code> option to preview which publications will be reused and which will be created.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--replication-slot=<em class=\"replaceable\"><code>name</code></em></code></span></dt>\n<dd>\n<p>The replication slot name to set up the logical replication. Multiple replication slots can be specified by writing multiple <code class=\"option\">--replication-slot</code> 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 <code class=\"option\">--all</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--subscription=<em class=\"replaceable\"><code>name</code></em></code></span></dt>\n<dd>\n<p>The subscription name to set up the logical replication. Multiple subscriptions can be specified by writing multiple <code class=\"option\">--subscription</code> 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 <code class=\"option\">--all</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-V</code><br></span><span class=\"term\"><code class=\"option\">--version</code></span></dt>\n<dd>\n<p>Print the <span class=\"application\">pg_createsubscriber</span> version and exit.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-?</code><br></span><span class=\"term\"><code class=\"option\">--help</code></span></dt>\n<dd>\n<p>Show help about <span class=\"application\">pg_createsubscriber</span> command line arguments, and exit.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.5.7.7\">\n<h2>Notes</h2>\n<div class=\"refsect2\" id=\"id-1.9.5.7.7.2\">\n<h3>Prerequisites</h3>\n<p>There are some prerequisites for <span class=\"application\">pg_createsubscriber</span> 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 <span class=\"application\">pg_createsubscriber</span>. 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 <a class=\"link\" href=\"/docs/19/sql-createsubscription.html\" title=\"CREATE SUBSCRIPTION\">subscriptions</a> and using <a class=\"link\" href=\"/docs/19/functions-admin.html#PG-REPLICATION-ORIGIN-ADVANCE\"><code class=\"function\">pg_replication_origin_advance()</code></a>.</p>\n<p>The target server must be used as a physical standby. The target server must have <a class=\"xref\" href=\"/docs/19/runtime-config-replication.html#GUC-MAX-ACTIVE-REPLICATION-ORIGINS\">max_active_replication_origins</a> and <a class=\"xref\" href=\"/docs/19/runtime-config-replication.html#GUC-MAX-LOGICAL-REPLICATION-WORKERS\">max_logical_replication_workers</a> configured to a value greater than or equal to the number of specified databases. The target server must have <a class=\"xref\" href=\"/docs/19/runtime-config-resource.html#GUC-MAX-WORKER-PROCESSES\">max_worker_processes</a> 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 <code class=\"option\">--enable-two-phase</code> switch then you will also need to set the <a class=\"xref\" href=\"/docs/19/runtime-config-resource.html#GUC-MAX-PREPARED-TRANSACTIONS\">max_prepared_transactions</a> appropriately.</p>\n<p>The source server must accept connections from the target server. The source server must not be in recovery. The source server must have <a class=\"xref\" href=\"/docs/19/runtime-config-wal.html#GUC-WAL-LEVEL\">wal_level</a> as <code class=\"literal\">replica</code> or <code class=\"literal\">logical</code>. The source server must have <a class=\"xref\" href=\"/docs/19/runtime-config-replication.html#GUC-MAX-REPLICATION-SLOTS\">max_replication_slots</a> configured to a value greater than or equal to the number of specified databases plus existing replication slots. The source server must have <a class=\"xref\" href=\"/docs/19/runtime-config-replication.html#GUC-MAX-WAL-SENDERS\">max_wal_senders</a> configured to a value greater than or equal to the number of specified databases and existing WAL sender processes.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.5.7.7.3\">\n<h3>Warnings</h3>\n<p>If <span class=\"application\">pg_createsubscriber</span> 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.</p>\n<p><span class=\"application\">pg_createsubscriber</span> usually starts the target server with different connection settings during transformation. Hence, connections to the target server should fail.</p>\n<p>Since DDL commands are not replicated by logical replication, avoid executing DDL commands that change the database schema while running <span class=\"application\">pg_createsubscriber</span>. If the target server has already been converted to logical replica, the DDL commands might not be replicated, which might cause an error.</p>\n<p>If <span class=\"application\">pg_createsubscriber</span> 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.</p>\n<p>If the replication is using <a class=\"xref\" href=\"/docs/19/runtime-config-replication.html#GUC-PRIMARY-SLOT-NAME\">primary_slot_name</a>, it will be removed from the source server after the logical replication setup.</p>\n<p>If the target server is a synchronous replica, transaction commits on the primary might wait for replication while running <span class=\"application\">pg_createsubscriber</span>.</p>\n<p>Unless the <code class=\"option\">--enable-two-phase</code> switch is specified, <span class=\"application\">pg_createsubscriber</span> sets up logical replication with two-phase commit disabled. This means that any prepared transactions will be replicated at the time of <code class=\"command\">COMMIT PREPARED</code>, without advance preparation. Once setup is complete, you can manually drop and re-create the subscription(s) with the <a class=\"link\" href=\"/docs/19/sql-createsubscription.html#SQL-CREATESUBSCRIPTION-PARAMS-WITH-TWO-PHASE\"><code class=\"literal\">two_phase</code></a> option enabled.</p>\n<p><span class=\"application\">pg_createsubscriber</span> changes the system identifier using <span class=\"application\">pg_resetwal</span>. 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.</p>\n<p>Replication failures can occur if required WAL files are missing. To prevent this, the source server must set <a class=\"xref\" href=\"/docs/19/runtime-config-replication.html#GUC-MAX-SLOT-WAL-KEEP-SIZE\">max_slot_wal_keep_size</a> to <code class=\"literal\">-1</code> to ensure that required WAL files are not prematurely removed.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.5.7.7.4\">\n<h3>How It Works</h3>\n<p>The basic idea is to have a replication start point from the source server and set up a logical replication to start from this point:</p>\n<div class=\"procedure\">\n<ol class=\"procedure\">\n<li class=\"step\">\n<p>Start the target server with the specified command-line options. If the target server is already running, <span class=\"application\">pg_createsubscriber</span> will terminate with an error.</p>\n</li>\n<li class=\"step\">\n<p>Check 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, <span class=\"application\">pg_createsubscriber</span> will terminate with an error.</p>\n</li>\n<li class=\"step\">\n<p>Create a publication and replication slot for each specified database on the source server. Each publication is created using <a class=\"link\" href=\"/docs/19/sql-createpublication.html#SQL-CREATEPUBLICATION-PARAMS-FOR-ALL-TABLES\"><code class=\"literal\">FOR ALL TABLES</code></a>. If the <code class=\"option\">--publication</code> option is not specified, the publication has the following name pattern: <span class=\"quote\">\u201c<span class=\"quote\"><code class=\"literal\">pg_createsubscriber_%u_%x</code></span>\u201d</span> (parameter: database <em class=\"parameter\"><code>oid</code></em>, random <em class=\"parameter\"><code>int</code></em>). If the <code class=\"option\">--replication-slot</code> option is not specified, the replication slot has the following name pattern: <span class=\"quote\">\u201c<span class=\"quote\"><code class=\"literal\">pg_createsubscriber_%u_%x</code></span>\u201d</span> (parameters: database <em class=\"parameter\"><code>oid</code></em>, random <em class=\"parameter\"><code>int</code></em>). 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 <a class=\"xref\" href=\"/docs/19/runtime-config-wal.html#GUC-RECOVERY-TARGET-LSN\">recovery_target_lsn</a> parameter and by the subscriptions as a replication start point. It guarantees that no transaction will be lost.</p>\n</li>\n<li class=\"step\">\n<p>Write recovery parameters into the separate configuration file <code class=\"filename\">pg_createsubscriber.conf</code> that is included from <code class=\"filename\">postgresql.auto.conf</code> using <code class=\"literal\">include_if_exists</code> in the target data directory, then restart the target server. It specifies an LSN (<a class=\"xref\" href=\"/docs/19/runtime-config-wal.html#GUC-RECOVERY-TARGET-LSN\">recovery_target_lsn</a>) of the write-ahead log location up to which recovery will proceed. It also specifies <code class=\"literal\">promote</code> as the action that the server should take once the recovery target is reached. Additional <a class=\"link\" href=\"/docs/19/runtime-config-wal.html#RUNTIME-CONFIG-WAL-RECOVERY-TARGET\" title=\"19.5.6.\u00a0Recovery Target\">recovery parameters</a> 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 <code class=\"option\">--recovery-timeout</code> option is set, <span class=\"application\">pg_createsubscriber</span> terminates if recovery does not end until the given number of seconds. Upon completion, the included configuration file is renamed to <code class=\"filename\">pg_createsubscriber.conf.disabled</code> so as it is no longer loaded on subsequent restarts.</p>\n</li>\n<li class=\"step\">\n<p>Create a subscription for each specified database on the target server. If the <code class=\"option\">--subscription</code> option is not specified, the subscription has the following name pattern: <span class=\"quote\">\u201c<span class=\"quote\"><code class=\"literal\">pg_createsubscriber_%u_%x</code></span>\u201d</span> (parameters: database <em class=\"parameter\"><code>oid</code></em>, random <em class=\"parameter\"><code>int</code></em>). 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.</p>\n</li>\n<li class=\"step\">\n<p>Drop publications on the target server that were replicated because they were created before the replication start location. It has no use on the subscriber.</p>\n</li>\n<li class=\"step\">\n<p>Set 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 <a class=\"link\" href=\"/docs/19/functions-admin.html#PG-REPLICATION-ORIGIN-ADVANCE\"><code class=\"function\">pg_replication_origin_advance()</code></a> to set up the initial replication location.</p>\n</li>\n<li class=\"step\">\n<p>Enable the subscription for each specified database on the target server. The subscription starts applying transactions from the replication start point.</p>\n</li>\n<li class=\"step\">\n<p>If the standby server was using <a class=\"xref\" href=\"/docs/19/runtime-config-replication.html#GUC-PRIMARY-SLOT-NAME\">primary_slot_name</a>, it has no use from now on so drop it.</p>\n</li>\n<li class=\"step\">\n<p>If the standby server contains <a class=\"link\" href=\"/docs/19/logicaldecoding-explanation.html#LOGICALDECODING-REPLICATION-SLOTS-SYNCHRONIZATION\" title=\"47.2.3.\u00a0Replication Slot Synchronization\">failover replication slots</a>, they cannot be synchronized anymore, so drop them.</p>\n</li>\n<li class=\"step\">\n<p>Update the system identifier on the target server. The <a class=\"xref\" href=\"/docs/19/app-pgresetwal.html\" title=\"pg_resetwal\"><span class=\"refentrytitle\"><span class=\"application\">pg_resetwal</span></span></a> is run to modify the system identifier. The target server is stopped as a <code class=\"command\">pg_resetwal</code> requirement.</p>\n</li>\n</ol>\n</div>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.5.7.8\">\n<h2>Examples</h2>\n<p>To create a logical replica for databases <code class=\"literal\">hr</code> and <code class=\"literal\">finance</code> from a physical replica at <code class=\"literal\">foo</code>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_createsubscriber -D /usr/local/pgsql/data -P \"host=foo\" -d hr -d finance</code></strong>\n</pre>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.5.7.9\">\n<h2>See Also</h2><span class=\"simplelist\"><a class=\"xref\" href=\"/docs/19/app-pgbasebackup.html\" title=\"pg_basebackup\"><span class=\"refentrytitle\"><span class=\"application\">pg_basebackup</span></span></a></span>\n</div>\n</div></div>", "manual_path": "app-pgcreatesubscriber.html", "comparison_data": {"options": [{"names": ["-a", "--all"], "signature": "-a --all", "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": ["-d dbname", "--database= dbname"], "signature": "-d dbname --database= dbname", "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 datadir", "--pgdata= datadir"], "signature": "-D datadir --pgdata= datadir", "description": "The target directory that contains a cluster directory from a physical replica."}, {"names": ["-l directory", "--logdir= directory"], "signature": "-l directory --logdir= directory", "description": "Specify the name of the log directory. A new directory is created with this name if it does not exist. A subdirectory with a timestamp indicating the time at which pg_createsubscriber was run will be created. The following two log files will be created in the subdirectory. pg_createsubscriber_server.log which captures logs related to stopping and starting the standby server, pg_createsubscriber_internal.log which captures internal diagnostic output (validations, checks, etc.) By default, the umask is set to 077 so that the log files are only readable by the user running the command. However, if the target data directory is configured to allow group-read access, pg_createsubscriber will adjust the log file permissions to match. This ensures that the log file security remains consistent with the database cluster itself."}, {"names": ["-n", "--dry-run"], "signature": "-n --dry-run", "description": "Do everything except actually modifying the target directory."}, {"names": ["-p port", "--subscriber-port= port"], "signature": "-p port --subscriber-port= port", "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 connstr", "--publisher-server= connstr"], "signature": "-P connstr --publisher-server= connstr", "description": "The connection string to the publisher. For details see Section 32.1.1 ."}, {"names": ["-s dir", "--socketdir= dir"], "signature": "-s dir --socketdir= dir", "description": "The directory to use for postmaster sockets on target server. The default is current directory."}, {"names": ["-t seconds", "--recovery-timeout= seconds"], "signature": "-t seconds --recovery-timeout= seconds", "description": "The maximum number of seconds to wait for recovery to end. Setting to 0 disables. The default is 0."}, {"names": ["-T", "--enable-two-phase"], "signature": "-T --enable-two-phase", "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": ["-U username", "--subscriber-username= username"], "signature": "-U username --subscriber-username= username", "description": "The user name to connect as on target server. Defaults to the current operating system user name."}, {"names": ["-v", "--verbose"], "signature": "-v --verbose", "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": ["--clean= objtype"], "signature": "--clean= objtype", "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": ["--config-file= filename"], "signature": "--config-file= filename", "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": ["--publication= name"], "signature": "--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 . If a specified publication already exists on the publisher, it is reused. It is useful to partially replicate the database if the specified publication includes a list of tables. If the publication does not exist, it is automatically created with FOR ALL TABLES . Use --dry-run option to preview which publications will be reused and which will be created."}, {"names": ["--replication-slot= name"], "signature": "--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": ["--subscription= name"], "signature": "--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": ["-V", "--version"], "signature": "-V --version", "description": "Print the pg_createsubscriber version and exit."}, {"names": ["-?", "--help"], "signature": "-? --help", "description": "Show help about pg_createsubscriber command line arguments, and exit."}], "synopsis": ["pg_createsubscriber [ option ...] { -d | --database } dbname { -D | --pgdata } datadir { -P | --publisher-server } connstr"], "environment": []}, "comparison_hash": "b4807e2c2ddbf51e9e6cdd5c6c5a1cd58c95530174f72f8e053b38ce95c721d8"}, "20": {"facts": [{"label": "Documented executable", "value": "pg_createsubscriber"}, {"label": "Executable version", "value": "20devel"}, {"label": "Reference inventory", "value": "Server applications"}, {"label": "Option definition groups", "value": "19"}], "tables": [{"key": "options", "rows": [{"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": {"url": "/docs/devel/app-pgcreatesubscriber.html", "text": "-a --all"}}, {"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": {"url": "/docs/devel/app-pgcreatesubscriber.html", "text": "-d dbname --database= dbname"}}, {"summary": "The target directory that contains a cluster directory from a physical replica.", "signature": {"url": "/docs/devel/app-pgcreatesubscriber.html", "text": "-D datadir --pgdata= datadir"}}, {"summary": "Specify the name of the log directory. A new directory is created with this name if it does not exist. A subdirectory with a timestamp indicating the time at which pg_createsubscriber was run will be created. The following two log files will be created in the subdirectory.", "signature": {"url": "/docs/devel/app-pgcreatesubscriber.html", "text": "-l directory --logdir= directory"}}, {"summary": "Do everything except actually modifying the target directory.", "signature": {"url": "/docs/devel/app-pgcreatesubscriber.html", "text": "-n --dry-run"}}, {"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": {"url": "/docs/devel/app-pgcreatesubscriber.html", "text": "-p port --subscriber-port= port"}}, {"summary": "The connection string to the publisher. For details see Section 32.1.1 .", "signature": {"url": "/docs/devel/app-pgcreatesubscriber.html", "text": "-P connstr --publisher-server= connstr"}}, {"summary": "The directory to use for postmaster sockets on target server. The default is current directory.", "signature": {"url": "/docs/devel/app-pgcreatesubscriber.html", "text": "-s dir --socketdir= dir"}}, {"summary": "The maximum number of seconds to wait for recovery to end. Setting to 0 disables. The default is 0.", "signature": {"url": "/docs/devel/app-pgcreatesubscriber.html", "text": "-t seconds --recovery-timeout= seconds"}}, {"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": {"url": "/docs/devel/app-pgcreatesubscriber.html", "text": "-T --enable-two-phase"}}, {"summary": "The user name to connect as on target server. Defaults to the current operating system user name.", "signature": {"url": "/docs/devel/app-pgcreatesubscriber.html", "text": "-U username --subscriber-username= username"}}, {"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": {"url": "/docs/devel/app-pgcreatesubscriber.html", "text": "-v --verbose"}}, {"summary": "Drop all objects of the specified type from specified databases on the target server.", "signature": {"url": "/docs/devel/app-pgcreatesubscriber.html", "text": "--clean= objtype"}}, {"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": {"url": "/docs/devel/app-pgcreatesubscriber.html", "text": "--config-file= filename"}}, {"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": {"url": "/docs/devel/app-pgcreatesubscriber.html", "text": "--publication= name"}}, {"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": {"url": "/docs/devel/app-pgcreatesubscriber.html", "text": "--replication-slot= name"}}, {"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": {"url": "/docs/devel/app-pgcreatesubscriber.html", "text": "--subscription= name"}}, {"summary": "Print the pg_createsubscriber version and exit.", "signature": {"url": "/docs/devel/app-pgcreatesubscriber.html", "text": "-V --version"}}, {"summary": "Show help about pg_createsubscriber command line arguments, and exit.", "signature": {"url": "/docs/devel/app-pgcreatesubscriber.html", "text": "-? --help"}}], "title": "Documented options", "columns": [{"key": "signature", "label": "Option and arguments"}, {"key": "summary", "label": "Description"}]}], "options": [{"names": ["-a", "--all"], "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": "-a --all", "source_url": "/docs/devel/app-pgcreatesubscriber.html", "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": ["-d dbname", "--database= dbname"], "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": "-d dbname --database= dbname", "source_url": "/docs/devel/app-pgcreatesubscriber.html", "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 datadir", "--pgdata= datadir"], "summary": "The target directory that contains a cluster directory from a physical replica.", "signature": "-D datadir --pgdata= datadir", "source_url": "/docs/devel/app-pgcreatesubscriber.html", "description": "The target directory that contains a cluster directory from a physical replica."}, {"names": ["-l directory", "--logdir= directory"], "summary": "Specify the name of the log directory. A new directory is created with this name if it does not exist. A subdirectory with a timestamp indicating the time at which pg_createsubscriber was run will be created. The following two log files will be created in the subdirectory.", "signature": "-l directory --logdir= directory", "source_url": "/docs/devel/app-pgcreatesubscriber.html", "description": "Specify the name of the log directory. A new directory is created with this name if it does not exist. A subdirectory with a timestamp indicating the time at which pg_createsubscriber was run will be created. The following two log files will be created in the subdirectory. pg_createsubscriber_server.log which captures logs related to stopping and starting the standby server, pg_createsubscriber_internal.log which captures internal diagnostic output (validations, checks, etc.) By default, the umask is set to 077 so that the log files are only readable by the user running the command. However, if the target data directory is configured to allow group-read access, pg_createsubscriber will adjust the log file permissions to match. This ensures that the log file security remains consistent with the database cluster itself."}, {"names": ["-n", "--dry-run"], "summary": "Do everything except actually modifying the target directory.", "signature": "-n --dry-run", "source_url": "/docs/devel/app-pgcreatesubscriber.html", "description": "Do everything except actually modifying the target directory."}, {"names": ["-p port", "--subscriber-port= port"], "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": "-p port --subscriber-port= port", "source_url": "/docs/devel/app-pgcreatesubscriber.html", "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 connstr", "--publisher-server= connstr"], "summary": "The connection string to the publisher. For details see Section 32.1.1 .", "signature": "-P connstr --publisher-server= connstr", "source_url": "/docs/devel/app-pgcreatesubscriber.html", "description": "The connection string to the publisher. For details see Section 32.1.1 ."}, {"names": ["-s dir", "--socketdir= dir"], "summary": "The directory to use for postmaster sockets on target server. The default is current directory.", "signature": "-s dir --socketdir= dir", "source_url": "/docs/devel/app-pgcreatesubscriber.html", "description": "The directory to use for postmaster sockets on target server. The default is current directory."}, {"names": ["-t seconds", "--recovery-timeout= seconds"], "summary": "The maximum number of seconds to wait for recovery to end. Setting to 0 disables. The default is 0.", "signature": "-t seconds --recovery-timeout= seconds", "source_url": "/docs/devel/app-pgcreatesubscriber.html", "description": "The maximum number of seconds to wait for recovery to end. Setting to 0 disables. The default is 0."}, {"names": ["-T", "--enable-two-phase"], "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": "-T --enable-two-phase", "source_url": "/docs/devel/app-pgcreatesubscriber.html", "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": ["-U username", "--subscriber-username= username"], "summary": "The user name to connect as on target server. Defaults to the current operating system user name.", "signature": "-U username --subscriber-username= username", "source_url": "/docs/devel/app-pgcreatesubscriber.html", "description": "The user name to connect as on target server. Defaults to the current operating system user name."}, {"names": ["-v", "--verbose"], "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": "-v --verbose", "source_url": "/docs/devel/app-pgcreatesubscriber.html", "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": ["--clean= objtype"], "summary": "Drop all objects of the specified type from specified databases on the target server.", "signature": "--clean= objtype", "source_url": "/docs/devel/app-pgcreatesubscriber.html", "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": ["--config-file= filename"], "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": "--config-file= filename", "source_url": "/docs/devel/app-pgcreatesubscriber.html", "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": ["--publication= name"], "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": "--publication= name", "source_url": "/docs/devel/app-pgcreatesubscriber.html", "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 . If a specified publication already exists on the publisher, it is reused. It is useful to partially replicate the database if the specified publication includes a list of tables. If the publication does not exist, it is automatically created with FOR ALL TABLES . Use --dry-run option to preview which publications will be reused and which will be created."}, {"names": ["--replication-slot= name"], "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": "--replication-slot= name", "source_url": "/docs/devel/app-pgcreatesubscriber.html", "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": ["--subscription= name"], "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": "--subscription= name", "source_url": "/docs/devel/app-pgcreatesubscriber.html", "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": ["-V", "--version"], "summary": "Print the pg_createsubscriber version and exit.", "signature": "-V --version", "source_url": "/docs/devel/app-pgcreatesubscriber.html", "description": "Print the pg_createsubscriber version and exit."}, {"names": ["-?", "--help"], "summary": "Show help about pg_createsubscriber command line arguments, and exit.", "signature": "-? --help", "source_url": "/docs/devel/app-pgcreatesubscriber.html", "description": "Show help about pg_createsubscriber command line arguments, and exit."}], "related": [], "release": {"ref": "https://ftp.postgresql.org/pub/snapshot/dev/postgresql-snapshot.tar.bz2", "label": "20devel", "major": "20", "channel": "devel", "manifest": {"pdf": {"A4": {"url": "/files/documentation/pdf/20/postgresql-20-A4.pdf", "bytes": 16030631, "pages": 3052, "sha256": "bd5d82c0ce38fc18f92a0447818a91a193a261776bca1c37564bf9a683e177d0", "built_at": "2026-09-28"}, "US": {"url": "/files/documentation/pdf/20/postgresql-20-US.pdf", "bytes": 15936613, "pages": 3223, "sha256": "d97d9e0db479a02f4234b175f50fcad70c3661619afc8d6df9b9437882e3c299", "built_at": "2026-09-28"}}, "tree": "0", "index": "index.html", "major": "20", "pages": 1156, "release": "20devel", "source_url": "https://ftp.postgresql.org/pub/snapshot/dev/postgresql-snapshot.tar.bz2", "svg_assets": 6, "source_mode": "en SGML built with pinned official archive", "source_sha256": "4d3346909b201ac1648232cf290462a7070c119326f56196f1f0253ed80fae41", "source_snapshot_utc": "26-Sep-2026 20:22"}, "revision": "2eba5e0fd4c3bffb2803247b6cd537878e9d6ee5a6dfbe3c50ece8b421b80918", "evidence_kind": "English manual and source declarations", "source_sha256": "4d3346909b201ac1648232cf290462a7070c119326f56196f1f0253ed80fae41"}, "sources": [{"url": "/docs/devel/app-pgcreatesubscriber.html", "file": "app-pgcreatesubscriber.html", "label": "20devel English manual \u00b7 app-pgcreatesubscriber.html", "anchor": "", "sha256": "55e90fc7b3d88304ec0ec7d8793a2f0993d82a397b09d5436ec2637e3aa47ba3"}, {"url": "/docs/devel/reference-server.html", "file": "reference-server.html", "label": "Server applications inventory", "anchor": "", "sha256": "5532c1ebfb8c6f310301be63a28daf0ae212e2a78025bea61a1bdca99e02c43d"}], "sections": [], "synopsis": ["pg_createsubscriber [ option ...] { -d | --database } dbname { -D | --pgdata } datadir { -P | --publisher-server } connstr"], "signature": "pg_createsubscriber [ option ...] { -d | --database } dbname { -D | --pgdata } datadir { -P | --publisher-server } connstr", "description": ["pg_createsubscriber \u2014 convert a physical replica into a new logical replica"], "environment": [], "manual_html": "<div><div class=\"refentry\" id=\"APP-PGCREATESUBSCRIBER\">\n<div class=\"titlepage\"></div>\n<div class=\"refnamediv\">\n<h2><span class=\"refentrytitle\"><span class=\"application\">pg_createsubscriber</span></span></h2>\n<p>pg_createsubscriber \u2014 convert a physical replica into a new logical replica</p>\n</div>\n<div class=\"refsynopsisdiv\">\n<h2>Synopsis</h2>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.5.7.4.1\"><code class=\"command\">pg_createsubscriber</code> [<em class=\"replaceable\"><code>option</code></em>...] { <code class=\"option\">-d</code> | <code class=\"option\">--database</code> } <em class=\"replaceable\"><code>dbname</code></em> { <code class=\"option\">-D</code> | <code class=\"option\">--pgdata</code> } <em class=\"replaceable\"><code>datadir</code></em> { <code class=\"option\">-P</code> | <code class=\"option\">--publisher-server</code> } <em class=\"replaceable\"><code>connstr</code></em></p>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.5.7.5\">\n<h2>Description</h2>\n<p><span class=\"application\">pg_createsubscriber</span> creates a new logical replica from a physical standby server. All tables in the specified database are included in the <a class=\"link\" href=\"/docs/devel/logical-replication.html\" title=\"Chapter\u00a029.\u00a0Logical Replication\">logical replication</a> setup. A pair of publication and subscription objects are created for each database. It must be run at the target server.</p>\n<p>After 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 <span class=\"application\">pg_createsubscriber</span> is how the data synchronization is done. <span class=\"application\">pg_createsubscriber</span> does not copy the initial table data. It does only the synchronization phase, which ensures each table is brought up to a synchronized state.</p>\n<p><span class=\"application\">pg_createsubscriber</span> 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 <code class=\"command\">CREATE SUBSCRIPTION</code> <a class=\"link\" href=\"/docs/devel/sql-createsubscription.html#SQL-CREATESUBSCRIPTION-PARAMS-WITH-COPY-DATA\"><code class=\"literal\">copy_data</code></a> option.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.5.7.6\">\n<h2>Options</h2>\n<p><span class=\"application\">pg_createsubscriber</span> accepts the following command-line arguments:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-a</code><br></span><span class=\"term\"><code class=\"option\">--all</code></span></dt>\n<dd>\n<p>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 <code class=\"option\">--publisher-server</code> connection string, or if not specified, the <code class=\"literal\">postgres</code> database will be used, or if that does not exist, <code class=\"literal\">template1</code> 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 <code class=\"option\">--database</code>, <code class=\"option\">--publication</code>, <code class=\"option\">--replication-slot</code>, or <code class=\"option\">--subscription</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-d <em class=\"replaceable\"><code>dbname</code></em></code><br></span><span class=\"term\"><code class=\"option\">--database=<em class=\"replaceable\"><code>dbname</code></em></code></span></dt>\n<dd>\n<p>The name of the database in which to create a subscription. Multiple databases can be selected by writing multiple <code class=\"option\">-d</code> switches. This option cannot be used together with <code class=\"option\">-a</code>. If <code class=\"option\">-d</code> option is not provided, the database name will be obtained from <code class=\"option\">-P</code> option. If the database name is not specified in either the <code class=\"option\">-d</code> option, or the <code class=\"option\">-P</code> option, and <code class=\"option\">-a</code> option is not specified, an error will be reported.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-D <em class=\"replaceable\"><code>datadir</code></em></code><br></span><span class=\"term\"><code class=\"option\">--pgdata=<em class=\"replaceable\"><code>datadir</code></em></code></span></dt>\n<dd>\n<p>The target directory that contains a cluster directory from a physical replica.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-l <em class=\"replaceable\"><code>directory</code></em></code><br></span><span class=\"term\"><code class=\"option\">--logdir=<em class=\"replaceable\"><code>directory</code></em></code></span></dt>\n<dd>\n<p>Specify the name of the log directory. A new directory is created with this name if it does not exist. A subdirectory with a timestamp indicating the time at which <span class=\"application\">pg_createsubscriber</span> was run will be created. The following two log files will be created in the subdirectory.</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p><code class=\"filename\">pg_createsubscriber_server.log</code> which captures logs related to stopping and starting the standby server,</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"filename\">pg_createsubscriber_internal.log</code> which captures internal diagnostic output (validations, checks, etc.)</p>\n</li>\n</ul>\n</div>\n<p>By default, the <span class=\"systemitem\">umask</span> is set to 077 so that the log files are only readable by the user running the command. However, if the target data directory is configured to allow group-read access, <span class=\"application\">pg_createsubscriber</span> will adjust the log file permissions to match. This ensures that the log file security remains consistent with the database cluster itself.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--dry-run</code></span></dt>\n<dd>\n<p>Do everything except actually modifying the target directory.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-p <em class=\"replaceable\"><code>port</code></em></code><br></span><span class=\"term\"><code class=\"option\">--subscriber-port=<em class=\"replaceable\"><code>port</code></em></code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-P <em class=\"replaceable\"><code>connstr</code></em></code><br></span><span class=\"term\"><code class=\"option\">--publisher-server=<em class=\"replaceable\"><code>connstr</code></em></code></span></dt>\n<dd>\n<p>The connection string to the publisher. For details see <a class=\"xref\" href=\"/docs/devel/libpq-connect.html#LIBPQ-CONNSTRING\" title=\"32.1.1.\u00a0Connection Strings\">Section\u00a032.1.1</a>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-s <em class=\"replaceable\"><code>dir</code></em></code><br></span><span class=\"term\"><code class=\"option\">--socketdir=<em class=\"replaceable\"><code>dir</code></em></code></span></dt>\n<dd>\n<p>The directory to use for postmaster sockets on target server. The default is current directory.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-t <em class=\"replaceable\"><code>seconds</code></em></code><br></span><span class=\"term\"><code class=\"option\">--recovery-timeout=<em class=\"replaceable\"><code>seconds</code></em></code></span></dt>\n<dd>\n<p>The maximum number of seconds to wait for recovery to end. Setting to 0 disables. The default is 0.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-T</code><br></span><span class=\"term\"><code class=\"option\">--enable-two-phase</code></span></dt>\n<dd>\n<p>Enables <a class=\"link\" href=\"/docs/devel/sql-createsubscription.html#SQL-CREATESUBSCRIPTION-PARAMS-WITH-TWO-PHASE\"><code class=\"literal\">two_phase</code></a> commit for the subscription. When multiple databases are specified, this option applies uniformly to all subscriptions created on those databases. The default is <code class=\"literal\">false</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-U <em class=\"replaceable\"><code>username</code></em></code><br></span><span class=\"term\"><code class=\"option\">--subscriber-username=<em class=\"replaceable\"><code>username</code></em></code></span></dt>\n<dd>\n<p>The user name to connect as on target server. Defaults to the current operating system user name.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-v</code><br></span><span class=\"term\"><code class=\"option\">--verbose</code></span></dt>\n<dd>\n<p>Enables verbose mode. This will cause <span class=\"application\">pg_createsubscriber</span> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--clean=<em class=\"replaceable\"><code>objtype</code></em></code></span></dt>\n<dd>\n<p>Drop all objects of the specified type from specified databases on the target server.</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p><code class=\"literal\">publications</code>: The <code class=\"literal\">FOR ALL TABLES</code> 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.</p>\n</li>\n</ul>\n</div>\n<p>The objects selected to be dropped are individually logged, including during a <code class=\"option\">--dry-run</code>. There is no opportunity to affect or stop the dropping of the selected objects, so consider taking a backup of them using <span class=\"application\">pg_dump</span>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--config-file=<em class=\"replaceable\"><code>filename</code></em></code></span></dt>\n<dd>\n<p>Use the specified main server configuration file for the target data directory. <span class=\"application\">pg_createsubscriber</span> internally uses the <span class=\"application\">pg_ctl</span> command to start and stop the target server. It allows you to specify the actual <code class=\"filename\">postgresql.conf</code> configuration file if it is stored outside the data directory.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--publication=<em class=\"replaceable\"><code>name</code></em></code></span></dt>\n<dd>\n<p>The publication name to set up the logical replication. Multiple publications can be specified by writing multiple <code class=\"option\">--publication</code> 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 <code class=\"option\">--all</code>.</p>\n<p>If a specified publication already exists on the publisher, it is reused. It is useful to partially replicate the database if the specified publication includes a list of tables. If the publication does not exist, it is automatically created with <code class=\"literal\">FOR ALL TABLES</code>. Use <code class=\"option\">--dry-run</code> option to preview which publications will be reused and which will be created.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--replication-slot=<em class=\"replaceable\"><code>name</code></em></code></span></dt>\n<dd>\n<p>The replication slot name to set up the logical replication. Multiple replication slots can be specified by writing multiple <code class=\"option\">--replication-slot</code> 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 <code class=\"option\">--all</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--subscription=<em class=\"replaceable\"><code>name</code></em></code></span></dt>\n<dd>\n<p>The subscription name to set up the logical replication. Multiple subscriptions can be specified by writing multiple <code class=\"option\">--subscription</code> 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 <code class=\"option\">--all</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-V</code><br></span><span class=\"term\"><code class=\"option\">--version</code></span></dt>\n<dd>\n<p>Print the <span class=\"application\">pg_createsubscriber</span> version and exit.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-?</code><br></span><span class=\"term\"><code class=\"option\">--help</code></span></dt>\n<dd>\n<p>Show help about <span class=\"application\">pg_createsubscriber</span> command line arguments, and exit.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.5.7.7\">\n<h2>Notes</h2>\n<div class=\"refsect2\" id=\"id-1.9.5.7.7.2\">\n<h3>Prerequisites</h3>\n<p>There are some prerequisites for <span class=\"application\">pg_createsubscriber</span> 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 <span class=\"application\">pg_createsubscriber</span>. 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 <a class=\"link\" href=\"/docs/devel/sql-createsubscription.html\" title=\"CREATE SUBSCRIPTION\">subscriptions</a> and using <a class=\"link\" href=\"/docs/devel/functions-admin.html#PG-REPLICATION-ORIGIN-ADVANCE\"><code class=\"function\">pg_replication_origin_advance()</code></a>.</p>\n<p>The target server must be used as a physical standby. The target server must have <a class=\"xref\" href=\"/docs/devel/runtime-config-replication.html#GUC-MAX-ACTIVE-REPLICATION-ORIGINS\">max_active_replication_origins</a> and <a class=\"xref\" href=\"/docs/devel/runtime-config-replication.html#GUC-MAX-LOGICAL-REPLICATION-WORKERS\">max_logical_replication_workers</a> configured to a value greater than or equal to the number of specified databases. The target server must have <a class=\"xref\" href=\"/docs/devel/runtime-config-resource.html#GUC-MAX-WORKER-PROCESSES\">max_worker_processes</a> 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 <code class=\"option\">--enable-two-phase</code> switch then you will also need to set the <a class=\"xref\" href=\"/docs/devel/runtime-config-resource.html#GUC-MAX-PREPARED-TRANSACTIONS\">max_prepared_transactions</a> appropriately.</p>\n<p>The source server must accept connections from the target server. The source server must not be in recovery. The source server must have <a class=\"xref\" href=\"/docs/devel/runtime-config-wal.html#GUC-WAL-LEVEL\">wal_level</a> as <code class=\"literal\">replica</code> or <code class=\"literal\">logical</code>. The source server must have <a class=\"xref\" href=\"/docs/devel/runtime-config-replication.html#GUC-MAX-REPLICATION-SLOTS\">max_replication_slots</a> configured to a value greater than or equal to the number of specified databases plus existing replication slots. The source server must have <a class=\"xref\" href=\"/docs/devel/runtime-config-replication.html#GUC-MAX-WAL-SENDERS\">max_wal_senders</a> configured to a value greater than or equal to the number of specified databases and existing WAL sender processes.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.5.7.7.3\">\n<h3>Warnings</h3>\n<p>If <span class=\"application\">pg_createsubscriber</span> 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.</p>\n<p><span class=\"application\">pg_createsubscriber</span> usually starts the target server with different connection settings during transformation. Hence, connections to the target server should fail.</p>\n<p>Since DDL commands are not replicated by logical replication, avoid executing DDL commands that change the database schema while running <span class=\"application\">pg_createsubscriber</span>. If the target server has already been converted to logical replica, the DDL commands might not be replicated, which might cause an error.</p>\n<p>If <span class=\"application\">pg_createsubscriber</span> 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.</p>\n<p>If the replication is using <a class=\"xref\" href=\"/docs/devel/runtime-config-replication.html#GUC-PRIMARY-SLOT-NAME\">primary_slot_name</a>, it will be removed from the source server after the logical replication setup.</p>\n<p>If the target server is a synchronous replica, transaction commits on the primary might wait for replication while running <span class=\"application\">pg_createsubscriber</span>.</p>\n<p>Unless the <code class=\"option\">--enable-two-phase</code> switch is specified, <span class=\"application\">pg_createsubscriber</span> sets up logical replication with two-phase commit disabled. This means that any prepared transactions will be replicated at the time of <code class=\"command\">COMMIT PREPARED</code>, without advance preparation. Once setup is complete, you can manually drop and re-create the subscription(s) with the <a class=\"link\" href=\"/docs/devel/sql-createsubscription.html#SQL-CREATESUBSCRIPTION-PARAMS-WITH-TWO-PHASE\"><code class=\"literal\">two_phase</code></a> option enabled.</p>\n<p><span class=\"application\">pg_createsubscriber</span> changes the system identifier using <span class=\"application\">pg_resetwal</span>. 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.</p>\n<p>Replication failures can occur if required WAL files are missing. To prevent this, the source server must set <a class=\"xref\" href=\"/docs/devel/runtime-config-replication.html#GUC-MAX-SLOT-WAL-KEEP-SIZE\">max_slot_wal_keep_size</a> to <code class=\"literal\">-1</code> to ensure that required WAL files are not prematurely removed.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.5.7.7.4\">\n<h3>How It Works</h3>\n<p>The basic idea is to have a replication start point from the source server and set up a logical replication to start from this point:</p>\n<div class=\"procedure\">\n<ol class=\"procedure\">\n<li class=\"step\">\n<p>Start the target server with the specified command-line options. If the target server is already running, <span class=\"application\">pg_createsubscriber</span> will terminate with an error.</p>\n</li>\n<li class=\"step\">\n<p>Check 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, <span class=\"application\">pg_createsubscriber</span> will terminate with an error.</p>\n</li>\n<li class=\"step\">\n<p>Create a publication and replication slot for each specified database on the source server. Each publication is created using <a class=\"link\" href=\"/docs/devel/sql-createpublication.html#SQL-CREATEPUBLICATION-PARAMS-FOR-ALL-TABLES\"><code class=\"literal\">FOR ALL TABLES</code></a>. If the <code class=\"option\">--publication</code> option is not specified, the publication has the following name pattern: <span class=\"quote\">\u201c<span class=\"quote\"><code class=\"literal\">pg_createsubscriber_%u_%x</code></span>\u201d</span> (parameter: database <em class=\"parameter\"><code>oid</code></em>, random <em class=\"parameter\"><code>int</code></em>). If the <code class=\"option\">--replication-slot</code> option is not specified, the replication slot has the following name pattern: <span class=\"quote\">\u201c<span class=\"quote\"><code class=\"literal\">pg_createsubscriber_%u_%x</code></span>\u201d</span> (parameters: database <em class=\"parameter\"><code>oid</code></em>, random <em class=\"parameter\"><code>int</code></em>). 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 <a class=\"xref\" href=\"/docs/devel/runtime-config-wal.html#GUC-RECOVERY-TARGET-LSN\">recovery_target_lsn</a> parameter and by the subscriptions as a replication start point. It guarantees that no transaction will be lost.</p>\n</li>\n<li class=\"step\">\n<p>Write recovery parameters into the separate configuration file <code class=\"filename\">pg_createsubscriber.conf</code> that is included from <code class=\"filename\">postgresql.auto.conf</code> using <code class=\"literal\">include_if_exists</code> in the target data directory, then restart the target server. It specifies an LSN (<a class=\"xref\" href=\"/docs/devel/runtime-config-wal.html#GUC-RECOVERY-TARGET-LSN\">recovery_target_lsn</a>) of the write-ahead log location up to which recovery will proceed. It also specifies <code class=\"literal\">promote</code> as the action that the server should take once the recovery target is reached. Additional <a class=\"link\" href=\"/docs/devel/runtime-config-wal.html#RUNTIME-CONFIG-WAL-RECOVERY-TARGET\" title=\"19.5.6.\u00a0Recovery Target\">recovery parameters</a> 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 <code class=\"option\">--recovery-timeout</code> option is set, <span class=\"application\">pg_createsubscriber</span> terminates if recovery does not end until the given number of seconds. Upon completion, the included configuration file is renamed to <code class=\"filename\">pg_createsubscriber.conf.disabled</code> so as it is no longer loaded on subsequent restarts.</p>\n</li>\n<li class=\"step\">\n<p>Create a subscription for each specified database on the target server. If the <code class=\"option\">--subscription</code> option is not specified, the subscription has the following name pattern: <span class=\"quote\">\u201c<span class=\"quote\"><code class=\"literal\">pg_createsubscriber_%u_%x</code></span>\u201d</span> (parameters: database <em class=\"parameter\"><code>oid</code></em>, random <em class=\"parameter\"><code>int</code></em>). 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.</p>\n</li>\n<li class=\"step\">\n<p>Drop publications on the target server that were replicated because they were created before the replication start location. It has no use on the subscriber.</p>\n</li>\n<li class=\"step\">\n<p>Set 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 <a class=\"link\" href=\"/docs/devel/functions-admin.html#PG-REPLICATION-ORIGIN-ADVANCE\"><code class=\"function\">pg_replication_origin_advance()</code></a> to set up the initial replication location.</p>\n</li>\n<li class=\"step\">\n<p>Enable the subscription for each specified database on the target server. The subscription starts applying transactions from the replication start point.</p>\n</li>\n<li class=\"step\">\n<p>If the standby server was using <a class=\"xref\" href=\"/docs/devel/runtime-config-replication.html#GUC-PRIMARY-SLOT-NAME\">primary_slot_name</a>, it has no use from now on so drop it.</p>\n</li>\n<li class=\"step\">\n<p>If the standby server contains <a class=\"link\" href=\"/docs/devel/logicaldecoding-explanation.html#LOGICALDECODING-REPLICATION-SLOTS-SYNCHRONIZATION\" title=\"47.2.3.\u00a0Replication Slot Synchronization\">failover replication slots</a>, they cannot be synchronized anymore, so drop them.</p>\n</li>\n<li class=\"step\">\n<p>Update the system identifier on the target server. The <a class=\"xref\" href=\"/docs/devel/app-pgresetwal.html\" title=\"pg_resetwal\"><span class=\"refentrytitle\"><span class=\"application\">pg_resetwal</span></span></a> is run to modify the system identifier. The target server is stopped as a <code class=\"command\">pg_resetwal</code> requirement.</p>\n</li>\n</ol>\n</div>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.5.7.8\">\n<h2>Examples</h2>\n<p>To create a logical replica for databases <code class=\"literal\">hr</code> and <code class=\"literal\">finance</code> from a physical replica at <code class=\"literal\">foo</code>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_createsubscriber -D /usr/local/pgsql/data -P \"host=foo\" -d hr -d finance</code></strong>\n</pre>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.5.7.9\">\n<h2>See Also</h2><span class=\"simplelist\"><a class=\"xref\" href=\"/docs/devel/app-pgbasebackup.html\" title=\"pg_basebackup\"><span class=\"refentrytitle\"><span class=\"application\">pg_basebackup</span></span></a></span>\n</div>\n</div></div>", "manual_path": "app-pgcreatesubscriber.html", "comparison_data": {"options": [{"names": ["-a", "--all"], "signature": "-a --all", "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": ["-d dbname", "--database= dbname"], "signature": "-d dbname --database= dbname", "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 datadir", "--pgdata= datadir"], "signature": "-D datadir --pgdata= datadir", "description": "The target directory that contains a cluster directory from a physical replica."}, {"names": ["-l directory", "--logdir= directory"], "signature": "-l directory --logdir= directory", "description": "Specify the name of the log directory. A new directory is created with this name if it does not exist. A subdirectory with a timestamp indicating the time at which pg_createsubscriber was run will be created. The following two log files will be created in the subdirectory. pg_createsubscriber_server.log which captures logs related to stopping and starting the standby server, pg_createsubscriber_internal.log which captures internal diagnostic output (validations, checks, etc.) By default, the umask is set to 077 so that the log files are only readable by the user running the command. However, if the target data directory is configured to allow group-read access, pg_createsubscriber will adjust the log file permissions to match. This ensures that the log file security remains consistent with the database cluster itself."}, {"names": ["-n", "--dry-run"], "signature": "-n --dry-run", "description": "Do everything except actually modifying the target directory."}, {"names": ["-p port", "--subscriber-port= port"], "signature": "-p port --subscriber-port= port", "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 connstr", "--publisher-server= connstr"], "signature": "-P connstr --publisher-server= connstr", "description": "The connection string to the publisher. For details see Section 32.1.1 ."}, {"names": ["-s dir", "--socketdir= dir"], "signature": "-s dir --socketdir= dir", "description": "The directory to use for postmaster sockets on target server. The default is current directory."}, {"names": ["-t seconds", "--recovery-timeout= seconds"], "signature": "-t seconds --recovery-timeout= seconds", "description": "The maximum number of seconds to wait for recovery to end. Setting to 0 disables. The default is 0."}, {"names": ["-T", "--enable-two-phase"], "signature": "-T --enable-two-phase", "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": ["-U username", "--subscriber-username= username"], "signature": "-U username --subscriber-username= username", "description": "The user name to connect as on target server. Defaults to the current operating system user name."}, {"names": ["-v", "--verbose"], "signature": "-v --verbose", "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": ["--clean= objtype"], "signature": "--clean= objtype", "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": ["--config-file= filename"], "signature": "--config-file= filename", "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": ["--publication= name"], "signature": "--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 . If a specified publication already exists on the publisher, it is reused. It is useful to partially replicate the database if the specified publication includes a list of tables. If the publication does not exist, it is automatically created with FOR ALL TABLES . Use --dry-run option to preview which publications will be reused and which will be created."}, {"names": ["--replication-slot= name"], "signature": "--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": ["--subscription= name"], "signature": "--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": ["-V", "--version"], "signature": "-V --version", "description": "Print the pg_createsubscriber version and exit."}, {"names": ["-?", "--help"], "signature": "-? --help", "description": "Show help about pg_createsubscriber command line arguments, and exit."}], "synopsis": ["pg_createsubscriber [ option ...] { -d | --database } dbname { -D | --pgdata } datadir { -P | --publisher-server } connstr"], "environment": []}, "comparison_hash": "b4807e2c2ddbf51e9e6cdd5c6c5a1cd58c95530174f72f8e053b38ce95c721d8"}}}, "snapshot": {"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"}], "tables": [{"key": "options", "rows": [{"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": {"url": "/docs/18/app-pgcreatesubscriber.html", "text": "-a --all"}}, {"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": {"url": "/docs/18/app-pgcreatesubscriber.html", "text": "-d dbname --database= dbname"}}, {"summary": "The target directory that contains a cluster directory from a physical replica.", "signature": {"url": "/docs/18/app-pgcreatesubscriber.html", "text": "-D directory --pgdata= directory"}}, {"summary": "Do everything except actually modifying the target directory.", "signature": {"url": "/docs/18/app-pgcreatesubscriber.html", "text": "-n --dry-run"}}, {"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": {"url": "/docs/18/app-pgcreatesubscriber.html", "text": "-p port --subscriber-port= port"}}, {"summary": "The connection string to the publisher. For details see Section 32.1.1 .", "signature": {"url": "/docs/18/app-pgcreatesubscriber.html", "text": "-P connstr --publisher-server= connstr"}}, {"summary": "The directory to use for postmaster sockets on target server. The default is current directory.", "signature": {"url": "/docs/18/app-pgcreatesubscriber.html", "text": "-s dir --socketdir= dir"}}, {"summary": "The maximum number of seconds to wait for recovery to end. Setting to 0 disables. The default is 0.", "signature": {"url": "/docs/18/app-pgcreatesubscriber.html", "text": "-t seconds --recovery-timeout= seconds"}}, {"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": {"url": "/docs/18/app-pgcreatesubscriber.html", "text": "-T --enable-two-phase"}}, {"summary": "The user name to connect as on target server. Defaults to the current operating system user name.", "signature": {"url": "/docs/18/app-pgcreatesubscriber.html", "text": "-U username --subscriber-username= username"}}, {"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": {"url": "/docs/18/app-pgcreatesubscriber.html", "text": "-v --verbose"}}, {"summary": "Drop all objects of the specified type from specified databases on the target server.", "signature": {"url": "/docs/18/app-pgcreatesubscriber.html", "text": "--clean= objtype"}}, {"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": {"url": "/docs/18/app-pgcreatesubscriber.html", "text": "--config-file= filename"}}, {"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": {"url": "/docs/18/app-pgcreatesubscriber.html", "text": "--publication= name"}}, {"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": {"url": "/docs/18/app-pgcreatesubscriber.html", "text": "--replication-slot= name"}}, {"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": {"url": "/docs/18/app-pgcreatesubscriber.html", "text": "--subscription= name"}}, {"summary": "Print the pg_createsubscriber version and exit.", "signature": {"url": "/docs/18/app-pgcreatesubscriber.html", "text": "-V --version"}}, {"summary": "Show help about pg_createsubscriber command line arguments, and exit.", "signature": {"url": "/docs/18/app-pgcreatesubscriber.html", "text": "-? --help"}}], "title": "Documented options", "columns": [{"key": "signature", "label": "Option and arguments"}, {"key": "summary", "label": "Description"}]}], "options": [{"names": ["-a", "--all"], "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": "-a --all", "source_url": "/docs/18/app-pgcreatesubscriber.html", "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": ["-d dbname", "--database= dbname"], "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": "-d dbname --database= dbname", "source_url": "/docs/18/app-pgcreatesubscriber.html", "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 directory", "--pgdata= directory"], "summary": "The target directory that contains a cluster directory from a physical replica.", "signature": "-D directory --pgdata= directory", "source_url": "/docs/18/app-pgcreatesubscriber.html", "description": "The target directory that contains a cluster directory from a physical replica."}, {"names": ["-n", "--dry-run"], "summary": "Do everything except actually modifying the target directory.", "signature": "-n --dry-run", "source_url": "/docs/18/app-pgcreatesubscriber.html", "description": "Do everything except actually modifying the target directory."}, {"names": ["-p port", "--subscriber-port= port"], "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": "-p port --subscriber-port= port", "source_url": "/docs/18/app-pgcreatesubscriber.html", "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 connstr", "--publisher-server= connstr"], "summary": "The connection string to the publisher. For details see Section 32.1.1 .", "signature": "-P connstr --publisher-server= connstr", "source_url": "/docs/18/app-pgcreatesubscriber.html", "description": "The connection string to the publisher. For details see Section 32.1.1 ."}, {"names": ["-s dir", "--socketdir= dir"], "summary": "The directory to use for postmaster sockets on target server. The default is current directory.", "signature": "-s dir --socketdir= dir", "source_url": "/docs/18/app-pgcreatesubscriber.html", "description": "The directory to use for postmaster sockets on target server. The default is current directory."}, {"names": ["-t seconds", "--recovery-timeout= seconds"], "summary": "The maximum number of seconds to wait for recovery to end. Setting to 0 disables. The default is 0.", "signature": "-t seconds --recovery-timeout= seconds", "source_url": "/docs/18/app-pgcreatesubscriber.html", "description": "The maximum number of seconds to wait for recovery to end. Setting to 0 disables. The default is 0."}, {"names": ["-T", "--enable-two-phase"], "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": "-T --enable-two-phase", "source_url": "/docs/18/app-pgcreatesubscriber.html", "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": ["-U username", "--subscriber-username= username"], "summary": "The user name to connect as on target server. Defaults to the current operating system user name.", "signature": "-U username --subscriber-username= username", "source_url": "/docs/18/app-pgcreatesubscriber.html", "description": "The user name to connect as on target server. Defaults to the current operating system user name."}, {"names": ["-v", "--verbose"], "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": "-v --verbose", "source_url": "/docs/18/app-pgcreatesubscriber.html", "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": ["--clean= objtype"], "summary": "Drop all objects of the specified type from specified databases on the target server.", "signature": "--clean= objtype", "source_url": "/docs/18/app-pgcreatesubscriber.html", "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": ["--config-file= filename"], "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": "--config-file= filename", "source_url": "/docs/18/app-pgcreatesubscriber.html", "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": ["--publication= name"], "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": "--publication= name", "source_url": "/docs/18/app-pgcreatesubscriber.html", "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": ["--replication-slot= name"], "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": "--replication-slot= name", "source_url": "/docs/18/app-pgcreatesubscriber.html", "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": ["--subscription= name"], "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": "--subscription= name", "source_url": "/docs/18/app-pgcreatesubscriber.html", "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": ["-V", "--version"], "summary": "Print the pg_createsubscriber version and exit.", "signature": "-V --version", "source_url": "/docs/18/app-pgcreatesubscriber.html", "description": "Print the pg_createsubscriber version and exit."}, {"names": ["-?", "--help"], "summary": "Show help about pg_createsubscriber command line arguments, and exit.", "signature": "-? --help", "source_url": "/docs/18/app-pgcreatesubscriber.html", "description": "Show help about pg_createsubscriber command line arguments, and exit."}], "related": [], "release": {"ref": "https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2", "label": "18.6", "major": "18", "channel": "stable", "manifest": {"pdf": {"A4": {"url": "/files/documentation/pdf/18/postgresql-18-A4.pdf", "bytes": 15865106, "pages": 3154, "sha256": "19512c405da53f9f7fcf0abba359223aa65f021be025bf3411381918f92e3190", "built_at": "2026-09-26"}, "US": {"url": "/files/documentation/pdf/18/postgresql-18-US.pdf", "bytes": 15748059, "pages": 3328, "sha256": "facbe6c229e598b872d3d98bef53308f46e06746006fa4590de9a7de9dd46319", "built_at": "2026-09-26"}}, "tree": "18", "index": "index.html", "major": "18", "pages": 1148, "release": "18.6", "source_url": "https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2", "svg_assets": 3, "source_mode": "en SGML built with pinned official archive", "source_sha256": "555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f"}, "revision": "ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8", "evidence_kind": "English manual and source declarations", "source_sha256": "555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f"}, "sources": [{"url": "/docs/18/app-pgcreatesubscriber.html", "file": "app-pgcreatesubscriber.html", "label": "18.6 English manual \u00b7 app-pgcreatesubscriber.html", "anchor": "", "sha256": "fb0e5cd7f37044410e06deb436d7b70a1bceffbd849ce10f468351d9cf11d385"}, {"url": "/docs/18/reference-server.html", "file": "reference-server.html", "label": "Server applications inventory", "anchor": "", "sha256": "e9f8bbcc8e3641fadd1d20991e8aad6b532155b786ba5a1b7b364ec4f1a5bef3"}], "sections": [], "synopsis": ["pg_createsubscriber [ option ...] { -d | --database } dbname { -D | --pgdata } datadir { -P | --publisher-server } connstr"], "signature": "pg_createsubscriber [ option ...] { -d | --database } dbname { -D | --pgdata } datadir { -P | --publisher-server } connstr", "description": ["pg_createsubscriber \u2014 convert a physical replica into a new logical replica"], "environment": [], "manual_html": "<div><div class=\"refentry\" id=\"APP-PGCREATESUBSCRIBER\">\n<div class=\"titlepage\"></div>\n<div class=\"refnamediv\">\n<h2><span class=\"refentrytitle\"><span class=\"application\">pg_createsubscriber</span></span></h2>\n<p>pg_createsubscriber \u2014 convert a physical replica into a new logical replica</p>\n</div>\n<div class=\"refsynopsisdiv\">\n<h2>Synopsis</h2>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.5.7.4.1\"><code class=\"command\">pg_createsubscriber</code> [<em class=\"replaceable\"><code>option</code></em>...] { <code class=\"option\">-d</code> | <code class=\"option\">--database</code> }<em class=\"replaceable\"><code>dbname</code></em> { <code class=\"option\">-D</code> | <code class=\"option\">--pgdata</code> }<em class=\"replaceable\"><code>datadir</code></em> { <code class=\"option\">-P</code> | <code class=\"option\">--publisher-server</code> }<em class=\"replaceable\"><code>connstr</code></em></p>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.5.7.5\">\n<h2>Description</h2>\n<p><span class=\"application\">pg_createsubscriber</span> creates a new logical replica from a physical standby server. All tables in the specified database are included in the <a class=\"link\" href=\"/docs/18/logical-replication.html\" title=\"Chapter\u00a029.\u00a0Logical Replication\">logical replication</a> setup. A pair of publication and subscription objects are created for each database. It must be run at the target server.</p>\n<p>After 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 <span class=\"application\">pg_createsubscriber</span> is how the data synchronization is done. <span class=\"application\">pg_createsubscriber</span> does not copy the initial table data. It does only the synchronization phase, which ensures each table is brought up to a synchronized state.</p>\n<p><span class=\"application\">pg_createsubscriber</span> 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 <code class=\"command\">CREATE SUBSCRIPTION</code> <a class=\"link\" href=\"/docs/18/sql-createsubscription.html#SQL-CREATESUBSCRIPTION-PARAMS-WITH-COPY-DATA\"><code class=\"literal\">copy_data</code></a> option.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.5.7.6\">\n<h2>Options</h2>\n<p><span class=\"application\">pg_createsubscriber</span> accepts the following command-line arguments:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-a</code><br></span><span class=\"term\"><code class=\"option\">--all</code></span></dt>\n<dd>\n<p>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 <code class=\"option\">--publisher-server</code> connection string, or if not specified, the <code class=\"literal\">postgres</code> database will be used, or if that does not exist, <code class=\"literal\">template1</code> 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 <code class=\"option\">--database</code>, <code class=\"option\">--publication</code>, <code class=\"option\">--replication-slot</code>, or <code class=\"option\">--subscription</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-d <em class=\"replaceable\"><code>dbname</code></em></code><br></span><span class=\"term\"><code class=\"option\">--database=<em class=\"replaceable\"><code>dbname</code></em></code></span></dt>\n<dd>\n<p>The name of the database in which to create a subscription. Multiple databases can be selected by writing multiple <code class=\"option\">-d</code> switches. This option cannot be used together with <code class=\"option\">-a</code>. If <code class=\"option\">-d</code> option is not provided, the database name will be obtained from <code class=\"option\">-P</code> option. If the database name is not specified in either the <code class=\"option\">-d</code> option, or the <code class=\"option\">-P</code> option, and <code class=\"option\">-a</code> option is not specified, an error will be reported.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-D <em class=\"replaceable\"><code>directory</code></em></code><br></span><span class=\"term\"><code class=\"option\">--pgdata=<em class=\"replaceable\"><code>directory</code></em></code></span></dt>\n<dd>\n<p>The target directory that contains a cluster directory from a physical replica.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--dry-run</code></span></dt>\n<dd>\n<p>Do everything except actually modifying the target directory.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-p <em class=\"replaceable\"><code>port</code></em></code><br></span><span class=\"term\"><code class=\"option\">--subscriber-port=<em class=\"replaceable\"><code>port</code></em></code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-P <em class=\"replaceable\"><code>connstr</code></em></code><br></span><span class=\"term\"><code class=\"option\">--publisher-server=<em class=\"replaceable\"><code>connstr</code></em></code></span></dt>\n<dd>\n<p>The connection string to the publisher. For details see <a class=\"xref\" href=\"/docs/18/libpq-connect.html#LIBPQ-CONNSTRING\" title=\"32.1.1.\u00a0Connection Strings\">Section\u00a032.1.1</a>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-s <em class=\"replaceable\"><code>dir</code></em></code><br></span><span class=\"term\"><code class=\"option\">--socketdir=<em class=\"replaceable\"><code>dir</code></em></code></span></dt>\n<dd>\n<p>The directory to use for postmaster sockets on target server. The default is current directory.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-t <em class=\"replaceable\"><code>seconds</code></em></code><br></span><span class=\"term\"><code class=\"option\">--recovery-timeout=<em class=\"replaceable\"><code>seconds</code></em></code></span></dt>\n<dd>\n<p>The maximum number of seconds to wait for recovery to end. Setting to 0 disables. The default is 0.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-T</code><br></span><span class=\"term\"><code class=\"option\">--enable-two-phase</code></span></dt>\n<dd>\n<p>Enables <a class=\"link\" href=\"/docs/18/sql-createsubscription.html#SQL-CREATESUBSCRIPTION-PARAMS-WITH-TWO-PHASE\"><code class=\"literal\">two_phase</code></a> commit for the subscription. When multiple databases are specified, this option applies uniformly to all subscriptions created on those databases. The default is <code class=\"literal\">false</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-U <em class=\"replaceable\"><code>username</code></em></code><br></span><span class=\"term\"><code class=\"option\">--subscriber-username=<em class=\"replaceable\"><code>username</code></em></code></span></dt>\n<dd>\n<p>The user name to connect as on target server. Defaults to the current operating system user name.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-v</code><br></span><span class=\"term\"><code class=\"option\">--verbose</code></span></dt>\n<dd>\n<p>Enables verbose mode. This will cause <span class=\"application\">pg_createsubscriber</span> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--clean=<em class=\"replaceable\"><code>objtype</code></em></code></span></dt>\n<dd>\n<p>Drop all objects of the specified type from specified databases on the target server.</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p><code class=\"literal\">publications</code>: The <code class=\"literal\">FOR ALL TABLES</code> 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.</p>\n</li>\n</ul>\n</div>\n<p>The objects selected to be dropped are individually logged, including during a <code class=\"option\">--dry-run</code>. There is no opportunity to affect or stop the dropping of the selected objects, so consider taking a backup of them using <span class=\"application\">pg_dump</span>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--config-file=<em class=\"replaceable\"><code>filename</code></em></code></span></dt>\n<dd>\n<p>Use the specified main server configuration file for the target data directory. <span class=\"application\">pg_createsubscriber</span> internally uses the <span class=\"application\">pg_ctl</span> command to start and stop the target server. It allows you to specify the actual <code class=\"filename\">postgresql.conf</code> configuration file if it is stored outside the data directory.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--publication=<em class=\"replaceable\"><code>name</code></em></code></span></dt>\n<dd>\n<p>The publication name to set up the logical replication. Multiple publications can be specified by writing multiple <code class=\"option\">--publication</code> 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 <code class=\"option\">--all</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--replication-slot=<em class=\"replaceable\"><code>name</code></em></code></span></dt>\n<dd>\n<p>The replication slot name to set up the logical replication. Multiple replication slots can be specified by writing multiple <code class=\"option\">--replication-slot</code> 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 <code class=\"option\">--all</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--subscription=<em class=\"replaceable\"><code>name</code></em></code></span></dt>\n<dd>\n<p>The subscription name to set up the logical replication. Multiple subscriptions can be specified by writing multiple <code class=\"option\">--subscription</code> 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 <code class=\"option\">--all</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-V</code><br></span><span class=\"term\"><code class=\"option\">--version</code></span></dt>\n<dd>\n<p>Print the <span class=\"application\">pg_createsubscriber</span> version and exit.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-?</code><br></span><span class=\"term\"><code class=\"option\">--help</code></span></dt>\n<dd>\n<p>Show help about <span class=\"application\">pg_createsubscriber</span> command line arguments, and exit.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.5.7.7\">\n<h2>Notes</h2>\n<div class=\"refsect2\" id=\"id-1.9.5.7.7.2\">\n<h3>Prerequisites</h3>\n<p>There are some prerequisites for <span class=\"application\">pg_createsubscriber</span> 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 <span class=\"application\">pg_createsubscriber</span>. 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 <a class=\"link\" href=\"/docs/18/sql-createsubscription.html\" title=\"CREATE SUBSCRIPTION\">subscriptions</a> and using <a class=\"link\" href=\"/docs/18/functions-admin.html#PG-REPLICATION-ORIGIN-ADVANCE\"><code class=\"function\">pg_replication_origin_advance()</code></a>.</p>\n<p>The target server must be used as a physical standby. The target server must have <a class=\"xref\" href=\"/docs/18/runtime-config-replication.html#GUC-MAX-ACTIVE-REPLICATION-ORIGINS\">max_active_replication_origins</a> and <a class=\"xref\" href=\"/docs/18/runtime-config-replication.html#GUC-MAX-LOGICAL-REPLICATION-WORKERS\">max_logical_replication_workers</a> configured to a value greater than or equal to the number of specified databases. The target server must have <a class=\"xref\" href=\"/docs/18/runtime-config-resource.html#GUC-MAX-WORKER-PROCESSES\">max_worker_processes</a> 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 <code class=\"option\">--enable-two-phase</code> switch then you will also need to set the <a class=\"xref\" href=\"/docs/18/runtime-config-resource.html#GUC-MAX-PREPARED-TRANSACTIONS\">max_prepared_transactions</a> appropriately.</p>\n<p>The source server must accept connections from the target server. The source server must not be in recovery. The source server must have <a class=\"xref\" href=\"/docs/18/runtime-config-wal.html#GUC-WAL-LEVEL\">wal_level</a> as <code class=\"literal\">logical</code>. The source server must have <a class=\"xref\" href=\"/docs/18/runtime-config-replication.html#GUC-MAX-REPLICATION-SLOTS\">max_replication_slots</a> configured to a value greater than or equal to the number of specified databases plus existing replication slots. The source server must have <a class=\"xref\" href=\"/docs/18/runtime-config-replication.html#GUC-MAX-WAL-SENDERS\">max_wal_senders</a> configured to a value greater than or equal to the number of specified databases and existing WAL sender processes.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.5.7.7.3\">\n<h3>Warnings</h3>\n<p>If <span class=\"application\">pg_createsubscriber</span> 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.</p>\n<p><span class=\"application\">pg_createsubscriber</span> usually starts the target server with different connection settings during transformation. Hence, connections to the target server should fail.</p>\n<p>Since DDL commands are not replicated by logical replication, avoid executing DDL commands that change the database schema while running <span class=\"application\">pg_createsubscriber</span>. If the target server has already been converted to logical replica, the DDL commands might not be replicated, which might cause an error.</p>\n<p>If <span class=\"application\">pg_createsubscriber</span> 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.</p>\n<p>If the replication is using <a class=\"xref\" href=\"/docs/18/runtime-config-replication.html#GUC-PRIMARY-SLOT-NAME\">primary_slot_name</a>, it will be removed from the source server after the logical replication setup.</p>\n<p>If the target server is a synchronous replica, transaction commits on the primary might wait for replication while running <span class=\"application\">pg_createsubscriber</span>.</p>\n<p>Unless the <code class=\"option\">--enable-two-phase</code> switch is specified, <span class=\"application\">pg_createsubscriber</span> sets up logical replication with two-phase commit disabled. This means that any prepared transactions will be replicated at the time of <code class=\"command\">COMMIT PREPARED</code>, without advance preparation. Once setup is complete, you can manually drop and re-create the subscription(s) with the <a class=\"link\" href=\"/docs/18/sql-createsubscription.html#SQL-CREATESUBSCRIPTION-PARAMS-WITH-TWO-PHASE\"><code class=\"literal\">two_phase</code></a> option enabled.</p>\n<p><span class=\"application\">pg_createsubscriber</span> changes the system identifier using <span class=\"application\">pg_resetwal</span>. 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.</p>\n<p>Replication failures can occur if required WAL files are missing. To prevent this, the source server must set <a class=\"xref\" href=\"/docs/18/runtime-config-replication.html#GUC-MAX-SLOT-WAL-KEEP-SIZE\">max_slot_wal_keep_size</a> to <code class=\"literal\">-1</code> to ensure that required WAL files are not prematurely removed.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.5.7.7.4\">\n<h3>How It Works</h3>\n<p>The basic idea is to have a replication start point from the source server and set up a logical replication to start from this point:</p>\n<div class=\"procedure\">\n<ol class=\"procedure\">\n<li class=\"step\">\n<p>Start the target server with the specified command-line options. If the target server is already running, <span class=\"application\">pg_createsubscriber</span> will terminate with an error.</p>\n</li>\n<li class=\"step\">\n<p>Check 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, <span class=\"application\">pg_createsubscriber</span> will terminate with an error.</p>\n</li>\n<li class=\"step\">\n<p>Create a publication and replication slot for each specified database on the source server. Each publication is created using <a class=\"link\" href=\"/docs/18/sql-createpublication.html#SQL-CREATEPUBLICATION-PARAMS-FOR-ALL-TABLES\"><code class=\"literal\">FOR ALL TABLES</code></a>. If the <code class=\"option\">--publication</code> option is not specified, the publication has the following name pattern: <span class=\"quote\">\u201c<span class=\"quote\"><code class=\"literal\">pg_createsubscriber_%u_%x</code></span>\u201d</span> (parameter: database <em class=\"parameter\"><code>oid</code></em>, random <em class=\"parameter\"><code>int</code></em>). If the <code class=\"option\">--replication-slot</code> option is not specified, the replication slot has the following name pattern: <span class=\"quote\">\u201c<span class=\"quote\"><code class=\"literal\">pg_createsubscriber_%u_%x</code></span>\u201d</span> (parameters: database <em class=\"parameter\"><code>oid</code></em>, random <em class=\"parameter\"><code>int</code></em>). 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 <a class=\"xref\" href=\"/docs/18/runtime-config-wal.html#GUC-RECOVERY-TARGET-LSN\">recovery_target_lsn</a> parameter and by the subscriptions as a replication start point. It guarantees that no transaction will be lost.</p>\n</li>\n<li class=\"step\">\n<p>Write recovery parameters into the target data directory and restart the target server. It specifies an LSN (<a class=\"xref\" href=\"/docs/18/runtime-config-wal.html#GUC-RECOVERY-TARGET-LSN\">recovery_target_lsn</a>) of the write-ahead log location up to which recovery will proceed. It also specifies <code class=\"literal\">promote</code> as the action that the server should take once the recovery target is reached. Additional <a class=\"link\" href=\"/docs/18/runtime-config-wal.html#RUNTIME-CONFIG-WAL-RECOVERY-TARGET\" title=\"19.5.6.\u00a0Recovery Target\">recovery parameters</a> 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 <code class=\"option\">--recovery-timeout</code> option is set, <span class=\"application\">pg_createsubscriber</span> terminates if recovery does not end until the given number of seconds.</p>\n</li>\n<li class=\"step\">\n<p>Create a subscription for each specified database on the target server. If the <code class=\"option\">--subscription</code> option is not specified, the subscription has the following name pattern: <span class=\"quote\">\u201c<span class=\"quote\"><code class=\"literal\">pg_createsubscriber_%u_%x</code></span>\u201d</span> (parameters: database <em class=\"parameter\"><code>oid</code></em>, random <em class=\"parameter\"><code>int</code></em>). 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.</p>\n</li>\n<li class=\"step\">\n<p>Drop publications on the target server that were replicated because they were created before the replication start location. It has no use on the subscriber.</p>\n</li>\n<li class=\"step\">\n<p>Set 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 <a class=\"link\" href=\"/docs/18/functions-admin.html#PG-REPLICATION-ORIGIN-ADVANCE\"><code class=\"function\">pg_replication_origin_advance()</code></a> to set up the initial replication location.</p>\n</li>\n<li class=\"step\">\n<p>Enable the subscription for each specified database on the target server. The subscription starts applying transactions from the replication start point.</p>\n</li>\n<li class=\"step\">\n<p>If the standby server was using <a class=\"xref\" href=\"/docs/18/runtime-config-replication.html#GUC-PRIMARY-SLOT-NAME\">primary_slot_name</a>, it has no use from now on so drop it.</p>\n</li>\n<li class=\"step\">\n<p>If the standby server contains <a class=\"link\" href=\"/docs/18/logicaldecoding-explanation.html#LOGICALDECODING-REPLICATION-SLOTS-SYNCHRONIZATION\" title=\"47.2.3.\u00a0Replication Slot Synchronization\">failover replication slots</a>, they cannot be synchronized anymore, so drop them.</p>\n</li>\n<li class=\"step\">\n<p>Update the system identifier on the target server. The <a class=\"xref\" href=\"/docs/18/app-pgresetwal.html\" title=\"pg_resetwal\"><span class=\"refentrytitle\"><span class=\"application\">pg_resetwal</span></span></a> is run to modify the system identifier. The target server is stopped as a <code class=\"command\">pg_resetwal</code> requirement.</p>\n</li>\n</ol>\n</div>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.5.7.8\">\n<h2>Examples</h2>\n<p>To create a logical replica for databases <code class=\"literal\">hr</code> and <code class=\"literal\">finance</code> from a physical replica at <code class=\"literal\">foo</code>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_createsubscriber -D /usr/local/pgsql/data -P \"host=foo\" -d hr -d finance</code></strong>\n</pre>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.5.7.9\">\n<h2>See Also</h2><span class=\"simplelist\"><a class=\"xref\" href=\"/docs/18/app-pgbasebackup.html\" title=\"pg_basebackup\"><span class=\"refentrytitle\"><span class=\"application\">pg_basebackup</span></span></a></span>\n</div>\n</div></div>", "manual_path": "app-pgcreatesubscriber.html", "comparison_data": {"options": [{"names": ["-a", "--all"], "signature": "-a --all", "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": ["-d dbname", "--database= dbname"], "signature": "-d dbname --database= dbname", "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 directory", "--pgdata= directory"], "signature": "-D directory --pgdata= directory", "description": "The target directory that contains a cluster directory from a physical replica."}, {"names": ["-n", "--dry-run"], "signature": "-n --dry-run", "description": "Do everything except actually modifying the target directory."}, {"names": ["-p port", "--subscriber-port= port"], "signature": "-p port --subscriber-port= port", "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 connstr", "--publisher-server= connstr"], "signature": "-P connstr --publisher-server= connstr", "description": "The connection string to the publisher. For details see Section 32.1.1 ."}, {"names": ["-s dir", "--socketdir= dir"], "signature": "-s dir --socketdir= dir", "description": "The directory to use for postmaster sockets on target server. The default is current directory."}, {"names": ["-t seconds", "--recovery-timeout= seconds"], "signature": "-t seconds --recovery-timeout= seconds", "description": "The maximum number of seconds to wait for recovery to end. Setting to 0 disables. The default is 0."}, {"names": ["-T", "--enable-two-phase"], "signature": "-T --enable-two-phase", "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": ["-U username", "--subscriber-username= username"], "signature": "-U username --subscriber-username= username", "description": "The user name to connect as on target server. Defaults to the current operating system user name."}, {"names": ["-v", "--verbose"], "signature": "-v --verbose", "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": ["--clean= objtype"], "signature": "--clean= objtype", "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": ["--config-file= filename"], "signature": "--config-file= filename", "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": ["--publication= name"], "signature": "--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": ["--replication-slot= name"], "signature": "--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": ["--subscription= name"], "signature": "--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": ["-V", "--version"], "signature": "-V --version", "description": "Print the pg_createsubscriber version and exit."}, {"names": ["-?", "--help"], "signature": "-? --help", "description": "Show help about pg_createsubscriber command line arguments, and exit."}], "synopsis": ["pg_createsubscriber [ option ...] { -d | --database } dbname { -D | --pgdata } datadir { -P | --publisher-server } connstr"], "environment": []}, "comparison_hash": "ab2f9ba9dc71a377cdb3a682c66b1a84f3cb3ae29cb8c1b178c5acc418bc4441"}, "comparison": {"left": "16", "right": "17", "status": "added", "diff": "--- PostgreSQL 16\n+++ PostgreSQL 17\n@@ -1 +1,124 @@\n-Not recorded in this version\n+{\n+  \"environment\": [],\n+  \"options\": [\n+    {\n+      \"description\": \"The name of the database in which to create a subscription. Multiple databases can be selected by writing multiple -d switches.\",\n+      \"names\": [\n+        \"-d dbname\",\n+        \"--database= dbname\"\n+      ],\n+      \"signature\": \"-d dbname --database= dbname\"\n+    },\n+    {\n+      \"description\": \"The target directory that contains a cluster directory from a physical replica.\",\n+      \"names\": [\n+        \"-D directory\",\n+        \"--pgdata= directory\"\n+      ],\n+      \"signature\": \"-D directory --pgdata= directory\"\n+    },\n+    {\n+      \"description\": \"Do everything except actually modifying the target directory.\",\n+      \"names\": [\n+        \"-n\",\n+        \"--dry-run\"\n+      ],\n+      \"signature\": \"-n --dry-run\"\n+    },\n+    {\n+      \"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.\",\n+      \"names\": [\n+        \"-p port\",\n+        \"--subscriber-port= port\"\n+      ],\n+      \"signature\": \"-p port --subscriber-port= port\"\n+    },\n+    {\n+      \"description\": \"The connection string to the publisher. For details see Section 32.1.1 .\",\n+      \"names\": [\n+        \"-P connstr\",\n+        \"--publisher-server= connstr\"\n+      ],\n+      \"signature\": \"-P connstr --publisher-server= connstr\"\n+    },\n+    {\n+      \"description\": \"The directory to use for postmaster sockets on target server. The default is current directory.\",\n+      \"names\": [\n+        \"-s dir\",\n+        \"--socketdir= dir\"\n+      ],\n+      \"signature\": \"-s dir --socketdir= dir\"\n+    },\n+    {\n+      \"description\": \"The maximum number of seconds to wait for recovery to end. Setting to 0 disables. The default is 0.\",\n+      \"names\": [\n+        \"-t seconds\",\n+        \"--recovery-timeout= seconds\"\n+      ],\n+      \"signature\": \"-t seconds --recovery-timeout= seconds\"\n+    },\n+    {\n+      \"description\": \"The user name to connect as on target server. Defaults to the current operating system user name.\",\n+      \"names\": [\n+        \"-U username\",\n+        \"--subscriber-username= username\"\n+      ],\n+      \"signature\": \"-U username --subscriber-username= username\"\n+    },\n+    {\n+      \"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.\",\n+      \"names\": [\n+        \"-v\",\n+        \"--verbose\"\n+      ],\n+      \"signature\": \"-v --verbose\"\n+    },\n+    {\n+      \"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.\",\n+      \"names\": [\n+        \"--config-file= filename\"\n+      ],\n+      \"signature\": \"--config-file= filename\"\n+    },\n+    {\n+      \"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.\",\n+      \"names\": [\n+        \"--publication= name\"\n+      ],\n+      \"signature\": \"--publication= name\"\n+    },\n+    {\n+      \"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.\",\n+      \"names\": [\n+        \"--replication-slot= name\"\n+      ],\n+      \"signature\": \"--replication-slot= name\"\n+    },\n+    {\n+      \"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.\",\n+      \"names\": [\n+        \"--subscription= name\"\n+      ],\n+      \"signature\": \"--subscription= name\"\n+    },\n+    {\n+      \"description\": \"Print the pg_createsubscriber version and exit.\",\n+      \"names\": [\n+        \"-V\",\n+        \"--version\"\n+      ],\n+      \"signature\": \"-V --version\"\n+    },\n+    {\n+      \"description\": \"Show help about pg_createsubscriber command line arguments, and exit.\",\n+      \"names\": [\n+        \"-?\",\n+        \"--help\"\n+      ],\n+      \"signature\": \"-? --help\"\n+    }\n+  ],\n+  \"synopsis\": [\n+    \"pg_createsubscriber [ option ...] { -d | --database } dbname { -D | --pgdata } datadir { -P | --publisher-server } connstr\"\n+  ]\n+}"}}