| 1 |
SET synchronous_commit = on; |
| 2 |
SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding'); |
| 3 |
?column? |
| 4 |
---------- |
| 5 |
init |
| 6 |
(1 row) |
| 7 |
|
| 8 |
CREATE TABLE stream_test(data text); |
| 9 |
-- consume DDL |
| 10 |
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1'); |
| 11 |
data |
| 12 |
------ |
| 13 |
(0 rows) |
| 14 |
|
| 15 |
-- streaming test with sub-transaction |
| 16 |
BEGIN; |
| 17 |
savepoint s1; |
| 18 |
SELECT 'msg5' FROM pg_logical_emit_message(true, 'test', repeat('a', 50)); |
| 19 |
?column? |
| 20 |
---------- |
| 21 |
msg5 |
| 22 |
(1 row) |
| 23 |
|
| 24 |
INSERT INTO stream_test SELECT repeat('a', 2000) || g.i FROM generate_series(1, 35) g(i); |
| 25 |
TRUNCATE table stream_test; |
| 26 |
rollback to s1; |
| 27 |
INSERT INTO stream_test SELECT repeat('a', 10) || g.i FROM generate_series(1, 20) g(i); |
| 28 |
COMMIT; |
| 29 |
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL,NULL, 'include-xids', '0', 'skip-empty-xacts', '1', 'stream-changes', '1'); |
| 30 |
data |
| 31 |
---------------------------------------------------------- |
| 32 |
opening a streamed block for transaction |
| 33 |
streaming message: transactional: 1 prefix: test, sz: 50 |
| 34 |
closing a streamed block for transaction |
| 35 |
aborting streamed (sub)transaction |
| 36 |
opening a streamed block for transaction |
| 37 |
streaming change for transaction |
| 38 |
streaming change for transaction |
| 39 |
streaming change for transaction |
| 40 |
streaming change for transaction |
| 41 |
streaming change for transaction |
| 42 |
streaming change for transaction |
| 43 |
streaming change for transaction |
| 44 |
streaming change for transaction |
| 45 |
streaming change for transaction |
| 46 |
streaming change for transaction |
| 47 |
streaming change for transaction |
| 48 |
streaming change for transaction |
| 49 |
streaming change for transaction |
| 50 |
streaming change for transaction |
| 51 |
streaming change for transaction |
| 52 |
streaming change for transaction |
| 53 |
streaming change for transaction |
| 54 |
streaming change for transaction |
| 55 |
streaming change for transaction |
| 56 |
streaming change for transaction |
| 57 |
closing a streamed block for transaction |
| 58 |
committing streamed transaction |
| 59 |
(27 rows) |
| 60 |
|
| 61 |
-- streaming test for toast changes |
| 62 |
ALTER TABLE stream_test ALTER COLUMN data set storage external; |
| 63 |
-- consume DDL |
| 64 |
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1'); |
| 65 |
data |
| 66 |
------ |
| 67 |
(0 rows) |
| 68 |
|
| 69 |
INSERT INTO stream_test SELECT repeat('a', 6000) || g.i FROM generate_series(1, 10) g(i); |
| 70 |
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL,NULL, 'include-xids', '0', 'skip-empty-xacts', '1', 'stream-changes', '1'); |
| 71 |
data |
| 72 |
------------------------------------------ |
| 73 |
opening a streamed block for transaction |
| 74 |
streaming change for transaction |
| 75 |
streaming change for transaction |
| 76 |
streaming change for transaction |
| 77 |
streaming change for transaction |
| 78 |
streaming change for transaction |
| 79 |
streaming change for transaction |
| 80 |
streaming change for transaction |
| 81 |
streaming change for transaction |
| 82 |
streaming change for transaction |
| 83 |
streaming change for transaction |
| 84 |
closing a streamed block for transaction |
| 85 |
committing streamed transaction |
| 86 |
(13 rows) |
| 87 |
|
| 88 |
-- streaming test for toast with multi-insert |
| 89 |
\COPY stream_test FROM STDIN |
| 90 |
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL,NULL, 'include-xids', '0', 'skip-empty-xacts', '1', 'stream-changes', '1'); |
| 91 |
data |
| 92 |
------------------------------------------ |
| 93 |
opening a streamed block for transaction |
| 94 |
streaming change for transaction |
| 95 |
streaming change for transaction |
| 96 |
streaming change for transaction |
| 97 |
streaming change for transaction |
| 98 |
streaming change for transaction |
| 99 |
streaming change for transaction |
| 100 |
streaming change for transaction |
| 101 |
streaming change for transaction |
| 102 |
streaming change for transaction |
| 103 |
streaming change for transaction |
| 104 |
streaming change for transaction |
| 105 |
closing a streamed block for transaction |
| 106 |
opening a streamed block for transaction |
| 107 |
streaming change for transaction |
| 108 |
closing a streamed block for transaction |
| 109 |
committing streamed transaction |
| 110 |
(17 rows) |
| 111 |
|
| 112 |
/* |
| 113 |
* Test concurrent abort with toast data. When streaming the second insertion, we |
| 114 |
* detect that the subtransaction was aborted, and reset the transaction while having |
| 115 |
* the TOAST changes in memory, resulting in deallocating both decoded changes and |
| 116 |
* TOAST reconstruction data. Memory usage counters must be updated correctly. |
| 117 |
* |
| 118 |
* Set debug_logical_replication_streaming to 'immediate' to disable the transaction |
| 119 |
* status check happening before streaming the second insertion, so we can detect a |
| 120 |
* concurrent abort while streaming. |
| 121 |
*/ |
| 122 |
SET debug_logical_replication_streaming = immediate; |
| 123 |
BEGIN; |
| 124 |
INSERT INTO stream_test SELECT repeat(string_agg(to_char(g.i, 'FM0000'), ''), 50) FROM generate_series(1, 500) g(i); |
| 125 |
ALTER TABLE stream_test ADD COLUMN i INT; |
| 126 |
SAVEPOINT s1; |
| 127 |
INSERT INTO stream_test(data, i) SELECT repeat(string_agg(to_char(g.i, 'FM0000'), ''), 50), 1 FROM generate_series(1, 500) g(i); |
| 128 |
ROLLBACK TO s1; |
| 129 |
COMMIT; |
| 130 |
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1', 'stream-changes', '1'); |
| 131 |
count |
| 132 |
------- |
| 133 |
5 |
| 134 |
(1 row) |
| 135 |
|
| 136 |
RESET debug_logical_replication_streaming; |
| 137 |
DROP TABLE stream_test; |
| 138 |
SELECT pg_drop_replication_slot('regression_slot'); |
| 139 |
pg_drop_replication_slot |
| 140 |
-------------------------- |
| 141 |
|
| 142 |
(1 row) |
| 143 |
|