|
| 1 | +/* First test whether a table's replication set can be properly manipulated */ |
| 2 | +SELECT * FROM pglogical_regress_variables() |
| 3 | +\gset |
| 4 | +\c :provider_dsn |
| 5 | +SELECT pglogical.replicate_ddl_command($$ |
| 6 | +CREATE TABLE public.test2pc_tbl(id serial primary key, value int); |
| 7 | +$$); |
| 8 | + replicate_ddl_command |
| 9 | +----------------------- |
| 10 | + t |
| 11 | +(1 row) |
| 12 | + |
| 13 | +SELECT * FROM pglogical.replication_set_add_all_tables('default', '{public}'); |
| 14 | + replication_set_add_all_tables |
| 15 | +-------------------------------- |
| 16 | + t |
| 17 | +(1 row) |
| 18 | + |
| 19 | +-- Check that prapeared state is visible on slave and data available after commit |
| 20 | +BEGIN; |
| 21 | +INSERT INTO test2pc_tbl VALUES (1, 10); |
| 22 | +PREPARE TRANSACTION 'tx1'; |
| 23 | +SELECT pg_xlog_wait_remote_apply(pg_current_xlog_location(), 0); |
| 24 | + pg_xlog_wait_remote_apply |
| 25 | +--------------------------- |
| 26 | + |
| 27 | +(1 row) |
| 28 | + |
| 29 | +\c :subscriber_dsn |
| 30 | +SELECT gid, owner, database FROM pg_prepared_xacts; |
| 31 | + gid | owner | database |
| 32 | +-----+-------+-------------------- |
| 33 | + tx1 | stas | contrib_regression |
| 34 | +(1 row) |
| 35 | + |
| 36 | +SELECT * FROM test2pc_tbl; |
| 37 | + id | value |
| 38 | +----+------- |
| 39 | +(0 rows) |
| 40 | + |
| 41 | +\c :provider_dsn |
| 42 | +COMMIT PREPARED 'tx1'; |
| 43 | +SELECT pg_xlog_wait_remote_apply(pg_current_xlog_location(), 0); |
| 44 | + pg_xlog_wait_remote_apply |
| 45 | +--------------------------- |
| 46 | + |
| 47 | +(1 row) |
| 48 | + |
| 49 | +\c :subscriber_dsn |
| 50 | +SELECT gid, owner, database FROM pg_prepared_xacts; |
| 51 | + gid | owner | database |
| 52 | +-----+-------+---------- |
| 53 | <
10000
span class="diff-text-marker">+(0 rows) |
| 54 | + |
| 55 | +SELECT * FROM test2pc_tbl; |
| 56 | + id | value |
| 57 | +----+------- |
| 58 | + 1 | 10 |
| 59 | +(1 row) |
| 60 | + |
| 61 | +-- Check that prapeared state is visible on slave and data is ignored after abort |
| 62 | +\c :provider_dsn |
| 63 | +BEGIN; |
| 64 | +INSERT INTO test2pc_tbl VALUES (2, 20); |
| 65 | +PREPARE TRANSACTION 'tx2'; |
| 66 | +SELECT pg_xlog_wait_remote_apply(pg_current_xlog_location(), 0); |
| 67 | + pg_xlog_wait_remote_apply |
| 68 | +--------------------------- |
| 69 | + |
| 70 | +(1 row) |
| 71 | + |
| 72 | +\c :subscriber_dsn |
| 73 | +SELECT gid, owner, database FROM pg_prepared_xacts; |
| 74 | + gid | owner | database |
| 75 | +-----+-------+-------------------- |
| 76 | + tx2 | stas | contrib_regression |
| 77 | +(1 row) |
| 78 | + |
| 79 | +SELECT * FROM test2pc_tbl; |
| 80 | + id | value |
| 81 | +----+------- |
| 82 | + 1 | 10 |
| 83 | +(1 row) |
| 84 | + |
| 85 | +\c :provider_dsn |
| 86 | +ROLLBACK PREPARED 'tx2'; |
| 87 | +SELECT pg_xlog_wait_remote_apply(pg_current_xlog_location(), 0); |
| 88 | + pg_xlog_wait_remote_apply |
| 89 | +--------------------------- |
| 90 | + |
| 91 | +(1 row) |
| 92 | + |
| 93 | +\c :subscriber_dsn |
| 94 | +SELECT gid, owner, database FROM pg_prepared_xacts; |
| 95 | + gid | owner | database |
| 96 | +-----+-------+---------- |
| 97 | +(0 rows) |
| 98 | + |
| 99 | +SELECT * FROM test2pc_tbl; |
| 100 | + id | value |
| 101 | +----+------- |
| 102 | + 1 | 10 |
| 103 | +(1 row) |
| 104 | + |
| 105 | +-- Clean up |
| 106 | +\set VERBOSITY terse |
| 107 | +SELECT pglogical.replicate_ddl_command($$ |
| 108 | + DROP TABLE public.test2pc_tbl CASCADE; |
| 109 | +$$); |
| 110 | + replicate_ddl_command |
| 111 | +----------------------- |
| 112 | + t |
| 113 | +(1 row) |
| 114 | + |
0 commit comments