@@ -81,21 +81,29 @@ Now create the provider node:
81
81
dsn := 'host=providerhost port=5432 dbname=db'
82
82
);
83
83
84
- Optionally you can also create replication sets and add tables to them (see
85
- [ Replication sets] ( #replication-sets ) ). It's usually better to create replication sets beforehand.
84
+ Add all tables in ` public ` schema to the ` default ` replication set.
86
85
87
- Once the provider node is setup, subscribers can be subscribed to it:
86
+ SELECT pglogical.replication_set_add_all_tables('default', ARRAY['public']);
87
+
88
+ Optionally you can also create additional replication sets and add tables to
89
+ them (see [ Replication sets] ( #replication-sets ) ). It's usually better to create
90
+ replication sets beforehand.
91
+
92
+ Once the provider node is setup, subscribers can be subscribed to it. First the
93
+ subscriber node must be created:
88
94
89
95
SELECT pglogical.create_node(
90
96
node_name := 'subscriber1',
91
97
dsn := 'host=thishost port=5432 dbname=db'
92
98
);
93
99
100
+ And finally on the subscriber node you can create the subscription which will
101
+ start synchronization and replication process in the background:
102
+
94
103
SELECT pglogical.create_subscription(
95
104
subscription_name := 'subscription1',
96
105
provider_dsn := 'host=providerhost port=5432 dbname=db'
97
106
);
98
- (run this on the subscriber node)
99
107
100
108
### Node management
101
109
@@ -223,11 +231,14 @@ Each replicated set can specify individually if `INSERTs`, `UPDATEs`,
223
231
` DELETEs ` and ` TRUNCATEs ` on the set are replicated. Every table can be in
224
232
multiple replication sets and every subscriber can subscribe to multiple
225
233
replication sets as well. The resulting set of tables and actions replicated
226
- is the union of the sets the table is in.
234
+ is the union of the sets the table is in. The tables are not replicated until
235
+ they are added into a replication set.
227
236
228
- There are two preexisting replication sets named "all" and "default". The "all"
229
- replication set contains every user table in the database and every table that
230
- has not been added to specific replication set will be in the "default" set.
237
+ There are two preexisting replication sets named "default" and
238
+ "default_insert_only". The "default" replication set is defined to replicate
239
+ all changes to tables in in. The "default_insert_only" only replicates INSERTs
240
+ and is meant for tables that don't have primary key (see
241
+ [ Limitations] ( #primary-key-or-replica-identity-required ) section for details).
231
242
232
243
The following functions are provided for managing the replication sets:
233
244
@@ -266,6 +277,19 @@ The following functions are provided for managing the replication sets:
266
277
- ` synchronize ` - if true, the table data is synchronized on all subscribers
267
278
which are subscribed to given replication set, default false
268
279
280
+ - ` pglogical.replication_set_add_all_tables(set_name name, schema_names text[], synchronize boolean) `
281
+ Adds all tables in given schemas. Only existing tables are added, table that
282
+ will be created in future will not be added automatically. For how to ensure
283
+ that tables created in future are added to correct replication set, see
284
+ [ Automatic assignment of replication sets for new tables] ( #automatic-assignment-of-replication-sets-for-new-tables ) .
285
+
286
+ Parameters:
287
+ - ` set_name ` - name of the existing replication set
288
+ - ` schema_names ` - array of names name of existing schemas from which tables
289
+ should be added
290
+ - ` synchronize ` - if true, the table data is synchronized on all subscribers
291
+ which are subscribed to given replication set, default false
292
+
269
293
- ` pglogical.replication_set_remove_table(set_name name, table_name regclass) `
270
294
Remove a table from replication set.
271
295
@@ -289,8 +313,12 @@ Example:
289
313
BEGIN
290
314
FOR obj IN SELECT * FROM pg_event_trigger_ddl_commands()
291
315
LOOP
292
- IF obj.object_type = 'table' AND obj.schema_name = 'config' THEN
293
- PERFORM pglogical.replication_set_add_table('configuration', obj.objid);
316
+ IF obj.object_type = 'table' THEN
317
+ IF obj.schema_name = 'config' THEN
318
+ PERFORM pglogical.replication_set_add_table('configuration', obj.objid);
319
+ ELSIF NOT obj.in_extension THEN
320
+ PERFORM pglogical.replication_set_add_table('default', obj.objid);
321
+ END IF;
294
322
END IF;
295
323
END LOOP;
296
324
END;
@@ -302,7 +330,8 @@ Example:
302
330
EXECUTE PROCEDURE pglogical_assign_repset();
303
331
304
332
The above example will put all new tables created in schema ` config ` into
305
- replication set ` configuration ` .
333
+ replication set ` configuration ` and all other new tables which are not created
334
+ by extensions will go to ` default ` replication set.
306
335
307
336
## Conflicts
308
337
@@ -424,7 +453,7 @@ To replicate multiple databases you must set up individual provider/subscriber
424
453
relationships for each. There is no way to configure replication for all databases
425
454
in a PostgreSQL install at once.
426
455
427
- #### ` PRIMARY KEY ` or ` REPLICA IDENTITY ` required
456
+ ### PRIMARY KEY or REPLICA IDENTITY required
428
457
429
458
` UPDATE ` s and ` DELETE ` s cannot be replicated for tables that lack a `PRIMARY
430
459
KEY` or other valid replica identity such as a ` UNIQUE` constraint. Replication
0 commit comments