2017-01-19 18:00:00 +01:00
|
|
|
<!--
|
|
|
|
doc/src/sgml/ref/create_subscription.sgml
|
|
|
|
PostgreSQL documentation
|
|
|
|
-->
|
|
|
|
|
2017-10-20 03:16:39 +02:00
|
|
|
<refentry id="sql-createsubscription">
|
2017-01-19 18:00:00 +01:00
|
|
|
<indexterm zone="sql-createsubscription">
|
|
|
|
<primary>CREATE SUBSCRIPTION</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<refmeta>
|
|
|
|
<refentrytitle>CREATE SUBSCRIPTION</refentrytitle>
|
|
|
|
<manvolnum>7</manvolnum>
|
|
|
|
<refmiscinfo>SQL - Language Statements</refmiscinfo>
|
|
|
|
</refmeta>
|
|
|
|
|
|
|
|
<refnamediv>
|
|
|
|
<refname>CREATE SUBSCRIPTION</refname>
|
|
|
|
<refpurpose>define a new subscription</refpurpose>
|
|
|
|
</refnamediv>
|
|
|
|
|
|
|
|
<refsynopsisdiv>
|
|
|
|
<synopsis>
|
2017-10-09 04:00:57 +02:00
|
|
|
CREATE SUBSCRIPTION <replaceable class="parameter">subscription_name</replaceable>
|
|
|
|
CONNECTION '<replaceable class="parameter">conninfo</replaceable>'
|
|
|
|
PUBLICATION <replaceable class="parameter">publication_name</replaceable> [, ...]
|
2017-05-12 14:57:01 +02:00
|
|
|
[ WITH ( <replaceable class="parameter">subscription_parameter</replaceable> [= <replaceable class="parameter">value</replaceable>] [, ... ] ) ]
|
2017-01-19 18:00:00 +01:00
|
|
|
</synopsis>
|
|
|
|
</refsynopsisdiv>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>Description</title>
|
|
|
|
|
|
|
|
<para>
|
2021-09-13 20:27:02 +02:00
|
|
|
<command>CREATE SUBSCRIPTION</command> adds a new logical-replication
|
|
|
|
subscription. The subscription name must be distinct from the name of
|
|
|
|
any existing subscription in the current database.
|
2017-01-19 18:00:00 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2021-09-13 20:27:02 +02:00
|
|
|
A subscription represents a replication connection to the publisher.
|
|
|
|
Hence, in addition to adding definitions in the local catalogs, this
|
|
|
|
command normally creates a replication slot on the publisher.
|
2017-01-19 18:00:00 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
A logical replication worker will be started to replicate data for the new
|
2021-09-13 20:27:02 +02:00
|
|
|
subscription at the commit of the transaction where this command is run,
|
|
|
|
unless the subscription is initially disabled.
|
2017-01-19 18:00:00 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2018-11-03 17:21:54 +01:00
|
|
|
Additional information about subscriptions and logical replication as a
|
|
|
|
whole is available at <xref linkend="logical-replication-subscription"/> and
|
2017-11-23 15:39:47 +01:00
|
|
|
<xref linkend="logical-replication"/>.
|
2017-01-19 18:00:00 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>Parameters</title>
|
|
|
|
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term><replaceable class="parameter">subscription_name</replaceable></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The name of the new subscription.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><literal>CONNECTION '<replaceable class="parameter">conninfo</replaceable>'</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2021-09-13 20:27:02 +02:00
|
|
|
The <application>libpq</application> connection string defining how
|
|
|
|
to connect to the publisher database. For details see
|
|
|
|
<xref linkend="libpq-connstring"/>.
|
2017-01-19 18:00:00 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2021-09-13 20:27:02 +02:00
|
|
|
<term><literal>PUBLICATION <replaceable class="parameter">publication_name</replaceable> [, ...]</literal></term>
|
2017-01-19 18:00:00 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-05-12 14:57:01 +02:00
|
|
|
Names of the publications on the publisher to subscribe to.
|
2017-03-23 13:36:36 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2017-04-14 19:58:46 +02:00
|
|
|
<varlistentry>
|
2017-05-12 14:57:01 +02:00
|
|
|
<term><literal>WITH ( <replaceable class="parameter">subscription_parameter</replaceable> [= <replaceable class="parameter">value</replaceable>] [, ... ] )</literal></term>
|
2017-04-14 19:58:46 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2021-09-13 04:59:10 +02:00
|
|
|
This clause specifies optional parameters for a subscription.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The following parameters control what happens during subscription creation:
|
2017-05-12 14:57:01 +02:00
|
|
|
|
|
|
|
<variablelist>
|
2021-09-13 04:59:10 +02:00
|
|
|
|
2017-05-12 14:57:01 +02:00
|
|
|
<varlistentry>
|
2021-09-13 04:59:10 +02:00
|
|
|
<term><literal>connect</literal> (<type>boolean</type>)</term>
|
2017-05-12 14:57:01 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2021-09-13 04:59:10 +02:00
|
|
|
Specifies whether the <command>CREATE SUBSCRIPTION</command>
|
2021-09-13 20:27:02 +02:00
|
|
|
command should connect to the publisher at all. The default
|
|
|
|
is <literal>true</literal>. Setting this to
|
|
|
|
<literal>false</literal> will force the values of
|
|
|
|
<literal>create_slot</literal>, <literal>enabled</literal> and
|
2021-09-13 04:59:10 +02:00
|
|
|
<literal>copy_data</literal> to <literal>false</literal>.
|
2021-09-13 20:27:02 +02:00
|
|
|
(You cannot combine setting <literal>connect</literal>
|
|
|
|
to <literal>false</literal> with
|
|
|
|
setting <literal>create_slot</literal>, <literal>enabled</literal>,
|
|
|
|
or <literal>copy_data</literal> to <literal>true</literal>.)
|
2021-09-13 04:59:10 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2021-09-13 20:27:02 +02:00
|
|
|
Since no connection is made when this option is
|
|
|
|
<literal>false</literal>, no tables are subscribed, and so
|
2021-09-13 04:59:10 +02:00
|
|
|
after you enable the subscription nothing will be replicated.
|
2021-09-13 20:27:02 +02:00
|
|
|
You will need to then run
|
|
|
|
<literal>ALTER SUBSCRIPTION ... REFRESH PUBLICATION</literal>
|
2021-09-13 04:59:10 +02:00
|
|
|
for tables to be subscribed.
|
2017-05-12 14:57:01 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><literal>create_slot</literal> (<type>boolean</type>)</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Specifies whether the command should create the replication slot on
|
|
|
|
the publisher. The default is <literal>true</literal>.
|
2021-09-13 20:27:02 +02:00
|
|
|
If set to <literal>false</literal>, you are responsible for
|
|
|
|
creating the publisher's slot in some other way.
|
2017-05-12 14:57:01 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><literal>enabled</literal> (<type>boolean</type>)</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2021-09-13 20:27:02 +02:00
|
|
|
Specifies whether the subscription should be actively replicating
|
|
|
|
or whether it should just be set up but not started yet. The default
|
2017-05-12 14:57:01 +02:00
|
|
|
is <literal>true</literal>.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><literal>slot_name</literal> (<type>string</type>)</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2021-09-13 20:27:02 +02:00
|
|
|
Name of the publisher's replication slot to use. The default is
|
|
|
|
to use the name of the subscription for the slot name.
|
2017-05-12 14:57:01 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2021-09-13 20:27:02 +02:00
|
|
|
Setting <literal>slot_name</literal> to <literal>NONE</literal>
|
|
|
|
means there will be no replication slot
|
|
|
|
associated with the subscription. Use this when you will be
|
|
|
|
creating the replication slot later manually. Such
|
2017-05-12 14:57:01 +02:00
|
|
|
subscriptions must also have both <literal>enabled</literal> and
|
|
|
|
<literal>create_slot</literal> set to <literal>false</literal>.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2021-09-13 04:59:10 +02:00
|
|
|
</variablelist>
|
|
|
|
</para>
|
2017-05-12 14:57:01 +02:00
|
|
|
|
2021-09-13 04:59:10 +02:00
|
|
|
<para>
|
2021-09-13 20:27:02 +02:00
|
|
|
The following parameters control the subscription's replication
|
|
|
|
behavior after it has been created:
|
2017-05-12 14:57:01 +02:00
|
|
|
|
2021-09-13 04:59:10 +02:00
|
|
|
<variablelist>
|
2017-05-12 14:57:01 +02:00
|
|
|
|
2020-07-18 18:44:51 +02:00
|
|
|
<varlistentry>
|
|
|
|
<term><literal>binary</literal> (<type>boolean</type>)</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Specifies whether the subscription will request the publisher to
|
|
|
|
send the data in binary format (as opposed to text).
|
|
|
|
The default is <literal>false</literal>.
|
2021-09-13 20:27:02 +02:00
|
|
|
Even when this option is enabled, only data types having
|
2020-07-18 18:44:51 +02:00
|
|
|
binary send and receive functions will be transferred in binary.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2021-09-13 20:27:02 +02:00
|
|
|
When doing cross-version replication, it could be that the
|
2020-07-18 18:44:51 +02:00
|
|
|
publisher has a binary send function for some data type, but the
|
2021-09-13 20:27:02 +02:00
|
|
|
subscriber lacks a binary receive function for that type. In
|
2020-07-18 18:44:51 +02:00
|
|
|
such a case, data transfer will fail, and
|
|
|
|
the <literal>binary</literal> option cannot be used.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2017-05-12 14:57:01 +02:00
|
|
|
<varlistentry>
|
2021-09-13 04:59:10 +02:00
|
|
|
<term><literal>copy_data</literal> (<type>boolean</type>)</term>
|
2017-05-12 14:57:01 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2021-09-13 20:27:02 +02:00
|
|
|
Specifies whether to copy pre-existing data in the publications
|
|
|
|
that are being subscribed to when the replication starts.
|
2021-09-13 04:59:10 +02:00
|
|
|
The default is <literal>true</literal>.
|
2017-05-12 14:57:01 +02:00
|
|
|
</para>
|
Allow specifying row filters for logical replication of tables.
This feature adds row filtering for publication tables. When a publication
is defined or modified, an optional WHERE clause can be specified. Rows
that don't satisfy this WHERE clause will be filtered out. This allows a
set of tables to be partially replicated. The row filter is per table. A
new row filter can be added simply by specifying a WHERE clause after the
table name. The WHERE clause must be enclosed by parentheses.
The row filter WHERE clause for a table added to a publication that
publishes UPDATE and/or DELETE operations must contain only columns that
are covered by REPLICA IDENTITY. The row filter WHERE clause for a table
added to a publication that publishes INSERT can use any column. If the
row filter evaluates to NULL, it is regarded as "false". The WHERE clause
only allows simple expressions that don't have user-defined functions,
user-defined operators, user-defined types, user-defined collations,
non-immutable built-in functions, or references to system columns. These
restrictions could be addressed in the future.
If you choose to do the initial table synchronization, only data that
satisfies the row filters is copied to the subscriber. If the subscription
has several publications in which a table has been published with
different WHERE clauses, rows that satisfy ANY of the expressions will be
copied. If a subscriber is a pre-15 version, the initial table
synchronization won't use row filters even if they are defined in the
publisher.
The row filters are applied before publishing the changes. If the
subscription has several publications in which the same table has been
published with different filters (for the same publish operation), those
expressions get OR'ed together so that rows satisfying any of the
expressions will be replicated.
This means all the other filters become redundant if (a) one of the
publications have no filter at all, (b) one of the publications was
created using FOR ALL TABLES, (c) one of the publications was created
using FOR ALL TABLES IN SCHEMA and the table belongs to that same schema.
If your publication contains a partitioned table, the publication
parameter publish_via_partition_root determines if it uses the partition's
row filter (if the parameter is false, the default) or the root
partitioned table's row filter.
Psql commands \dRp+ and \d <table-name> will display any row filters.
Author: Hou Zhijie, Euler Taveira, Peter Smith, Ajin Cherian
Reviewed-by: Greg Nancarrow, Haiying Tang, Amit Kapila, Tomas Vondra, Dilip Kumar, Vignesh C, Alvaro Herrera, Andres Freund, Wei Wang
Discussion: https://www.postgresql.org/message-id/flat/CAHE3wggb715X%2BmK_DitLXF25B%3DjE6xyNCH4YOwM860JR7HarGQ%40mail.gmail.com
2022-02-22 03:24:12 +01:00
|
|
|
<para>
|
|
|
|
If the publications contain <literal>WHERE</literal> clauses, it
|
|
|
|
will affect what data is copied. Refer to the
|
|
|
|
<xref linkend="sql-createsubscription-notes" /> for details.
|
|
|
|
</para>
|
2022-09-08 03:24:13 +02:00
|
|
|
<para>
|
|
|
|
See <xref linkend="sql-createsubscription-notes"/> for details of how
|
|
|
|
<literal>copy_data = true</literal> can interact with the
|
|
|
|
<literal>origin</literal> parameter.
|
|
|
|
</para>
|
2017-05-12 14:57:01 +02:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2021-09-13 04:59:10 +02:00
|
|
|
|
Add support for streaming to built-in logical replication.
To add support for streaming of in-progress transactions into the
built-in logical replication, we need to do three things:
* Extend the logical replication protocol, so identify in-progress
transactions, and allow adding additional bits of information (e.g.
XID of subtransactions).
* Modify the output plugin (pgoutput) to implement the new stream
API callbacks, by leveraging the extended replication protocol.
* Modify the replication apply worker, to properly handle streamed
in-progress transaction by spilling the data to disk and then
replaying them on commit.
We however must explicitly disable streaming replication during
replication slot creation, even if the plugin supports it. We
don't need to replicate the changes accumulated during this phase,
and moreover we don't have a replication connection open so we
don't have where to send the data anyway.
Author: Tomas Vondra, Dilip Kumar and Amit Kapila
Reviewed-by: Amit Kapila, Kuntal Ghosh and Ajin Cherian
Tested-by: Neha Sharma, Mahendra Singh Thalor and Ajin Cherian
Discussion: https://postgr.es/m/688b0b7f-2f6c-d827-c27b-216a8e3ea700@2ndquadrant.com
2020-09-03 04:24:07 +02:00
|
|
|
<varlistentry>
|
|
|
|
<term><literal>streaming</literal> (<type>boolean</type>)</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2021-09-13 20:27:02 +02:00
|
|
|
Specifies whether to enable streaming of in-progress transactions
|
|
|
|
for this subscription. By default, all transactions
|
|
|
|
are fully decoded on the publisher and only then sent to the
|
Add support for streaming to built-in logical replication.
To add support for streaming of in-progress transactions into the
built-in logical replication, we need to do three things:
* Extend the logical replication protocol, so identify in-progress
transactions, and allow adding additional bits of information (e.g.
XID of subtransactions).
* Modify the output plugin (pgoutput) to implement the new stream
API callbacks, by leveraging the extended replication protocol.
* Modify the replication apply worker, to properly handle streamed
in-progress transaction by spilling the data to disk and then
replaying them on commit.
We however must explicitly disable streaming replication during
replication slot creation, even if the plugin supports it. We
don't need to replicate the changes accumulated during this phase,
and moreover we don't have a replication connection open so we
don't have where to send the data anyway.
Author: Tomas Vondra, Dilip Kumar and Amit Kapila
Reviewed-by: Amit Kapila, Kuntal Ghosh and Ajin Cherian
Tested-by: Neha Sharma, Mahendra Singh Thalor and Ajin Cherian
Discussion: https://postgr.es/m/688b0b7f-2f6c-d827-c27b-216a8e3ea700@2ndquadrant.com
2020-09-03 04:24:07 +02:00
|
|
|
subscriber as a whole.
|
|
|
|
</para>
|
2021-09-13 04:59:10 +02:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><literal>synchronous_commit</literal> (<type>enum</type>)</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The value of this parameter overrides the
|
|
|
|
<xref linkend="guc-synchronous-commit"/> setting within this
|
|
|
|
subscription's apply worker processes. The default value
|
|
|
|
is <literal>off</literal>.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
It is safe to use <literal>off</literal> for logical replication:
|
|
|
|
If the subscriber loses transactions because of missing
|
|
|
|
synchronization, the data will be sent again from the publisher.
|
|
|
|
</para>
|
Add support for prepared transactions to built-in logical replication.
To add support for streaming transactions at prepare time into the
built-in logical replication, we need to do the following things:
* Modify the output plugin (pgoutput) to implement the new two-phase API
callbacks, by leveraging the extended replication protocol.
* Modify the replication apply worker, to properly handle two-phase
transactions by replaying them on prepare.
* Add a new SUBSCRIPTION option "two_phase" to allow users to enable
two-phase transactions. We enable the two_phase once the initial data sync
is over.
We however must explicitly disable replication of two-phase transactions
during replication slot creation, even if the plugin supports it. We
don't need to replicate the changes accumulated during this phase,
and moreover, we don't have a replication connection open so we don't know
where to send the data anyway.
The streaming option is not allowed with this new two_phase option. This
can be done as a separate patch.
We don't allow to toggle two_phase option of a subscription because it can
lead to an inconsistent replica. For the same reason, we don't allow to
refresh the publication once the two_phase is enabled for a subscription
unless copy_data option is false.
Author: Peter Smith, Ajin Cherian and Amit Kapila based on previous work by Nikhil Sontakke and Stas Kelvich
Reviewed-by: Amit Kapila, Sawada Masahiko, Vignesh C, Dilip Kumar, Takamichi Osumi, Greg Nancarrow
Tested-By: Haiying Tang
Discussion: https://postgr.es/m/02DA5F5E-CECE-4D9C-8B4B-418077E2C010@postgrespro.ru
Discussion: https://postgr.es/m/CAA4eK1+opiV4aFTmWWUF9h_32=HfPOW9vZASHarT0UA5oBrtGw@mail.gmail.com
2021-07-14 04:03:50 +02:00
|
|
|
|
2021-09-13 04:59:10 +02:00
|
|
|
<para>
|
|
|
|
A different setting might be appropriate when doing synchronous
|
|
|
|
logical replication. The logical replication workers report the
|
|
|
|
positions of writes and flushes to the publisher, and when using
|
|
|
|
synchronous replication, the publisher will wait for the actual
|
|
|
|
flush. This means that setting
|
|
|
|
<literal>synchronous_commit</literal> for the subscriber to
|
|
|
|
<literal>off</literal> when the subscription is used for
|
|
|
|
synchronous replication might increase the latency for
|
|
|
|
<command>COMMIT</command> on the publisher. In this scenario, it
|
|
|
|
can be advantageous to set <literal>synchronous_commit</literal>
|
|
|
|
to <literal>local</literal> or higher.
|
|
|
|
</para>
|
Add support for prepared transactions to built-in logical replication.
To add support for streaming transactions at prepare time into the
built-in logical replication, we need to do the following things:
* Modify the output plugin (pgoutput) to implement the new two-phase API
callbacks, by leveraging the extended replication protocol.
* Modify the replication apply worker, to properly handle two-phase
transactions by replaying them on prepare.
* Add a new SUBSCRIPTION option "two_phase" to allow users to enable
two-phase transactions. We enable the two_phase once the initial data sync
is over.
We however must explicitly disable replication of two-phase transactions
during replication slot creation, even if the plugin supports it. We
don't need to replicate the changes accumulated during this phase,
and moreover, we don't have a replication connection open so we don't know
where to send the data anyway.
The streaming option is not allowed with this new two_phase option. This
can be done as a separate patch.
We don't allow to toggle two_phase option of a subscription because it can
lead to an inconsistent replica. For the same reason, we don't allow to
refresh the publication once the two_phase is enabled for a subscription
unless copy_data option is false.
Author: Peter Smith, Ajin Cherian and Amit Kapila based on previous work by Nikhil Sontakke and Stas Kelvich
Reviewed-by: Amit Kapila, Sawada Masahiko, Vignesh C, Dilip Kumar, Takamichi Osumi, Greg Nancarrow
Tested-By: Haiying Tang
Discussion: https://postgr.es/m/02DA5F5E-CECE-4D9C-8B4B-418077E2C010@postgrespro.ru
Discussion: https://postgr.es/m/CAA4eK1+opiV4aFTmWWUF9h_32=HfPOW9vZASHarT0UA5oBrtGw@mail.gmail.com
2021-07-14 04:03:50 +02:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2021-09-13 04:59:10 +02:00
|
|
|
|
Add support for prepared transactions to built-in logical replication.
To add support for streaming transactions at prepare time into the
built-in logical replication, we need to do the following things:
* Modify the output plugin (pgoutput) to implement the new two-phase API
callbacks, by leveraging the extended replication protocol.
* Modify the replication apply worker, to properly handle two-phase
transactions by replaying them on prepare.
* Add a new SUBSCRIPTION option "two_phase" to allow users to enable
two-phase transactions. We enable the two_phase once the initial data sync
is over.
We however must explicitly disable replication of two-phase transactions
during replication slot creation, even if the plugin supports it. We
don't need to replicate the changes accumulated during this phase,
and moreover, we don't have a replication connection open so we don't know
where to send the data anyway.
The streaming option is not allowed with this new two_phase option. This
can be done as a separate patch.
We don't allow to toggle two_phase option of a subscription because it can
lead to an inconsistent replica. For the same reason, we don't allow to
refresh the publication once the two_phase is enabled for a subscription
unless copy_data option is false.
Author: Peter Smith, Ajin Cherian and Amit Kapila based on previous work by Nikhil Sontakke and Stas Kelvich
Reviewed-by: Amit Kapila, Sawada Masahiko, Vignesh C, Dilip Kumar, Takamichi Osumi, Greg Nancarrow
Tested-By: Haiying Tang
Discussion: https://postgr.es/m/02DA5F5E-CECE-4D9C-8B4B-418077E2C010@postgrespro.ru
Discussion: https://postgr.es/m/CAA4eK1+opiV4aFTmWWUF9h_32=HfPOW9vZASHarT0UA5oBrtGw@mail.gmail.com
2021-07-14 04:03:50 +02:00
|
|
|
<varlistentry>
|
|
|
|
<term><literal>two_phase</literal> (<type>boolean</type>)</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Specifies whether two-phase commit is enabled for this subscription.
|
|
|
|
The default is <literal>false</literal>.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2021-09-13 20:27:02 +02:00
|
|
|
When two-phase commit is enabled, prepared transactions are sent
|
|
|
|
to the subscriber at the time of <command>PREPARE
|
|
|
|
TRANSACTION</command>, and are processed as two-phase
|
|
|
|
transactions on the subscriber too. Otherwise, prepared
|
|
|
|
transactions are sent to the subscriber only when committed, and
|
|
|
|
are then processed immediately by the subscriber.
|
Add support for prepared transactions to built-in logical replication.
To add support for streaming transactions at prepare time into the
built-in logical replication, we need to do the following things:
* Modify the output plugin (pgoutput) to implement the new two-phase API
callbacks, by leveraging the extended replication protocol.
* Modify the replication apply worker, to properly handle two-phase
transactions by replaying them on prepare.
* Add a new SUBSCRIPTION option "two_phase" to allow users to enable
two-phase transactions. We enable the two_phase once the initial data sync
is over.
We however must explicitly disable replication of two-phase transactions
during replication slot creation, even if the plugin supports it. We
don't need to replicate the changes accumulated during this phase,
and moreover, we don't have a replication connection open so we don't know
where to send the data anyway.
The streaming option is not allowed with this new two_phase option. This
can be done as a separate patch.
We don't allow to toggle two_phase option of a subscription because it can
lead to an inconsistent replica. For the same reason, we don't allow to
refresh the publication once the two_phase is enabled for a subscription
unless copy_data option is false.
Author: Peter Smith, Ajin Cherian and Amit Kapila based on previous work by Nikhil Sontakke and Stas Kelvich
Reviewed-by: Amit Kapila, Sawada Masahiko, Vignesh C, Dilip Kumar, Takamichi Osumi, Greg Nancarrow
Tested-By: Haiying Tang
Discussion: https://postgr.es/m/02DA5F5E-CECE-4D9C-8B4B-418077E2C010@postgrespro.ru
Discussion: https://postgr.es/m/CAA4eK1+opiV4aFTmWWUF9h_32=HfPOW9vZASHarT0UA5oBrtGw@mail.gmail.com
2021-07-14 04:03:50 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2021-09-13 20:27:02 +02:00
|
|
|
The implementation of two-phase commit requires that replication
|
|
|
|
has successfully finished the initial table synchronization
|
|
|
|
phase. So even when <literal>two_phase</literal> is enabled for a
|
|
|
|
subscription, the internal two-phase state remains
|
|
|
|
temporarily <quote>pending</quote> until the initialization phase
|
|
|
|
completes. See column <structfield>subtwophasestate</structfield>
|
|
|
|
of <link linkend="catalog-pg-subscription"><structname>pg_subscription</structname></link>
|
Add support for prepared transactions to built-in logical replication.
To add support for streaming transactions at prepare time into the
built-in logical replication, we need to do the following things:
* Modify the output plugin (pgoutput) to implement the new two-phase API
callbacks, by leveraging the extended replication protocol.
* Modify the replication apply worker, to properly handle two-phase
transactions by replaying them on prepare.
* Add a new SUBSCRIPTION option "two_phase" to allow users to enable
two-phase transactions. We enable the two_phase once the initial data sync
is over.
We however must explicitly disable replication of two-phase transactions
during replication slot creation, even if the plugin supports it. We
don't need to replicate the changes accumulated during this phase,
and moreover, we don't have a replication connection open so we don't know
where to send the data anyway.
The streaming option is not allowed with this new two_phase option. This
can be done as a separate patch.
We don't allow to toggle two_phase option of a subscription because it can
lead to an inconsistent replica. For the same reason, we don't allow to
refresh the publication once the two_phase is enabled for a subscription
unless copy_data option is false.
Author: Peter Smith, Ajin Cherian and Amit Kapila based on previous work by Nikhil Sontakke and Stas Kelvich
Reviewed-by: Amit Kapila, Sawada Masahiko, Vignesh C, Dilip Kumar, Takamichi Osumi, Greg Nancarrow
Tested-By: Haiying Tang
Discussion: https://postgr.es/m/02DA5F5E-CECE-4D9C-8B4B-418077E2C010@postgrespro.ru
Discussion: https://postgr.es/m/CAA4eK1+opiV4aFTmWWUF9h_32=HfPOW9vZASHarT0UA5oBrtGw@mail.gmail.com
2021-07-14 04:03:50 +02:00
|
|
|
to know the actual two-phase state.
|
|
|
|
</para>
|
|
|
|
|
Add support for streaming to built-in logical replication.
To add support for streaming of in-progress transactions into the
built-in logical replication, we need to do three things:
* Extend the logical replication protocol, so identify in-progress
transactions, and allow adding additional bits of information (e.g.
XID of subtransactions).
* Modify the output plugin (pgoutput) to implement the new stream
API callbacks, by leveraging the extended replication protocol.
* Modify the replication apply worker, to properly handle streamed
in-progress transaction by spilling the data to disk and then
replaying them on commit.
We however must explicitly disable streaming replication during
replication slot creation, even if the plugin supports it. We
don't need to replicate the changes accumulated during this phase,
and moreover we don't have a replication connection open so we
don't have where to send the data anyway.
Author: Tomas Vondra, Dilip Kumar and Amit Kapila
Reviewed-by: Amit Kapila, Kuntal Ghosh and Ajin Cherian
Tested-by: Neha Sharma, Mahendra Singh Thalor and Ajin Cherian
Discussion: https://postgr.es/m/688b0b7f-2f6c-d827-c27b-216a8e3ea700@2ndquadrant.com
2020-09-03 04:24:07 +02:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
Optionally disable subscriptions on error.
Logical replication apply workers for a subscription can easily get stuck
in an infinite loop of attempting to apply a change, triggering an error
(such as a constraint violation), exiting with the error written to the
subscription server log, and restarting.
To partially remedy the situation, this patch adds a new subscription
option named 'disable_on_error'. To be consistent with old behavior, this
option defaults to false. When true, both the tablesync worker and apply
worker catch any errors thrown and disable the subscription in order to
break the loop. The error is still also written in the logs.
Once the subscription is disabled, users can either manually resolve the
conflict/error or skip the conflicting transaction by using
pg_replication_origin_advance() function. After resolving the conflict,
users need to enable the subscription to allow apply process to proceed.
Author: Osumi Takamichi and Mark Dilger
Reviewed-by: Greg Nancarrow, Vignesh C, Amit Kapila, Wang wei, Tang Haiying, Peter Smith, Masahiko Sawada, Shi Yu
Discussion : https://postgr.es/m/DB35438F-9356-4841-89A0-412709EBD3AB%40enterprisedb.com
2022-03-14 05:02:40 +01:00
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><literal>disable_on_error</literal> (<type>boolean</type>)</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Specifies whether the subscription should be automatically disabled
|
|
|
|
if any errors are detected by subscription workers during data
|
|
|
|
replication from the publisher. The default is
|
|
|
|
<literal>false</literal>.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2022-07-21 05:17:38 +02:00
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><literal>origin</literal> (<type>string</type>)</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Specifies whether the subscription will request the publisher to only
|
|
|
|
send changes that don't have an origin or send changes regardless of
|
|
|
|
origin. Setting <literal>origin</literal> to <literal>none</literal>
|
|
|
|
means that the subscription will request the publisher to only send
|
|
|
|
changes that don't have an origin. Setting <literal>origin</literal>
|
|
|
|
to <literal>any</literal> means that the publisher sends changes
|
|
|
|
regardless of their origin. The default is <literal>any</literal>.
|
|
|
|
</para>
|
2022-09-08 03:24:13 +02:00
|
|
|
<para>
|
|
|
|
See <xref linkend="sql-createsubscription-notes"/> for details of how
|
|
|
|
<literal>copy_data = true</literal> can interact with the
|
|
|
|
<literal>origin</literal> parameter.
|
|
|
|
</para>
|
2022-07-21 05:17:38 +02:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2022-04-07 18:23:28 +02:00
|
|
|
</variablelist></para>
|
2021-09-13 04:59:10 +02:00
|
|
|
|
2017-03-23 13:36:36 +01:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2017-01-19 18:00:00 +01:00
|
|
|
</variablelist>
|
|
|
|
</refsect1>
|
|
|
|
|
Allow specifying row filters for logical replication of tables.
This feature adds row filtering for publication tables. When a publication
is defined or modified, an optional WHERE clause can be specified. Rows
that don't satisfy this WHERE clause will be filtered out. This allows a
set of tables to be partially replicated. The row filter is per table. A
new row filter can be added simply by specifying a WHERE clause after the
table name. The WHERE clause must be enclosed by parentheses.
The row filter WHERE clause for a table added to a publication that
publishes UPDATE and/or DELETE operations must contain only columns that
are covered by REPLICA IDENTITY. The row filter WHERE clause for a table
added to a publication that publishes INSERT can use any column. If the
row filter evaluates to NULL, it is regarded as "false". The WHERE clause
only allows simple expressions that don't have user-defined functions,
user-defined operators, user-defined types, user-defined collations,
non-immutable built-in functions, or references to system columns. These
restrictions could be addressed in the future.
If you choose to do the initial table synchronization, only data that
satisfies the row filters is copied to the subscriber. If the subscription
has several publications in which a table has been published with
different WHERE clauses, rows that satisfy ANY of the expressions will be
copied. If a subscriber is a pre-15 version, the initial table
synchronization won't use row filters even if they are defined in the
publisher.
The row filters are applied before publishing the changes. If the
subscription has several publications in which the same table has been
published with different filters (for the same publish operation), those
expressions get OR'ed together so that rows satisfying any of the
expressions will be replicated.
This means all the other filters become redundant if (a) one of the
publications have no filter at all, (b) one of the publications was
created using FOR ALL TABLES, (c) one of the publications was created
using FOR ALL TABLES IN SCHEMA and the table belongs to that same schema.
If your publication contains a partitioned table, the publication
parameter publish_via_partition_root determines if it uses the partition's
row filter (if the parameter is false, the default) or the root
partitioned table's row filter.
Psql commands \dRp+ and \d <table-name> will display any row filters.
Author: Hou Zhijie, Euler Taveira, Peter Smith, Ajin Cherian
Reviewed-by: Greg Nancarrow, Haiying Tang, Amit Kapila, Tomas Vondra, Dilip Kumar, Vignesh C, Alvaro Herrera, Andres Freund, Wei Wang
Discussion: https://www.postgresql.org/message-id/flat/CAHE3wggb715X%2BmK_DitLXF25B%3DjE6xyNCH4YOwM860JR7HarGQ%40mail.gmail.com
2022-02-22 03:24:12 +01:00
|
|
|
<refsect1 id="sql-createsubscription-notes" xreflabel="Notes">
|
2017-02-08 03:26:50 +01:00
|
|
|
<title>Notes</title>
|
|
|
|
|
|
|
|
<para>
|
2017-11-23 15:39:47 +01:00
|
|
|
See <xref linkend="logical-replication-security"/> for details on
|
2017-02-08 03:26:50 +01:00
|
|
|
how to configure access control between the subscription and the
|
|
|
|
publication instance.
|
|
|
|
</para>
|
2017-06-09 23:11:46 +02:00
|
|
|
|
2017-09-22 21:01:13 +02:00
|
|
|
<para>
|
|
|
|
When creating a replication slot (the default behavior), <command>CREATE
|
|
|
|
SUBSCRIPTION</command> cannot be executed inside a transaction block.
|
|
|
|
</para>
|
|
|
|
|
2017-06-09 23:11:46 +02:00
|
|
|
<para>
|
|
|
|
Creating a subscription that connects to the same database cluster (for
|
|
|
|
example, to replicate between databases in the same cluster or to replicate
|
|
|
|
within the same database) will only succeed if the replication slot is not
|
|
|
|
created as part of the same command. Otherwise, the <command>CREATE
|
|
|
|
SUBSCRIPTION</command> call will hang. To make this work, create the
|
|
|
|
replication slot separately (using the
|
|
|
|
function <function>pg_create_logical_replication_slot</function> with the
|
|
|
|
plugin name <literal>pgoutput</literal>) and create the subscription using
|
|
|
|
the parameter <literal>create_slot = false</literal>. This is an
|
|
|
|
implementation restriction that might be lifted in a future release.
|
|
|
|
</para>
|
Allow specifying row filters for logical replication of tables.
This feature adds row filtering for publication tables. When a publication
is defined or modified, an optional WHERE clause can be specified. Rows
that don't satisfy this WHERE clause will be filtered out. This allows a
set of tables to be partially replicated. The row filter is per table. A
new row filter can be added simply by specifying a WHERE clause after the
table name. The WHERE clause must be enclosed by parentheses.
The row filter WHERE clause for a table added to a publication that
publishes UPDATE and/or DELETE operations must contain only columns that
are covered by REPLICA IDENTITY. The row filter WHERE clause for a table
added to a publication that publishes INSERT can use any column. If the
row filter evaluates to NULL, it is regarded as "false". The WHERE clause
only allows simple expressions that don't have user-defined functions,
user-defined operators, user-defined types, user-defined collations,
non-immutable built-in functions, or references to system columns. These
restrictions could be addressed in the future.
If you choose to do the initial table synchronization, only data that
satisfies the row filters is copied to the subscriber. If the subscription
has several publications in which a table has been published with
different WHERE clauses, rows that satisfy ANY of the expressions will be
copied. If a subscriber is a pre-15 version, the initial table
synchronization won't use row filters even if they are defined in the
publisher.
The row filters are applied before publishing the changes. If the
subscription has several publications in which the same table has been
published with different filters (for the same publish operation), those
expressions get OR'ed together so that rows satisfying any of the
expressions will be replicated.
This means all the other filters become redundant if (a) one of the
publications have no filter at all, (b) one of the publications was
created using FOR ALL TABLES, (c) one of the publications was created
using FOR ALL TABLES IN SCHEMA and the table belongs to that same schema.
If your publication contains a partitioned table, the publication
parameter publish_via_partition_root determines if it uses the partition's
row filter (if the parameter is false, the default) or the root
partitioned table's row filter.
Psql commands \dRp+ and \d <table-name> will display any row filters.
Author: Hou Zhijie, Euler Taveira, Peter Smith, Ajin Cherian
Reviewed-by: Greg Nancarrow, Haiying Tang, Amit Kapila, Tomas Vondra, Dilip Kumar, Vignesh C, Alvaro Herrera, Andres Freund, Wei Wang
Discussion: https://www.postgresql.org/message-id/flat/CAHE3wggb715X%2BmK_DitLXF25B%3DjE6xyNCH4YOwM860JR7HarGQ%40mail.gmail.com
2022-02-22 03:24:12 +01:00
|
|
|
|
|
|
|
<para>
|
|
|
|
If any table in the publication has a <literal>WHERE</literal> clause, rows
|
|
|
|
for which the <replaceable class="parameter">expression</replaceable>
|
|
|
|
evaluates to false or null will not be published. If the subscription has
|
|
|
|
several publications in which the same table has been published with
|
|
|
|
different <literal>WHERE</literal> clauses, a row will be published if any
|
|
|
|
of the expressions (referring to that publish operation) are satisfied. In
|
|
|
|
the case of different <literal>WHERE</literal> clauses, if one of the
|
|
|
|
publications has no <literal>WHERE</literal> clause (referring to that
|
|
|
|
publish operation) or the publication is declared as
|
|
|
|
<literal>FOR ALL TABLES</literal> or
|
2022-09-22 19:02:25 +02:00
|
|
|
<literal>FOR TABLES IN SCHEMA</literal>, rows are always published
|
Allow specifying row filters for logical replication of tables.
This feature adds row filtering for publication tables. When a publication
is defined or modified, an optional WHERE clause can be specified. Rows
that don't satisfy this WHERE clause will be filtered out. This allows a
set of tables to be partially replicated. The row filter is per table. A
new row filter can be added simply by specifying a WHERE clause after the
table name. The WHERE clause must be enclosed by parentheses.
The row filter WHERE clause for a table added to a publication that
publishes UPDATE and/or DELETE operations must contain only columns that
are covered by REPLICA IDENTITY. The row filter WHERE clause for a table
added to a publication that publishes INSERT can use any column. If the
row filter evaluates to NULL, it is regarded as "false". The WHERE clause
only allows simple expressions that don't have user-defined functions,
user-defined operators, user-defined types, user-defined collations,
non-immutable built-in functions, or references to system columns. These
restrictions could be addressed in the future.
If you choose to do the initial table synchronization, only data that
satisfies the row filters is copied to the subscriber. If the subscription
has several publications in which a table has been published with
different WHERE clauses, rows that satisfy ANY of the expressions will be
copied. If a subscriber is a pre-15 version, the initial table
synchronization won't use row filters even if they are defined in the
publisher.
The row filters are applied before publishing the changes. If the
subscription has several publications in which the same table has been
published with different filters (for the same publish operation), those
expressions get OR'ed together so that rows satisfying any of the
expressions will be replicated.
This means all the other filters become redundant if (a) one of the
publications have no filter at all, (b) one of the publications was
created using FOR ALL TABLES, (c) one of the publications was created
using FOR ALL TABLES IN SCHEMA and the table belongs to that same schema.
If your publication contains a partitioned table, the publication
parameter publish_via_partition_root determines if it uses the partition's
row filter (if the parameter is false, the default) or the root
partitioned table's row filter.
Psql commands \dRp+ and \d <table-name> will display any row filters.
Author: Hou Zhijie, Euler Taveira, Peter Smith, Ajin Cherian
Reviewed-by: Greg Nancarrow, Haiying Tang, Amit Kapila, Tomas Vondra, Dilip Kumar, Vignesh C, Alvaro Herrera, Andres Freund, Wei Wang
Discussion: https://www.postgresql.org/message-id/flat/CAHE3wggb715X%2BmK_DitLXF25B%3DjE6xyNCH4YOwM860JR7HarGQ%40mail.gmail.com
2022-02-22 03:24:12 +01:00
|
|
|
regardless of the definition of the other expressions.
|
|
|
|
If the subscriber is a <productname>PostgreSQL</productname> version before
|
|
|
|
15 then any row filtering is ignored during the initial data synchronization
|
|
|
|
phase. For this case, the user might want to consider deleting any initially
|
|
|
|
copied data that would be incompatible with subsequent filtering.
|
2022-06-24 05:07:26 +02:00
|
|
|
Because initial data synchronization does not take into account the publication
|
|
|
|
<literal>publish</literal> parameter when copying existing table data, some rows
|
|
|
|
may be copied that would not be replicated using DML. See
|
|
|
|
<xref linkend="logical-replication-subscription-examples"/> for examples.
|
Allow specifying row filters for logical replication of tables.
This feature adds row filtering for publication tables. When a publication
is defined or modified, an optional WHERE clause can be specified. Rows
that don't satisfy this WHERE clause will be filtered out. This allows a
set of tables to be partially replicated. The row filter is per table. A
new row filter can be added simply by specifying a WHERE clause after the
table name. The WHERE clause must be enclosed by parentheses.
The row filter WHERE clause for a table added to a publication that
publishes UPDATE and/or DELETE operations must contain only columns that
are covered by REPLICA IDENTITY. The row filter WHERE clause for a table
added to a publication that publishes INSERT can use any column. If the
row filter evaluates to NULL, it is regarded as "false". The WHERE clause
only allows simple expressions that don't have user-defined functions,
user-defined operators, user-defined types, user-defined collations,
non-immutable built-in functions, or references to system columns. These
restrictions could be addressed in the future.
If you choose to do the initial table synchronization, only data that
satisfies the row filters is copied to the subscriber. If the subscription
has several publications in which a table has been published with
different WHERE clauses, rows that satisfy ANY of the expressions will be
copied. If a subscriber is a pre-15 version, the initial table
synchronization won't use row filters even if they are defined in the
publisher.
The row filters are applied before publishing the changes. If the
subscription has several publications in which the same table has been
published with different filters (for the same publish operation), those
expressions get OR'ed together so that rows satisfying any of the
expressions will be replicated.
This means all the other filters become redundant if (a) one of the
publications have no filter at all, (b) one of the publications was
created using FOR ALL TABLES, (c) one of the publications was created
using FOR ALL TABLES IN SCHEMA and the table belongs to that same schema.
If your publication contains a partitioned table, the publication
parameter publish_via_partition_root determines if it uses the partition's
row filter (if the parameter is false, the default) or the root
partitioned table's row filter.
Psql commands \dRp+ and \d <table-name> will display any row filters.
Author: Hou Zhijie, Euler Taveira, Peter Smith, Ajin Cherian
Reviewed-by: Greg Nancarrow, Haiying Tang, Amit Kapila, Tomas Vondra, Dilip Kumar, Vignesh C, Alvaro Herrera, Andres Freund, Wei Wang
Discussion: https://www.postgresql.org/message-id/flat/CAHE3wggb715X%2BmK_DitLXF25B%3DjE6xyNCH4YOwM860JR7HarGQ%40mail.gmail.com
2022-02-22 03:24:12 +01:00
|
|
|
</para>
|
|
|
|
|
2022-06-02 05:01:50 +02:00
|
|
|
<para>
|
|
|
|
Subscriptions having several publications in which the same table has been
|
|
|
|
published with different column lists are not supported.
|
|
|
|
</para>
|
|
|
|
|
2022-03-31 04:54:19 +02:00
|
|
|
<para>
|
|
|
|
We allow non-existent publications to be specified so that users can add
|
|
|
|
those later. This means
|
|
|
|
<link linkend="catalog-pg-subscription"><structname>pg_subscription</structname></link>
|
|
|
|
can have non-existent publications.
|
|
|
|
</para>
|
|
|
|
|
2022-09-08 03:24:13 +02:00
|
|
|
<para>
|
|
|
|
When using a subscription parameter combination of
|
|
|
|
<literal>copy_data = true</literal> and <literal>origin = NONE</literal>,
|
|
|
|
the initial sync table data is copied directly from the publisher, meaning
|
|
|
|
that knowledge of the true origin of that data is not possible. If the
|
|
|
|
publisher also has subscriptions then the copied table data might have
|
|
|
|
originated from further upstream. This scenario is detected and a WARNING is
|
|
|
|
logged to the user, but the warning is only an indication of a potential
|
|
|
|
problem; it is the user's responsibility to make the necessary checks to
|
|
|
|
ensure the copied data origins are really as wanted or not.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
To find which tables might potentially include non-local origins (due to
|
|
|
|
other subscriptions created on the publisher) try this SQL query:
|
|
|
|
<programlisting>
|
|
|
|
# substitute <pub-names> below with your publication name(s) to be queried
|
|
|
|
SELECT DISTINCT N.nspname AS schemaname, C.relname AS tablename
|
|
|
|
FROM pg_publication P,
|
|
|
|
LATERAL pg_get_publication_tables(P.pubname) GPT
|
|
|
|
JOIN pg_subscription_rel PS ON (GPT.relid = PS.srrelid),
|
|
|
|
pg_class C JOIN pg_namespace N ON (N.oid = C.relnamespace)
|
|
|
|
WHERE C.oid = GPT.relid AND P.pubname IN (<pub-names>);
|
|
|
|
</programlisting></para>
|
|
|
|
|
2017-02-08 03:26:50 +01:00
|
|
|
</refsect1>
|
|
|
|
|
2017-01-19 18:00:00 +01:00
|
|
|
<refsect1>
|
|
|
|
<title>Examples</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Create a subscription to a remote server that replicates tables in
|
2017-02-18 00:59:29 +01:00
|
|
|
the publications <literal>mypublication</literal> and
|
2017-01-19 18:00:00 +01:00
|
|
|
<literal>insert_only</literal> and starts replicating immediately on
|
|
|
|
commit:
|
|
|
|
<programlisting>
|
|
|
|
CREATE SUBSCRIPTION mysub
|
2017-02-08 03:26:50 +01:00
|
|
|
CONNECTION 'host=192.168.1.50 port=5432 user=foo dbname=foodb'
|
2017-01-19 18:00:00 +01:00
|
|
|
PUBLICATION mypublication, insert_only;
|
|
|
|
</programlisting>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Create a subscription to a remote server that replicates tables in
|
|
|
|
the <literal>insert_only</literal> publication and does not start replicating
|
|
|
|
until enabled at a later time.
|
|
|
|
<programlisting>
|
|
|
|
CREATE SUBSCRIPTION mysub
|
2017-02-08 03:26:50 +01:00
|
|
|
CONNECTION 'host=192.168.1.50 port=5432 user=foo dbname=foodb'
|
2017-01-19 18:00:00 +01:00
|
|
|
PUBLICATION insert_only
|
2017-05-12 14:57:01 +02:00
|
|
|
WITH (enabled = false);
|
2017-06-14 19:55:43 +02:00
|
|
|
</programlisting></para>
|
2017-01-19 18:00:00 +01:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>Compatibility</title>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
<command>CREATE SUBSCRIPTION</command> is a <productname>PostgreSQL</productname>
|
2017-01-19 18:00:00 +01:00
|
|
|
extension.
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>See Also</title>
|
|
|
|
|
|
|
|
<simplelist type="inline">
|
2017-11-23 15:39:47 +01:00
|
|
|
<member><xref linkend="sql-altersubscription"/></member>
|
|
|
|
<member><xref linkend="sql-dropsubscription"/></member>
|
|
|
|
<member><xref linkend="sql-createpublication"/></member>
|
|
|
|
<member><xref linkend="sql-alterpublication"/></member>
|
2017-01-19 18:00:00 +01:00
|
|
|
</simplelist>
|
|
|
|
</refsect1>
|
|
|
|
</refentry>
|