• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

compat10/H10-Aug-2021-12876

compat11/H10-Aug-2021-14280

compat12/H10-Aug-2021-12773

compat13/H10-Aug-2021-11969

compat14/H10-Aug-2021-11061

compat94/H10-Aug-2021-931581

compat95/H10-Aug-2021-215106

compat96/H10-Aug-2021-18382

docs/H10-Aug-2021-993728

expected/H10-Aug-2021-9,8528,674

internals-doc/H03-May-2022-860633

pglogical_dump/H06-Dec-2017-32,08421,536

sql/H10-Aug-2021-4,1462,998

t/H10-Aug-2021-813583

.gitignoreH A D10-Aug-2021210 1716

.gitmodulesH A D10-Aug-2021105 43

COPYRIGHTH A D10-Aug-20211.2 KiB2418

FAQ.mdH A D10-Aug-20212.6 KiB4937

MakefileH A D10-Aug-20219.8 KiB263170

README.mdH A D10-Aug-202141.1 KiB977713

README.tests94H A D10-Aug-2021546 1512

pglogical--1.0.0--1.0.1.sqlH A D10-Aug-2021893 2218

pglogical--1.0.0.sqlH A D10-Aug-20219.3 KiB204168

pglogical--1.0.1--1.1.0.sqlH A D10-Aug-20214.5 KiB8270

pglogical--1.1.0--1.1.1.sqlH A D10-Aug-20210 10

pglogical--1.1.1--1.1.2.sqlH A D10-Aug-20210 10

pglogical--1.1.2--1.2.0.sqlH A D10-Aug-20210 10

pglogical--1.2.0--1.2.1.sqlH A D10-Aug-202131 21

pglogical--1.2.1--1.2.2.sqlH A D10-Aug-202141 21

pglogical--1.2.2--2.0.0.sqlH A D10-Aug-20214.3 KiB9884

pglogical--2.0.0--2.0.1.sqlH A D10-Aug-20210 10

pglogical--2.0.0--2.1.0.sqlH A D10-Aug-2021153 53

pglogical--2.0.1--2.1.0.sqlH A D10-Aug-2021153 53

pglogical--2.1.0--2.1.1.sqlH A D10-Aug-2021224 43

pglogical--2.1.1--2.2.0.sqlH A D10-Aug-20210 10

pglogical--2.2.0--2.2.1.sqlH A D10-Aug-2021681 96

pglogical--2.2.0.sqlH A D10-Aug-202111.4 KiB240199

pglogical--2.2.1--2.2.2.sqlH A D10-Aug-20210 10

pglogical--2.2.1.sqlH A D10-Aug-202112.1 KiB248205

pglogical--2.2.2--2.3.0.sqlH A D10-Aug-20213 KiB5342

pglogical--2.2.2--2.3.1.sqlH A D10-Aug-2021100 21

pglogical--2.2.2.sqlH A D10-Aug-202112.1 KiB248205

pglogical--2.3.0--2.3.1.sqlH A D10-Aug-20213.9 KiB9072

pglogical--2.3.0.sqlH A D10-Aug-202112.8 KiB258214

pglogical--2.3.1--2.3.2.sqlH A D10-Aug-20210 10

pglogical--2.3.1.sqlH A D10-Aug-202112.2 KiB250207

pglogical--2.3.2--2.3.3.sqlH A D10-Aug-20210 10

pglogical--2.3.2.sqlH A D10-Aug-202112.2 KiB250207

pglogical--2.3.3--2.3.4.sqlH A D10-Aug-20210 10

pglogical--2.3.3.sqlH A D10-Aug-202112.2 KiB250207

pglogical--2.3.4--2.4.0.sqlH A D10-Aug-20210 10

pglogical--2.3.4.sqlH A D10-Aug-202112.2 KiB250207

pglogical--2.4.0.sqlH A D10-Aug-202112.2 KiB250207

pglogical.cH A D10-Aug-202122.5 KiB873618

pglogical.control.inH A D10-Aug-2021197 87

pglogical.hH A D10-Aug-20213.4 KiB11266

pglogical.suppH A D10-Aug-20219.2 KiB496448

pglogical_apply.cH A D10-Aug-202150.6 KiB1,9851,319

pglogical_apply.hH A D10-Aug-20211.2 KiB3618

pglogical_apply_heap.cH A D10-Aug-202127.3 KiB1,070784

pglogical_apply_heap.hH A D10-Aug-20211.1 KiB3618

pglogical_apply_spi.cH A D03-May-202218.3 KiB707454

pglogical_apply_spi.hH A D10-Aug-20211.2 KiB3618

pglogical_conflict.cH A D10-Aug-202123.6 KiB851528

pglogical_conflict.hH A D10-Aug-20212.4 KiB8657

pglogical_create_subscriber.cH A D10-Aug-202145.9 KiB1,7971,298

pglogical_dependency.cH A D10-Aug-202165.2 KiB2,1501,326

pglogical_dependency.hH A D10-Aug-20211.1 KiB3718

pglogical_executor.cH A D10-Aug-20218.1 KiB343243

pglogical_executor.hH A D10-Aug-2021784 279

pglogical_fe.cH A D03-May-20226.3 KiB264173

pglogical_fe.hH A D10-Aug-2021623 226

pglogical_functions.cH A D10-Aug-202162.4 KiB2,4321,673

pglogical_manager.cH A D10-Aug-20215.8 KiB255164

pglogical_monitoring.cH A D10-Aug-20212.8 KiB11671

pglogical_node.cH A D10-Aug-202124.8 KiB1,066739

pglogical_node.hH A D10-Aug-20212.2 KiB8257

pglogical_origin--1.0.0.sqlH A D10-Aug-202171 21

pglogical_origin.controlH A D10-Aug-2021218 76

pglogical_output.cH A D10-Aug-2021986 3915

pglogical_output_config.cH A D10-Aug-202116.2 KiB544382

pglogical_output_config.hH A D10-Aug-2021753 5243

pglogical_output_plugin.cH A D10-Aug-202128.5 KiB1,031647

pglogical_output_plugin.hH A D10-Aug-20212.1 KiB7641

pglogical_output_proto.cH A D10-Aug-20211.4 KiB5134

pglogical_output_proto.hH A D10-Aug-20213.5 KiB9847

pglogical_proto_json.cH A D10-Aug-202117.5 KiB703512

pglogical_proto_json.hH A D10-Aug-20211.4 KiB3921

pglogical_proto_native.cH A D10-Aug-202120.9 KiB905572

pglogical_proto_native.hH A D10-Aug-20212.5 KiB6142

pglogical_queue.cH A D10-Aug-20216.1 KiB253166

pglogical_queue.hH A D10-Aug-20211 KiB4221

pglogical_relcache.cH A D10-Aug-20216.9 KiB298195

pglogical_relcache.hH A D10-Aug-20211.5 KiB6235

pglogical_repset.cH A D10-Aug-202136.4 KiB1,4801,008

pglogical_repset.hH A D10-Aug-20213 KiB9157

pglogical_rpc.cH A D10-Aug-20219.9 KiB366261

pglogical_rpc.hH A D10-Aug-20211.1 KiB3215

pglogical_sequences.cH A D10-Aug-20218.7 KiB353239

pglogical_sync.cH A D10-Aug-202158.1 KiB2,2441,524

pglogical_sync.hH A D10-Aug-20213 KiB9763

pglogical_worker.cH A D10-Aug-202118.3 KiB740456

pglogical_worker.hH A D10-Aug-20213.1 KiB11262

regress-pg_hba.confH A D10-Aug-20214.8 KiB10312

regress-postgresql.confH A D10-Aug-2021830 3115

README.md

1# pglogical 2
2
3The pglogical 2 extension provides logical streaming replication for PostgreSQL,
4using a publish/subscribe model. It is based on technology developed as part
5of the BDR project (http://2ndquadrant.com/BDR).
6
7We use the following terms to describe data streams between nodes, deliberately
8reused from the earlier Slony technology:
9* Nodes - PostgreSQL database instances
10* Providers and Subscribers - roles taken by Nodes
11* Replication Set - a collection of tables
12
13pglogical is utilising the latest in-core features, so we have these version restrictions:
14* Provider & subscriber nodes must run PostgreSQL 9.4+
15* PostgreSQL 9.5+ is required for replication origin filtering and conflict detection
16* Additionally, subscriber can be Postgres-XL 9.5+
17
18Use cases supported are:
19* Upgrades between major versions (given the above restrictions)
20* Full database replication
21* Selective replication of sets of tables using replication sets
22* Selective replication of table rows at either publisher or subscriber side (row_filter)
23* Selective replication of table columns at publisher side
24* Data gather/merge from multiple upstream servers
25
26Architectural details:
27* pglogical works on a per-database level, not whole server level like
28  physical streaming replication
29* One Provider may feed multiple Subscribers without incurring additional disk
30  write overhead
31* One Subscriber can merge changes from several origins and detect conflict
32  between changes with automatic and configurable conflict resolution (some,
33  but not all aspects required for multi-master).
34* Cascading replication is implemented in the form of changeset forwarding.
35
36## Requirements
37
38To use pglogical the provider and subscriber must be running PostgreSQL 9.4 or newer.
39
40The `pglogical` extension must be installed on both provider and subscriber.
41You must `CREATE EXTENSION pglogical` on both.
42
43Tables on the provider and subscriber must have the same names and be in the
44same schema. Future revisions may add mapping features.
45
46Tables on the provider and subscriber must have the same columns, with the same
47data types in each column. `CHECK` constraints, `NOT NULL` constraints, etc., must
48be the same or weaker (more permissive) on the subscriber than the provider.
49
50Tables must have the same `PRIMARY KEY`s. It is not recommended to add additional
51`UNIQUE` constraints other than the `PRIMARY KEY` (see below).
52
53Some additional requirements are covered in "Limitations and Restrictions", below.
54
55## Installation
56
57### Packages
58
59pglogical is available as RPMs via yum for Fedora, CentOS, & RHEL, and as DEBs
60via apt for Debian and Ubuntu, or as source code here. Please see below for
61instructions on installing from source.
62
63#### Installing pglogical with YUM
64
65The instructions below are valid for Red Hat family of operating systems (RHEL, CentOS, Fedora).
66Pre-Requisites
67
68##### Pre-requisites
69
70These RPMs all require the PGDG PostgreSQL releases from http://yum.postgresql.org/.
71You cannot use them with stock PostgreSQL releases included in Fedora and RHEL.
72If you don’t have PostgreSQL already:
73
74 - Install the appropriate PGDG repo rpm from http://yum.postgresql.org/repopackages.php
75 - Install PostgreSQL
76    - PostgreSQL 9.4: `yum install postgresql94-server postgresql94-contrib`
77    - PostgreSQL 9.5: `yum install postgresql95-server postgresql95-contrib`
78    - PostgreSQL 9.6: `yum install postgresql96-server postgresql96-contrib`
79    - PostgreSQL 10: `yum install postgresql10-server postgresql10-contrib`
80    - PostgreSQL 11: `yum install postgresql11-server postgresql11-contrib`
81    - PostgreSQL 12: `yum install postgresql12-server postgresql12-contrib`
82    - PostgreSQL 13: `yum install postgresql13-server postgresql13-contrib`
83
84Then install the “2ndQuadrant’s General Public” repository for your PostgreSQL
85version, by running the following instructions as root on the destination Linux server:
86
87 - PostgreSQL 9.4: `curl https://access.2ndquadrant.com/api/repository/dl/default/release/9.4/rpm | bash`
88 - PostgreSQL 9.5: `curl https://access.2ndquadrant.com/api/repository/dl/default/release/9.5/rpm | bash`
89 - PostgreSQL 9.6: `curl https://access.2ndquadrant.com/api/repository/dl/default/release/9.6/rpm | bash`
90 - PostgreSQL 10: `curl https://access.2ndquadrant.com/api/repository/dl/default/release/10/rpm | bash`
91 - PostgreSQL 11: `curl https://access.2ndquadrant.com/api/repository/dl/default/release/11/rpm | bash`
92 - PostgreSQL 12: `curl https://access.2ndquadrant.com/api/repository/dl/default/release/12/rpm | bash`
93 - PostgreSQL 13: `curl https://access.2ndquadrant.com/api/repository/dl/default/release/13/rpm | bash`
94
95##### Installation
96
97Once the repository is installed, you can proceed to pglogical for your PostgreSQL version:
98
99 - PostgreSQL 9.4: `yum install postgresql94-pglogical`
100 - PostgreSQL 9.5: `yum install postgresql95-pglogical`
101 - PostgreSQL 9.6: `yum install postgresql96-pglogical`
102 - PostgreSQL 10: `yum install postgresql10-pglogical`
103 - PostgreSQL 11: `yum install postgresql11-pglogical`
104 - PostgreSQL 12: `yum install postgresql12-pglogical`
105 - PostgreSQL 13: `yum install postgresql13-pglogical`
106
107You may be prompted to accept the repository GPG key for package signing:
108
109    Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-2NDQ-DL-DEFAULT Importing GPG key 0xD6BAF0C3: Userid : "Public repository signing key 2ndQuadrant <ci@2ndquadrant.com>" Fingerprint: 8565 305c ea7d 0b66 4933 d250 9904 cd4b d6ba f0c3 From : /etc/pki/rpm-gpg/RPM-GPG-KEY-2NDQ-DL-DEFAULT Is this ok [y/N]:
110
111If so, accept the key (if it matches the above) by pressing ‘y’ then enter.
112(It’s signed by the 2ndQuadrant master packaging key, if you want to verify that.)
113
114#### Installing pglogical with APT
115
116The instructions below are valid for Debian and all Linux flavors based on
117Debian (e.g. Ubuntu).
118
119##### Pre-requisites
120
121You can install the “2ndQuadrant’s General Public” repository by running the
122following instructions as root on the destination Linux server: `curl https://access.2ndquadrant.com/api/repository/dl/default/release/deb | bash`
123
124 - Add the http://apt.postgresql.org/ repository. See the site for instructions.
125
126##### Installation
127
128Once pre-requisites are complete, installing pglogical is simply a matter of executing the following for your version of PostgreSQL:
129
130 - PostgreSQL 9.4: `sudo apt-get install postgresql-9.4-pglogical`
131 - PostgreSQL 9.5: `sudo apt-get install postgresql-9.5-pglogical`
132 - PostgreSQL 9.6: `sudo apt-get install postgresql-9.6-pglogical`
133 - PostgreSQL 10: `sudo apt-get install postgresql-10-pglogical`
134 - PostgreSQL 11: `sudo apt-get install postgresql-11-pglogical`
135 - PostgreSQL 12: `sudo apt-get install postgresql-12-pglogical`
136 - PostgreSQL 13: `sudo apt-get install postgresql-13-pglogical`
137
138### From source code
139
140Source code installs are the same as for any other PostgreSQL extension built
141using PGXS.
142
143Make sure the directory containing `pg_config` from the PostgreSQL release is
144listed in your `PATH` environment variable. You might have to install a `-dev`
145or `-devel` package for your PostgreSQL release from your package manager if
146you don't have `pg_config`.
147
148Then run `make` to compile, and `make install` to
149install. You might need to use `sudo` for the install step.
150
151e.g. for a typical Fedora or RHEL 7 install, assuming you're using the
152[yum.postgresql.org](http://yum.postgresql.org) packages for PostgreSQL:
153
154    sudo dnf install postgresql95-devel
155    PATH=/usr/pgsql-9.5/bin:$PATH make clean all
156    sudo PATH=/usr/pgsql-9.5/bin:$PATH make install
157
158## Usage
159
160This section describes basic usage of the pglogical replication extension.
161
162### Quick setup
163
164First the PostgreSQL server has to be properly configured to support logical
165decoding:
166
167    wal_level = 'logical'
168    max_worker_processes = 10   # one per database needed on provider node
169                                # one per node needed on subscriber node
170    max_replication_slots = 10  # one per node needed on provider node
171    max_wal_senders = 10        # one per node needed on provider node
172    shared_preload_libraries = 'pglogical'
173
174If you are using PostgreSQL 9.5+ (this won't work on 9.4) and want to handle
175conflict resolution with last/first update wins (see [Conflicts](#conflicts)),
176you can add this additional option to postgresql.conf:
177
178    track_commit_timestamp = on # needed for last/first update wins conflict resolution
179                                # property available in PostgreSQL 9.5+
180
181`pg_hba.conf` has to allow logical replication connections from
182localhost. Up until PostgreSQL 9.6, logical replication connections
183are managed using the `replication` keyword in `pg_hba.conf`. In
184PostgreSQL 10 and later, logical replication connections are treated
185by `pg_hba.conf` as regular connections to the provider database.
186
187Next the `pglogical` extension has to be installed on all nodes:
188
189    CREATE EXTENSION pglogical;
190
191If using PostgreSQL 9.4, then the `pglogical_origin` extension
192also has to be installed on that node:
193
194    CREATE EXTENSION pglogical_origin;
195
196Now create the provider node:
197
198    SELECT pglogical.create_node(
199        node_name := 'provider1',
200        dsn := 'host=providerhost port=5432 dbname=db'
201    );
202
203Add all tables in `public` schema to the `default` replication set.
204
205    SELECT pglogical.replication_set_add_all_tables('default', ARRAY['public']);
206
207Optionally you can also create additional replication sets and add tables to
208them (see [Replication sets](#replication-sets)).
209
210It's usually better to create replication sets before subscribing so that all
211tables are synchronized during initial replication setup in a single initial
212transaction. However, users of bigger databases may instead wish to create them
213incrementally for better control.
214
215Once the provider node is setup, subscribers can be subscribed to it. First the
216subscriber node must be created:
217
218    SELECT pglogical.create_node(
219        node_name := 'subscriber1',
220        dsn := 'host=thishost port=5432 dbname=db'
221    );
222
223And finally on the subscriber node you can create the subscription which will
224start synchronization and replication process in the background:
225
226    SELECT pglogical.create_subscription(
227        subscription_name := 'subscription1',
228        provider_dsn := 'host=providerhost port=5432 dbname=db'
229    );
230
231    SELECT pglogical.wait_for_subscription_sync_complete('subscription1');
232
233### Creating subscriber nodes with base backups
234
235In addition to the SQL-level node and subscription creation, pglogical also
236supports creating a subscriber by cloning the provider with `pg_basebackup` and
237starting it up as a pglogical subscriber. This is done with the
238`pglogical_create_subscriber` tool; see the `--help` output.
239
240Unlike `pglogical.create_subscription`'s data sync options, this clone ignores
241replication sets and copies all tables on all databases. However, it's often
242much faster, especially over high-bandwidth links.
243
244### Node management
245
246Nodes can be added and removed dynamically using the SQL interfaces.
247
248- `pglogical.create_node(node_name name, dsn text)`
249  Creates a node.
250
251  Parameters:
252  - `node_name` - name of the new node, only one node is allowed per database
253  - `dsn` - connection string to the node, for nodes that are supposed to be
254    providers, this should be reachable from outside
255
256- `pglogical.drop_node(node_name name, ifexists bool)`
257  Drops the pglogical node.
258
259  Parameters:
260  - `node_name` - name of an existing node
261  - `ifexists` - if true, error is not thrown when subscription does not exist,
262    default is false
263
264- `pglogical.alter_node_add_interface(node_name name, interface_name name, dsn text)`
265  Adds additional interface to a node.
266
267  When node is created, the interface for it is also created with the `dsn`
268  specified in the `create_node` and with the same name as the node. This
269  interface allows adding alternative interfaces with different connection
270  strings to an existing node.
271
272  Parameters:
273  - `node_name` - name of an existing node
274  - `interface_name` - name of a new interface to be added
275  - `dsn` - connection string to the node used for the new interface
276
277- `pglogical.alter_node_drop_interface(node_name name, interface_name name)`
278  Remove existing interface from a node.
279
280  Parameters:
281  - `node_name` - name of and existing node
282  - `interface_name` - name of an existing interface
283
284### Subscription management
285
286- `pglogical.create_subscription(subscription_name name, provider_dsn text,
287  replication_sets text[], synchronize_structure boolean,
288  synchronize_data boolean, forward_origins text[], apply_delay interval)`
289  Creates a subscription from current node to the provider node. Command does
290  not block, just initiates the action.
291
292  Parameters:
293  - `subscription_name` - name of the subscription, must be unique
294  - `provider_dsn` - connection string to a provider
295  - `replication_sets` - array of replication sets to subscribe to, these must
296    already exist, default is "{default,default_insert_only,ddl_sql}"
297  - `synchronize_structure` - specifies if to synchronize structure from
298    provider to the subscriber, default false
299  - `synchronize_data` - specifies if to synchronize data from provider to
300    the subscriber, default true
301  - `forward_origins` - array of origin names to forward, currently only
302    supported values are empty array meaning don't forward any changes
303    that didn't originate on provider node (this is useful for two-way
304    replication between the nodes), or "{all}" which means replicate all
305    changes no matter what is their origin, default is "{all}"
306  - `apply_delay` - how much to delay replication, default is 0 seconds
307  - `force_text_transfer` - force the provider to replicate all columns
308    using a text representation (which is slower, but may be used to
309    change the type of a replicated column on the subscriber), default
310    is false
311
312  The `subscription_name` is used as `application_name` by the replication
313  connection. This means that it's visible in the `pg_stat_replication`
314  monitoring view. It can also be used in `synchronous_standby_names` when
315  pglogical is used as part of
316  [synchronous replication](#synchronous-replication) setup.
317
318  Use `pglogical.wait_for_subscription_sync_complete(sub_name)` to wait for the
319  subscription to asynchronously start replicating and complete any needed
320  schema and/or data sync.
321
322- `pglogical.drop_subscription(subscription_name name, ifexists bool)`
323  Disconnects the subscription and removes it from the catalog.
324
325  Parameters:
326  - `subscription_name` - name of the existing subscription
327  - `ifexists` - if true, error is not thrown when subscription does not exist,
328    default is false
329
330- `pglogical.alter_subscription_disable(subscription_name name, immediate bool)`
331   Disables a subscription and disconnects it from the provider.
332
333  Parameters:
334  - `subscription_name` - name of the existing subscription
335  - `immediate` - if true, the subscription is stopped immediately, otherwise
336    it will be only stopped at the end of current transaction, default is false
337
338- `pglogical.alter_subscription_enable(subscription_name name, immediate bool)`
339  Enables disabled subscription.
340
341  Parameters:
342  - `subscription_name` - name of the existing subscription
343  - `immediate` - if true, the subscription is started immediately, otherwise
344    it will be only started at the end of current transaction, default is false
345
346- `pglogical.alter_subscription_interface(subscription_name name, interface_name name)`
347  Switch the subscription to use different interface to connect to provider
348  node.
349
350  Parameters:
351  - `subscription_name` - name of an existing subscription
352  - `interface_name` - name of an existing interface of the current provider
353    node
354
355- `pglogical.alter_subscription_synchronize(subscription_name name, truncate bool)`
356  All unsynchronized tables in all sets are synchronized in a single operation.
357  Tables are copied and synchronized one by one. Command does not block, just
358  initiates the action. Use `pglogical.wait_for_subscription_sync_complete`
359  to wait for completion.
360
361  Parameters:
362  - `subscription_name` - name of the existing subscription
363  - `truncate` - if true, tables will be truncated before copy, default false
364
365- `pglogical.alter_subscription_resynchronize_table(subscription_name name,
366  relation regclass)`
367  Resynchronize one existing table. The table may not be the target of any
368  foreign key constraints.
369  **WARNING: This function will truncate the table immediately, and only then
370  begin synchronising it, so it will be empty while being synced**
371
372  Does not block, use `pglogical.wait_for_table_sync_complete` to wait for
373  completion.
374
375  Parameters:
376  - `subscription_name` - name of the existing subscription
377  - `relation` - name of existing table, optionally qualified
378
379- `pglogical.wait_for_subscription_sync_complete(subscription_name name)`
380
381   Wait for a subscription or to finish synchronization after a
382   `pglogical.create_subscription` or `pglogical.alter_subscription_synchronize`.
383
384  This function waits until the subscription's initial schema/data sync,
385  if any, are done, and until any tables pending individual resynchronisation
386  have also finished synchronising.
387
388  For best results, run `SELECT pglogical.wait_slot_confirm_lsn(NULL, NULL)` on the
389  provider after any replication set changes that requested resyncs, and only
390  then call `pglogical.wait_for_subscription_sync_complete` on the subscriber.
391
392- `pglogical.wait_for_table_sync_complete(subscription_name name, relation regclass)`
393
394  Same as `pglogical.wait_for_subscription_sync_complete`, but waits only for
395  the subscription's initial sync and the named table. Other tables pending
396  resynchronisation are ignored.
397
398- `pglogical.wait_slot_confirm_lsn`
399
400  `SELECT pglogical.wait_slot_confirm_lsn(NULL, NULL)`
401
402  Wait until all replication slots on the current node have replayed up to the
403  xlog insert position at time of call on all providers. Returns when
404  all slots' `confirmed_flush_lsn` passes the `pg_current_wal_insert_lsn()` at
405  time of call.
406
407  Optionally may wait for only one replication slot (first argument).
408  Optionally may wait for an arbitrary LSN passed instead of the insert lsn
409  (second argument). Both are usually just left null.
410
411  This function is very useful to ensure all subscribers have received changes
412  up to a certain point on the provider.
413
414- `pglogical.show_subscription_status(subscription_name name)`
415  Shows status and basic information about subscription.
416
417  Parameters:
418  - `subscription_name` - optional name of the existing subscription, when no
419    name was provided, the function will show status for all subscriptions on
420    local node
421
422- `pglogical.show_subscription_table(subscription_name name,
423  relation regclass)`
424  Shows synchronization status of a table.
425
426  Parameters:
427  - `subscription_name` - name of the existing subscription
428  - `relation` - name of existing table, optionally qualified
429
430- `pglogical.alter_subscription_add_replication_set(subscription_name name,
431  replication_set name)`
432  Adds one replication set into a subscriber. Does not synchronize, only
433  activates consumption of events.
434
435  Parameters:
436  - `subscription_name` - name of the existing subscription
437  - `replication_set` - name of replication set to add
438
439- `pglogical.alter_subscription_remove_replication_set(subscription_name name,
440  replication_set name)`
441  Removes one replication set from a subscriber.
442
443  Parameters:
444  - `subscription_name` - name of the existing subscription
445  - `replication_set` - name of replication set to remove
446
447
448There is also a `postgresql.conf` parameter,
449`pglogical.extra_connection_options`, that may be set to assign connection
450options that apply to all connections made by pglogical. This can be a useful
451place to set up custom keepalive options, etc.
452
453pglogical defaults to enabling TCP keepalives to ensure that it notices
454when the upstream server disappears unexpectedly. To disable them add
455`keepalives = 0` to `pglogical.extra_connection_options`.
456
457### Replication sets
458
459Replication sets provide a mechanism to control which tables in the database
460will be replicated and which actions on those tables will be replicated.
461
462Each replicated set can specify individually if `INSERTs`, `UPDATEs`,
463`DELETEs` and `TRUNCATEs` on the set are replicated. Every table can be in
464multiple replication sets and every subscriber can subscribe to multiple
465replication sets as well. The resulting set of tables and actions replicated
466is the union of the sets the table is in. The tables are not replicated until
467they are added into a replication set.
468
469There are three preexisting replication sets named "default",
470"default_insert_only" and "ddl_sql". The "default" replication set is defined
471to replicate all changes to tables in it. The "default_insert_only" only
472replicates INSERTs and is meant for tables that don't have primary key (see
473[Limitations](#primary-key-required) section for details).
474The "ddl_sql" replication set is defined to replicate schema changes specified by
475`pglogical.replicate_ddl_command`
476
477The following functions are provided for managing the replication sets:
478
479- `pglogical.create_replication_set(set_name name, replicate_insert bool, replicate_update bool, replicate_delete bool, replicate_truncate bool)`
480  This function creates a new replication set.
481
482  Parameters:
483  - `set_name` - name of the set, must be unique
484  - `replicate_insert` - specifies if `INSERT` is replicated, default true
485  - `replicate_update` - specifies if `UPDATE` is replicated, default true
486  - `replicate_delete` - specifies if `DELETE` is replicated, default true
487  - `replicate_truncate` - specifies if `TRUNCATE` is replicated, default true
488
489- `pglogical.alter_replication_set(set_name name, replicate_inserts bool, replicate_updates bool, replicate_deletes bool, replicate_truncate bool)`
490  This function changes the parameters of the existing replication set.
491
492  Parameters:
493  - `set_name` - name of the existing replication set
494  - `replicate_insert` - specifies if `INSERT` is replicated, default true
495  - `replicate_update` - specifies if `UPDATE` is replicated, default true
496  - `replicate_delete` - specifies if `DELETE` is replicated, default true
497  - `replicate_truncate` - specifies if `TRUNCATE` is replicated, default true
498
499- `pglogical.drop_replication_set(set_name text)`
500  Removes the replication set.
501
502  Parameters:
503  - `set_name` - name of the existing replication set
504
505- `pglogical.replication_set_add_table(set_name name, relation regclass, synchronize_data boolean, columns text[], row_filter text)`
506  Adds a table to replication set.
507
508  Parameters:
509  - `set_name` - name of the existing replication set
510  - `relation` - name or OID of the table to be added to the set
511  - `synchronize_data` - if true, the table data is synchronized on all
512    subscribers which are subscribed to given replication set, default false
513  - `columns` - list of columns to replicate. Normally when all columns
514    should be replicated, this will be set to NULL which is the
515    default
516  - `row_filter` - row filtering expression, default NULL (no filtering),
517    see [Row Filtering](#row-filtering) for more info.
518  **WARNING: Use caution when synchronizing data with a valid row filter.**
519Using `synchronize_data=true` with a valid `row_filter` is like a one-time operation for a table.
520Executing it again with modified `row_filter` won't synchronize data to subscriber. Subscribers
521may need to call `pglogical.alter_subscription_resynchronize_table()` to fix it.
522
523- `pglogical.replication_set_add_all_tables(set_name name, schema_names text[], synchronize_data boolean)`
524  Adds all tables in given schemas. Only existing tables are added, table that
525  will be created in future will not be added automatically. For how to ensure
526  that tables created in future are added to correct replication set, see
527  [Automatic assignment of replication sets for new tables](#automatic-assignment-of-replication-sets-for-new-tables).
528
529  Parameters:
530  - `set_name` - name of the existing replication set
531  - `schema_names` - array of names name of existing schemas from which tables
532    should be added
533  - `synchronize_data` - if true, the table data is synchronized on all
534    subscribers which are subscribed to given replication set, default false
535
536- `pglogical.replication_set_remove_table(set_name name, relation regclass)`
537  Remove a table from replication set.
538
539  Parameters:
540  - `set_name` - name of the existing replication set
541  - `relation` - name or OID of the table to be removed from the set
542
543- `pglogical.replication_set_add_sequence(set_name name, relation regclass, synchronize_data boolean)`
544  Adds a sequence to a replication set.
545
546  Parameters:
547  - `set_name` - name of the existing replication set
548  - `relation` - name or OID of the sequence to be added to the set
549  - `synchronize_data` - if true, the sequence value will be synchronized immediately, default false
550
551- `pglogical.replication_set_add_all_sequences(set_name name, schema_names text[], synchronize_data boolean)`
552  Adds all sequences from the given schemas. Only existing sequences are added, any sequences that
553  will be created in future will not be added automatically.
554
555  Parameters:
556  - `set_name` - name of the existing replication set
557  - `schema_names` - array of names name of existing schemas from which tables
558    should be added
559  - `synchronize_data` - if true, the sequence value will be synchronized immediately, default false
560
561- `pglogical.replication_set_remove_sequence(set_name name, relation regclass)`
562  Remove a sequence from a replication set.
563
564  Parameters:
565  - `set_name` - name of the existing replication set
566  - `relation` - name or OID of the sequence to be removed from the set
567
568You can view the information about which table is in which set by querying the
569`pglogical.tables` view.
570
571#### Automatic assignment of replication sets for new tables
572
573The event trigger facility can be used for describing rules which define
574replication sets for newly created tables.
575
576Example:
577
578    CREATE OR REPLACE FUNCTION pglogical_assign_repset()
579    RETURNS event_trigger AS $$
580    DECLARE obj record;
581    BEGIN
582        FOR obj IN SELECT * FROM pg_event_trigger_ddl_commands()
583        LOOP
584            IF obj.object_type = 'table' THEN
585                IF obj.schema_name = 'config' THEN
586                    PERFORM pglogical.replication_set_add_table('configuration', obj.objid);
587                ELSIF NOT obj.in_extension THEN
588                    PERFORM pglogical.replication_set_add_table('default', obj.objid);
589                END IF;
590            END IF;
591        END LOOP;
592    END;
593    $$ LANGUAGE plpgsql;
594
595    CREATE EVENT TRIGGER pglogical_assign_repset_trg
596        ON ddl_command_end
597        WHEN TAG IN ('CREATE TABLE', 'CREATE TABLE AS')
598        EXECUTE PROCEDURE pglogical_assign_repset();
599
600The above example will put all new tables created in schema `config` into
601replication set `configuration` and all other new tables which are not created
602by extensions will go to `default` replication set.
603
604### Additional functions
605
606- `pglogical.replicate_ddl_command(command text, replication_sets text[])`
607  Execute locally and then send the specified command to the replication queue
608  for execution on subscribers which are subscribed to one of the specified
609  `replication_sets`.
610
611  Parameters:
612  - `command` - DDL query to execute
613  - `replication_sets` - array of replication sets which this command should be
614    associated with, default "{ddl_sql}"
615
616- `pglogical.synchronize_sequence(relation regclass)`
617  Push sequence state to all subscribers. Unlike the subscription and table
618  synchronization function, this function should be run on provider. It forces
619  update of the tracked sequence state which will be consumed by all
620  subscribers (replication set filtering still applies) once they replicate the
621  transaction in which this function has been executed.
622
623  Parameters:
624  - `relation` - name of existing sequence, optionally qualified
625
626### Row Filtering
627
628PGLogical allows row based filtering both on provider side and the subscriber
629side.
630
631#### Row Filtering on Provider
632
633On the provider the row filtering can be done by specifying `row_filter`
634parameter for the `pglogical.replication_set_add_table` function. The
635`row_filter` is normal PostgreSQL expression which has the same limitations
636on what's allowed as the `CHECK` constraint.
637
638Simple `row_filter` would look something like `row_filter := 'id > 0'` which
639would ensure that only rows where values of `id` column is bigger than zero
640will be replicated.
641
642It's allowed to use volatile function inside `row_filter` but caution must
643be exercised with regard to writes as any expression which will do writes
644will throw error and stop replication.
645
646It's also worth noting that the `row_filter` is running inside the replication
647session so session specific expressions such as `CURRENT_USER` will have
648values of the replication session and not the session which did the writes.
649
650#### Row Filtering on Subscriber
651
652On the subscriber the row based filtering can be implemented using standard
653`BEFORE TRIGGER` mechanism.
654
655It is required to mark any such triggers as either `ENABLE REPLICA` or
656`ENABLE ALWAYS` otherwise they will not be executed by the replication
657process.
658
659## Synchronous Replication
660
661Synchronous replication is supported using same standard mechanism provided
662by PostgreSQL for physical replication.
663
664The `synchronous_commit` and `synchronous_standby_names` settings will affect
665when `COMMIT` command reports success to client if pglogical subscription
666name is used in `synchronous_standby_names`. Refer to PostgreSQL
667documentation for more info about how to configure these two variables.
668
669## Conflicts
670
671In case the node is subscribed to multiple providers, or when local writes
672happen on a subscriber, conflicts can arise for the incoming changes. These
673are automatically detected and can be acted on depending on the configuration.
674
675The configuration of the conflicts resolver is done via the
676`pglogical.conflict_resolution` setting.
677
678The resolved conflicts are logged using the log level set using
679`pglogical.conflict_log_level`. This parameter defaults to `LOG`. If set to
680lower level than `log_min_messages` the resolved conflicts won't appear in
681the server log.
682
683## Configuration options
684
685Some aspects of PGLogical can be configured using configuration options that
686can be either set in `postgresql.conf` or via `ALTER SYSTEM SET`.
687
688- `pglogical.conflict_resolution`
689  Sets the resolution method for any detected conflicts between local data
690  and incoming changes.
691
692  Possible values:
693  - `error` - the replication will stop on error if conflict is detected and
694    manual action is needed for resolving
695  - `apply_remote` - always apply the change that's conflicting with local
696    data
697  - `keep_local` - keep the local version of the data and ignore the
698     conflicting change that is coming from the remote node
699  - `last_update_wins` - the version of data with newest commit timestamp
700     will be kept (this can be either local or remote version)
701  - `first_update_wins` - the version of the data with oldest timestamp will
702     be kept (this can be either local or remote version)
703
704  The available settings and defaults depend on version of PostgreSQL and
705  other settings.
706
707  The default value in PostgreSQL is `apply_remote`.
708
709  The `keep_local`, `last_update_wins` and `first_update_wins` settings
710  require `track_commit_timestamp` PostgreSQL setting to be enabled. As
711  `track_commit_timestamp` is not available in PostgreSQL 9.4
712  `pglogical.conflict_resolution` can only be `apply_remote` or `error`.
713
714  In Postgres-XL, the only supported value and the default is `error`.
715
716- `pglogical.conflict_log_level`
717  Sets the log level for reporting detected conflicts when the
718  `pglogical.conflict_resolution` is set to anything else than `error`.
719
720  Main use for this setting is to suppress logging of conflicts.
721
722  Possible values are same as for `log_min_messages` PostgreSQL setting.
723
724  The default is `LOG`.
725
726- `pglogical.batch_inserts`
727  Tells PGLogical to use batch insert mechanism if possible. Batch mechanism
728  uses PostgreSQL internal batch insert mode which is also used by `COPY`
729  command.
730
731  The batch inserts will improve replication performance of transactions that
732  did many inserts into one table. PGLogical will switch to batch mode when
733  transaction did more than 5 INSERTs.
734
735  It's only possible to switch to batch mode when there are no
736  `INSTEAD OF INSERT` and `BEFORE INSERT` triggers on the table and when
737  there are no defaults with volatile expressions for columns of the table.
738  Also the batch mode will only work when `pglogical.conflict_resolution` is
739  set to `error`.
740
741  The default is `true`.
742
743- `pglogical.use_spi`
744  Tells PGLogical to use SPI interface to form actual SQL
745  (`INSERT`, `UPDATE`, `DELETE`) statements to apply incoming changes instead
746  of using internal low level interface.
747
748  This is mainly useful for Postgres-XL and debugging purposes.
749
750  The default in PostgreSQL is `false`.
751
752  This can be set to `true` only when `pglogical.conflict_resolution` is set to `error`.
753In this state, conflicts are not detected.
754
755  In Postgres-XL the default and only allowed setting is `true`.
756
757- `pglogical.temp_directory`
758  Defines system path where to put temporary files needed for schema
759  synchronization. This path need to exist and be writable by user running
760  Postgres.
761
762  Default is empty, which tells PGLogical to use default temporary directory
763  based on environment and operating system settings.
764
765## Limitations and restrictions
766
767### Superuser is required
768
769Currently pglogical replication and administration requires superuser
770privileges. It may be later extended to more granular privileges.
771
772### `UNLOGGED` and `TEMPORARY` not replicated
773
774`UNLOGGED` and `TEMPORARY` tables will not and cannot be replicated, much like
775with physical streaming replication.
776
777### One database at a time
778
779To replicate multiple databases you must set up individual provider/subscriber
780relationships for each. There is no way to configure replication for all databases
781in a PostgreSQL install at once.
782
783### PRIMARY KEY or REPLICA IDENTITY required
784
785`UPDATE`s and `DELETE`s cannot be replicated for tables that lack a `PRIMARY
786KEY` or other valid replica identity such as using an index, which must be unique,
787not partial, not deferrable, and include only columns marked NOT NULL.
788Replication has no way to find the tuple that should be updated/deleted since
789there is no unique identifier.
790`REPLICA IDENTITY FULL` is not supported yet.
791
792
793### Only one unique index/constraint/PK
794
795If more than one upstream is configured or the downstream accepts local writes
796then only one `UNIQUE` index should be present on downstream replicated tables.
797Conflict resolution can only use one index at a time so conflicting rows may
798`ERROR` if a row satisfies the `PRIMARY KEY` but violates a `UNIQUE` constraint
799on the downstream side. This will stop replication until the downstream table
800is modified to remove the violation.
801
802It's fine to have extra unique constraints on an upstream if the downstream only
803gets writes from that upstream and nowhere else. The rule is that the downstream
804constraints must *not be more restrictive* than those on the upstream(s).
805
806Partial secondary unique indexes are permitted, but will be ignored for
807conflict resolution purposes.
808
809### Unique constraints must not be deferrable
810
811On the downstream end pglogical does not support index-based constraints
812defined as `DEFERRABLE`. It will emit the error
813
814    ERROR: pglogical doesn't support index rechecks needed for deferrable indexes
815    DETAIL: relation "public"."test_relation" has deferrable indexes: "index1", "index2"
816
817if such an index is present when it attempts to apply changes to a table.
818
819### DDL
820
821Automatic DDL replication is not supported. Managing DDL so that the provider and
822subscriber database(s) remain compatible is the responsibility of the user.
823
824pglogical provides the `pglogical.replicate_ddl_command` function to allow DDL
825to be run on the provider and subscriber at a consistent point.
826
827### No replication queue flush
828
829There's no support for freezing transactions on the master and waiting until
830all pending queued xacts are replayed from slots. Support for making the
831upstream read-only for this will be added in a future release.
832
833This means that care must be taken when applying table structure changes. If
834there are committed transactions that aren't yet replicated and the table
835structure of the provider and subscriber are changed at the same time in a way
836that makes the subscriber table incompatible with the queued transactions
837replication will stop.
838
839Administrators should either ensure that writes to the master are stopped
840before making schema changes, or use the `pglogical.replicate_ddl_command`
841function to queue schema changes so they're replayed at a consistent point
842on the replica.
843
844Once multi-master replication support is added then using
845`pglogical.replicate_ddl_command` will not be enough, as the subscriber may be
846generating new xacts with the old structure after the schema change is
847committed on the publisher. Users will have to ensure writes are stopped on all
848nodes and all slots are caught up before making schema changes.
849
850### FOREIGN KEYS
851
852Foreign keys constraints are not enforced for the replication process - what
853succeeds on provider side gets applied to subscriber even if the `FOREIGN KEY`
854would be violated.
855
856### TRUNCATE
857
858Using `TRUNCATE ... CASCADE` will only apply the `CASCADE` option on the
859provider side.
860
861(Properly handling this would probably require the addition of `ON TRUNCATE CASCADE`
862support for foreign keys in PostgreSQL).
863
864`TRUNCATE ... RESTART IDENTITY` is not supported. The identity restart step is
865not replicated to the replica.
866
867### Sequences
868
869The state of sequences added to replication sets is replicated periodically
870and not in real-time. Dynamic buffer is used for the value being replicated so
871that the subscribers actually receive future state of the sequence. This
872minimizes the chance of subscriber's notion of sequence's `last_value` falling
873behind but does not completely eliminate the possibility.
874
875It might be desirable to call `synchronize_sequence` to ensure all subscribers
876have up to date information about given sequence after "big events" in the
877database such as data loading or during the online upgrade.
878
879It's generally recommended to use `bigserial` and `bigint` types for sequences
880on multi-node systems as smaller sequences might reach end of the sequence
881space fast.
882
883Users who want to have independent sequences on provider and subscriber can
884avoid adding sequences to replication sets and create sequences with step
885interval equal to or greater than the number of nodes. And then setting a
886different offset on each node. Use the `INCREMENT BY` option for
887`CREATE SEQUENCE` or `ALTER SEQUENCE`, and use `setval(...)` to set the start
888point.
889
890### Triggers
891
892Apply process and the initial COPY process both run with
893`session_replication_role` set to `replica` which means that `ENABLE REPLICA`
894and `ENABLE ALWAYS` triggers will be fired.
895
896### PostgreSQL Version differences
897
898PGLogical can replicate across PostgreSQL major versions. Despite that, long
899term cross-version replication is not considered a design target, though it may
900often work. Issues where changes are valid on the provider but not on the
901subscriber are more likely to arise when replicating across versions.
902
903It is safer to replicate from an old version to a newer version since PostgreSQL
904maintains solid backward compatibility but only limited forward compatibility.
905Initial schema synchronization is only supported when replicating between same
906version of PostgreSQL or from lower version to higher version.
907
908Replicating between different minor versions makes no difference at all.
909
910### Database encoding differences
911
912PGLogical does not support replication between databases with different
913encoding. We recommend using `UTF-8` encoding in all replicated databases.
914
915### Large objects
916
917PostgreSQL's logical decoding facility does not support decoding changes
918to large objects, so pglogical cannot replicate large objects.
919
920### Postgres-XL
921
922Minimum supported version of Postgres-XL is 9.5r1.5.
923
924Postgres-XL is only supported as subscriber (cannot be a provider). For
925workloads with many small transactions the performance of replication may
926suffer due to increased write latency. On the other hand large insert
927(or bulkcopy) transactions are heavily optimized to work very fast with
928Postgres-XL.
929
930Also any DDL limitations apply so extra care need to be taken when using
931`replicate_ddl_command()`.
932
933Postgres-XL changes defaults and available settings for
934`pglogical.conflict_resolution` and `pglogical.use_spi` configuration options.
935
936## Appendix A: Credits and License
937
938pglogical has been designed, developed and tested by the 2ndQuadrant team
939* Petr Jelinek
940* Craig Ringer
941* Simon Riggs
942* Pallavi Sontakke
943* Umair Shahid
944
945pglogical license is The PostgreSQL License
946
947pglogical copyright is donated to PostgreSQL Global Development Group
948
949## Appendix B: Release Notes
950
951Version 2.4.0 is a maintenance release of pglogical 2.
952
953### Changes
954
955* Add preliminary support for PostgreSQL 14 (beta)
956
957* Fix pglogical_show_subscription_table to return row rather than set of rows
958
959* Fix snapshot handling in output plugin and apply worker
960
961* Fix command quoting on Windows so that it actually works
962  Seems like the API used before has 1024 limit on command line length
963
964* Make sure that the schema syncing process can be interrupted on Windows
965
966* Fix compilation issues with pglogical_create_subscriber on Windows
967
968* Fix double closing of relation when a BEFORE ROW DELETE trigger returns NULL
969  in the apply worker
970
971* Fix multi-insert crash in the SPI apply worker
972
973* Fix multi-insert doing insert of last tuple multiple times in apply worker
974
975* Make sure debug_query_string is always set
976  Newer versions of PostgreSQL require that debug_query_string is always set.
977

README.tests94

1On 9.4 you can't run 'make check' since we don't have any way to make a temp
2instance using PGXS. So you'll need to roll a 9.4 install yourself, with
3something like:
4
5export PATH=$HOME/pg/94/bin:$PATH
6export PGUSER=postgres
7
8[ -e 94test ] && pg_ctl -D 94test -m immediate -w stop
9rm -rf 94test
10initdb -D 94test -U postgres -A trust
11grep -v '^track_commit_timestamp' regress-postgresql.conf >> 94test/postgresql.conf
12cp regress-pg_hba.conf 94test/
13PGPORT=5495 pg_ctl -D 94test -w -l 94test.log start
14PGPORT=5495 make -s clean install installcheck
15