Movatterモバイル変換


[0]ホーム

URL:



Facebook
Postgres Pro
Facebook
Downloads
CREATE SUBSCRIPTION
Prev UpSQL CommandsHome Next

CREATE SUBSCRIPTION

CREATE SUBSCRIPTION — define a new subscription

Synopsis

CREATE SUBSCRIPTIONsubscription_name    CONNECTION 'conninfo'    PUBLICATIONpublication_name [, ...]    [ WITH (subscription_parameter [=value] [, ... ] ) ]

Description

CREATE SUBSCRIPTION adds a new subscription for the current database. The subscription name must be distinct from the name of any existing subscription in the database.

The subscription represents a replication connection to the publisher. As such this command does not only add definitions in the local catalogs but also creates a replication slot on the publisher.

A logical replication worker will be started to replicate data for the new subscription at the commit of the transaction where this command is run.

Additional information about subscriptions and logical replication as a whole is available atSection 31.2 andChapter 31.

Parameters

subscription_name

The name of the new subscription.

CONNECTION 'conninfo'

The connection string to the publisher. For details seeSection 33.1.1.

PUBLICATIONpublication_name

Names of the publications on the publisher to subscribe to.

WITH (subscription_parameter [=value] [, ... ] )

This clause specifies optional parameters for a subscription. The following parameters are supported:

copy_data (boolean)

Specifies whether the existing data in the publications that are being subscribed to should be copied once the replication starts. The default istrue.

create_slot (boolean)

Specifies whether the command should create the replication slot on the publisher. The default istrue.

enabled (boolean)

Specifies whether the subscription should be actively replicating, or whether it should be just setup but not started yet. The default istrue.

slot_name (string)

Name of the replication slot to use. The default behavior is to use the name of the subscription for the slot name.

Whenslot_name is set toNONE, there will be no replication slot associated with the subscription. This can be used if the replication slot will be created later manually. Such subscriptions must also have bothenabled andcreate_slot set tofalse.

synchronous_commit (enum)

The value of this parameter overrides thesynchronous_commit setting. The default value isoff.

It is safe to useoff for logical replication: If the subscriber loses transactions because of missing synchronization, the data will be sent again from the publisher.

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 settingsynchronous_commit for the subscriber tooff when the subscription is used for synchronous replication might increase the latency forCOMMIT on the publisher. In this scenario, it can be advantageous to setsynchronous_commit tolocal or higher.

connect (boolean)

Specifies whether theCREATE SUBSCRIPTION should connect to the publisher at all. Setting this tofalse will change default values ofenabled,create_slot andcopy_data tofalse.

It is not allowed to combineconnect set tofalse andenabled,create_slot, orcopy_data set totrue.

Since no connection is made when this option is set tofalse, the tables are not subscribed, and so after you enable the subscription nothing will be replicated. It is required to runALTER SUBSCRIPTION ... REFRESH PUBLICATION in order for tables to be subscribed.

Notes

SeeSection 31.7 for details on how to configure access control between the subscription and the publication instance.

When creating a replication slot (the default behavior),CREATE SUBSCRIPTION cannot be executed inside a transaction block.

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, theCREATE SUBSCRIPTION call will hang. To make this work, create the replication slot separately (using the functionpg_create_logical_replication_slot with the plugin namepgoutput) and create the subscription using the parametercreate_slot = false. This is an implementation restriction that might be lifted in a future release.

Examples

Create a subscription to a remote server that replicates tables in the publicationsmypublication andinsert_only and starts replicating immediately on commit:

CREATE SUBSCRIPTION mysub         CONNECTION 'host=192.168.1.50 port=5432 user=foo dbname=foodb'        PUBLICATION mypublication, insert_only;

Create a subscription to a remote server that replicates tables in theinsert_only publication and does not start replicating until enabled at a later time.

CREATE SUBSCRIPTION mysub         CONNECTION 'host=192.168.1.50 port=5432 user=foo dbname=foodb'        PUBLICATION insert_only               WITH (enabled = false);

Compatibility

CREATE SUBSCRIPTION is aPostgreSQL extension.


Prev Up Next
CREATE STATISTICS Home CREATE TABLE
epubpdf
Go to PostgreSQL 10
By continuing to browse this website, you agree to the use of cookies. Go toPrivacy Policy.

[8]ページ先頭

©2009-2025 Movatter.jp