1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
SELECT * FROM pglogical_regress_variables()
\gset
\c :subscriber_dsn
GRANT ALL ON SCHEMA public TO nonsuper;
SELECT E'\'' || current_database() || E'\'' AS subdb;
subdb
------------
'postgres'
(1 row)
\gset
\c :provider_dsn
SELECT * FROM pglogical.create_replication_set('delay');
create_replication_set
------------------------
3064111751
(1 row)
\c :subscriber_dsn
CREATE or REPLACE function int2interval (x integer) returns interval as
$$ select $1*'1 sec'::interval $$
language sql;
SELECT * FROM pglogical.create_subscription(
subscription_name := 'test_subscription_delay',
provider_dsn := (SELECT provider_dsn FROM pglogical_regress_variables()) || ' user=super',
replication_sets := '{delay}',
forward_origins := '{}',
synchronize_structure := false,
synchronize_data := false,
apply_delay := int2interval(2) -- 2 seconds
);
create_subscription
---------------------
1550781037
(1 row)
BEGIN;
SET LOCAL statement_timeout = '180s';
SELECT pglogical.wait_for_subscription_sync_complete('test_subscription_delay');
wait_for_subscription_sync_complete
-------------------------------------
(1 row)
COMMIT;
SELECT sync_kind, sync_subid, sync_nspname, sync_relname, sync_status IN ('y', 'r') FROM pglogical.local_sync_status ORDER BY 2,3,4;
sync_kind | sync_subid | sync_nspname | sync_relname | ?column?
-----------+------------+--------------+--------------+----------
i | 1550781037 | | | t
f | 3848008564 | | | t
(2 rows)
SELECT status FROM pglogical.show_subscription_status() WHERE subscription_name = 'test_subscription_delay';
status
-------------
replicating
(1 row)
-- Make sure we see the slot and active connection
\c :provider_dsn
SELECT plugin, slot_type, database, active FROM pg_replication_slots;
plugin | slot_type | database | active
------------------+-----------+------------+--------
pglogical_output | logical | regression | t
pglogical_output | logical | regression | t
(2 rows)
SELECT count(*) FROM pg_stat_replication;
count
-------
2
(1 row)
CREATE TABLE public.timestamps (
id text primary key,
ts timestamptz
);
SELECT pglogical.replicate_ddl_command($$
CREATE TABLE public.basic_dml1 (
id serial primary key,
other integer,
data text,
something interval
);
$$);
replicate_ddl_command
-----------------------
t
(1 row)
-- clear old applies, from any previous tests etc.
SELECT pglogical.wait_slot_confirm_lsn(NULL, NULL);
wait_slot_confirm_lsn
-----------------------
(1 row)
INSERT INTO timestamps VALUES ('ts1', CURRENT_TIMESTAMP);
SELECT * FROM pglogical.replication_set_add_table('delay', 'basic_dml1');
replication_set_add_table
---------------------------
t
(1 row)
SELECT pglogical.wait_slot_confirm_lsn(NULL, NULL);
wait_slot_confirm_lsn
-----------------------
(1 row)
INSERT INTO timestamps VALUES ('ts2', CURRENT_TIMESTAMP);
INSERT INTO basic_dml1(other, data, something)
VALUES (5, 'foo', '1 minute'::interval),
(4, 'bar', '12 weeks'::interval),
(3, 'baz', '2 years 1 hour'::interval),
(2, 'qux', '8 months 2 days'::interval),
(1, NULL, NULL);
SELECT pglogical.wait_slot_confirm_lsn(NULL, NULL);
wait_slot_confirm_lsn
-----------------------
(1 row)
INSERT INTO timestamps VALUES ('ts3', CURRENT_TIMESTAMP);
SELECT round (EXTRACT(EPOCH FROM (SELECT ts from timestamps where id = 'ts2')) -
EXTRACT(EPOCH FROM (SELECT ts from timestamps where id = 'ts1'))) :: integer >= 2 as ddl_replication_delayed;
ddl_replication_delayed
-------------------------
t
(1 row)
SELECT round (EXTRACT(EPOCH FROM (SELECT ts from timestamps where id = 'ts3')) -
EXTRACT(EPOCH FROM (SELECT ts from timestamps where id = 'ts2'))) :: integer >= 2 as inserts_replication_delayed;
inserts_replication_delayed
-----------------------------
t
(1 row)
\c :subscriber_dsn
SELECT * FROM basic_dml1;
id | other | data | something
----+-------+------+------------------
1 | 5 | foo | @ 1 min
2 | 4 | bar | @ 84 days
3 | 3 | baz | @ 2 years 1 hour
4 | 2 | qux | @ 8 mons 2 days
5 | 1 | |
(5 rows)
SELECT pglogical.drop_subscription('test_subscription_delay');
drop_subscription
-------------------
1
(1 row)
\c :provider_dsn
\set VERBOSITY terse
SELECT * FROM pglogical.drop_replication_set('delay');
drop_replication_set
----------------------
t
(1 row)
DROP TABLE public.timestamps CASCADE;
SELECT pglogical.replicate_ddl_command($$
DROP TABLE public.basic_dml1 CASCADE;
$$);
replicate_ddl_command
-----------------------
t
(1 row)
|