Skip to content

Commit 20bb28d

Browse files
committed
Merge branch 'master' into REL1_0_STABLE
2 parents c4c6949 + 306c935 commit 20bb28d

File tree

6 files changed

+46
-17
lines changed

6 files changed

+46
-17
lines changed

README.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,13 @@ Tables on the provider and subscriber must have the same columns, with the same
4848
data types in each column. `CHECK` constraints, `NOT NULL` constraints, etc must
4949
be the same or weaker (more permissive) on the subscriber than the provider.
5050

51-
Tables must have the same Primary Keys and be related by the same Foreign Keys.
51+
Tables must have the same `PRIMARY KEY`s. It is not recommended to add additional
52+
`UNIQUE` constraints other than the `PRIMARY KEY` (see below).
53+
54+
Any `FOREIGN KEY`s on the subscriber must also be present on the provider with
55+
all rows on the subscriber present on the provider. In other words a
56+
subscriber's FK constraints must always permit a write if the provider's FK
57+
constraints permitted it.
5258

5359
Some additional requirements are covered in "Limitations and Restrictions", below.
5460

@@ -94,8 +100,12 @@ Add all tables in `public` schema to the `default` replication set.
94100
SELECT pglogical.replication_set_add_all_tables('default', ARRAY['public']);
95101

96102
Optionally you can also create additional replication sets and add tables to
97-
them (see [Replication sets](#replication-sets)). It's usually better to create
98-
replication sets beforehand.
103+
them (see [Replication sets](#replication-sets)).
104+
105+
It's usually better to create replication sets before subscribing so that all
106+
tables are synchronized during initial replication setup in a single initial
107+
transaction. However, users of bigger databases may instead wish to create them
108+
incrementally for better control.
99109

100110
Once the provider node is setup, subscribers can be subscribed to it. First the
101111
subscriber node must be created:
@@ -393,6 +403,19 @@ unique identifier.
393403

394404
See http://www.postgresql.org/docs/current/static/sql-altertable.html#SQL-CREATETABLE-REPLICA-IDENTITY for details on replica identity.
395405

406+
### Only one unique index/constraint/PK
407+
408+
If more than one upstream is configured or the downstream accepts local writes
409+
then only one `UNIQUE` index should be present on downstream replicated tables.
410+
Conflict resolution can only use one index at a time so conflicting rows may
411+
`ERROR` if a row satisfies the `PRIMARY KEY` but violates a `UNIQUE` constraint
412+
on on the downstream side. This will stop replication until the downstream table
413+
is modified to remove the violation.
414+
415+
It's fine to have extra unique constraints on an upstream if the downstream only
416+
gets writes from that upstream and nowhere else. The rule is that the downstream
417+
constraints must *not be more restrictive* than those on the upstream(s).
418+
396419
### DDL
397420

398421
Automatic DDL replication is not supported. Managing DDL so that the provider and

expected/init.out

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ END;$FUNC$ LANGUAGE plpgsql;
3030
GRANT ALL ON SCHEMA public TO nonsuper;
3131
\c :provider_dsn
3232
SET client_min_messages = 'warning';
33-
CREATE EXTENSION IF NOT EXISTS pglogical;
33+
CREATE EXTENSION IF NOT EXISTS pglogical VERSION '1.0.0';
34+
ALTER EXTENSION pglogical UPDATE;
3435
SELECT * FROM pglogical.create_node(node_name := 'test_provider', dsn := (SELECT provider_dsn FROM pglogical_regress_variables()) || ' user=super');
3536
create_node
3637
-------------

expected/init_fail.out

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ GRANT ALL ON ALL TABLES IN SCHEMA pglogical TO nonreplica;
1010
\c :subscriber_dsn
1111
SET client_min_messages = 'warning';
1212
\set VERBOSITY terse
13-
CREATE EXTENSION IF NOT EXISTS pglogical;
13+
CREATE EXTENSION IF NOT EXISTS pglogical VERSION '1.0.0';
14+
ALTER EXTENSION pglogical UPDATE;
1415
-- fail (local node not existing)
1516
SELECT * FROM pglogical.create_subscription(
1617
subscription_name := 'test_subscription',
@@ -63,6 +64,7 @@ SELECT * FROM pglogical.drop_node('test_subscriber');
6364
t
6465
(1 row)
6566

67+
DROP EXTENSION pglogical;
6668
\c :provider_dsn
6769
SELECT * FROM pglogical.drop_node('test_provider');
6870
drop_node
@@ -73,3 +75,4 @@ SELECT * FROM pglogical.drop_node('test_provider');
7375
SET client_min_messages = 'warning';
7476
DROP OWNED BY nonreplica;
7577
DROP ROLE IF EXISTS nonreplica;
78+
DROP EXTENSION pglogical;

pglogical--1.0.0--1.0.1.sql

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,17 @@ RETURNS oid STRICT VOLATILE LANGUAGE c AS 'MODULE_PATHNAME', 'pglogical_create_s
55

66
DO $$
77
BEGIN
8-
IF (SELECT count(1) FROM pglogical.nodes) > 0 THEN
8+
IF (SELECT count(1) FROM pglogical.node) > 0 THEN
99
SELECT * FROM pglogical.create_replication_set('ddl_sql', true, false, false, false);
1010
END IF;
1111
END; $$;
1212

1313
UPDATE pglogical.subscription SET sub_replication_sets = array_append(sub_replication_sets, 'ddl_sql');
1414

15-
BEGIN;
16-
WITH applys AS (
17-
SELECT sub_name FROM pglogical.subscription WHERE sub_enabled
18-
),
19-
WITH disable AS (
20-
SELECT pglogical.alter_subscription_disable(sub_name, true) FROM applys
21-
)
22-
SELECT pglogical.alter_subscription_enable(sub_name, true) FROM applys;
23-
COMMIT;
15+
WITH applys AS (
16+
SELECT sub_name FROM pglogical.subscription WHERE sub_enabled
17+
),
18+
disable AS (
19+
SELECT pglogical.alter_subscription_disable(sub_name, true) FROM applys
20+
)
21+
SELECT pglogical.alter_subscription_enable(sub_name, true) FROM applys;

sql/init.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ GRANT ALL ON SCHEMA public TO nonsuper;
3939

4040
\c :provider_dsn
4141
SET client_min_messages = 'warning';
42-
CREATE EXTENSION IF NOT EXISTS pglogical;
42+
CREATE EXTENSION IF NOT EXISTS pglogical VERSION '1.0.0';
43+
ALTER EXTENSION pglogical UPDATE;
4344

4445
SELECT * FROM pglogical.create_node(node_name := 'test_provider', dsn := (SELECT provider_dsn FROM pglogical_regress_variables()) || ' user=super');
4546

sql/init_fail.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ GRANT ALL ON ALL TABLES IN SCHEMA pglogical TO nonreplica;
1313
\c :subscriber_dsn
1414
SET client_min_messages = 'warning';
1515
\set VERBOSITY terse
16-
CREATE EXTENSION IF NOT EXISTS pglogical;
16+
CREATE EXTENSION IF NOT EXISTS pglogical VERSION '1.0.0';
17+
ALTER EXTENSION pglogical UPDATE;
1718

1819
-- fail (local node not existing)
1920
SELECT * FROM pglogical.create_subscription(
@@ -52,10 +53,12 @@ SELECT * FROM pglogical.create_subscription(
5253
-- cleanup
5354

5455
SELECT * FROM pglogical.drop_node('test_subscriber');
56+
DROP EXTENSION pglogical;
5557

5658
\c :provider_dsn
5759
SELECT * FROM pglogical.drop_node('test_provider');
5860

5961
SET client_min_messages = 'warning';
6062
DROP OWNED BY nonreplica;
6163
DROP ROLE IF EXISTS nonreplica;
64+
DROP EXTENSION pglogical;

0 commit comments

Comments
 (0)