Skip to content

Commit 581092c

Browse files
author
Amit Kapila
committed
Stabilize the test added by commit 022564f.
The test was unstable in branches 14 and 15 as we were relying on the number of changes in the table having a toast column to start streaming. On branches >= 16, we have a GUC debug_logical_replication_streaming which can stream each change, so the test was stable in those branches. Change the test to use PREPARE TRANSACTION as that should make the result consistent and test the code changed in 022564f. Reported-by: Daniel Gustafsson as per buildfarm Author: Hou Zhijie, Amit Kapila Backpatch-through: 14 Discussion: https://postgr.es/m/8C2F86AA-981E-4803-B14D-E264C0255330@yesql.se
1 parent ce6f278 commit 581092c

File tree

4 files changed

+45
-38
lines changed

4 files changed

+45
-38
lines changed

contrib/test_decoding/expected/stream.out

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -106,26 +106,6 @@ SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL,NULL, 'incl
106106
committing streamed transaction
107107
(17 rows)
108108

109-
-- Test that accessing a TOAST table in streaming mode is allowed.
110-
-- Create a table with a column that uses a TOASTed default value.
111-
-- (temporarily hide query, to avoid the long CREATE TABLE stmt)
112-
\set ECHO none
113-
BEGIN;
114-
INSERT INTO test_tab SELECT repeat('a', 6000) || g.i FROM generate_series(1, 350) g(i);
115-
-- Force WAL flush, so that the above changes will be streamed.
116-
SELECT 'force flush' FROM pg_switch_wal();
117-
?column?
118-
-------------
119-
force flush
120-
(1 row)
121-
122-
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1', 'stream-changes', '1');
123-
count
124-
-------
125-
315
126-
(1 row)
127-
128-
COMMIT;
129109
DROP TABLE stream_test;
130110
SELECT pg_drop_replication_slot('regression_slot');
131111
pg_drop_replication_slot

contrib/test_decoding/expected/twophase.out

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,33 @@ SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'inc
202202
COMMIT
203203
(3 rows)
204204

205+
-- Test that accessing a TOAST table is permitted during the decoding of a
206+
-- prepared transaction.
207+
-- Create a table with a column that uses a TOASTed default value.
208+
-- (temporarily hide query, to avoid the long CREATE TABLE stmt)
209+
\set ECHO none
210+
BEGIN;
211+
INSERT INTO test_tab VALUES('test');
212+
PREPARE TRANSACTION 'test_toast_table_access';
213+
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1', 'stream-changes', '1');
214+
count
215+
-------
216+
3
217+
(1 row)
218+
219+
COMMIT PREPARED 'test_toast_table_access';
220+
-- consume commit prepared
221+
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1', 'stream-changes', '1');
222+
data
223+
-------------------------------------------
224+
COMMIT PREPARED 'test_toast_table_access'
225+
(1 row)
226+
205227
-- Test 8:
206228
-- cleanup and make sure results are also empty
207229
DROP TABLE test_prepared1;
208230
DROP TABLE test_prepared2;
231+
DROP TABLE test_tab;
209232
-- show results. There should be nothing to show
210233
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
211234
data

contrib/test_decoding/sql/stream.sql

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,5 @@ toasted-123456789012345678901234567890123456789012345678901234567890123456789012
4444

4545
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL,NULL, 'include-xids', '0', 'skip-empty-xacts', '1', 'stream-changes', '1');
4646

47-
-- Test that accessing a TOAST table in streaming mode is allowed.
48-
49-
-- Create a table with a column that uses a TOASTed default value.
50-
-- (temporarily hide query, to avoid the long CREATE TABLE stmt)
51-
\set ECHO none
52-
SELECT 'CREATE TABLE test_tab (a text DEFAULT ''' || string_agg('toast value', '') || ''');' FROM generate_series(1, 4000)
53-
\gexec
54-
\set ECHO all
55-
56-
BEGIN;
57-
INSERT INTO test_tab SELECT repeat('a', 6000) || g.i FROM generate_series(1, 350) g(i);
58-
59-
-- Force WAL flush, so that the above changes will be streamed.
60-
SELECT 'force flush' FROM pg_switch_wal();
61-
62-
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1', 'stream-changes', '1');
63-
COMMIT;
64-
6547
DROP TABLE stream_test;
6648
SELECT pg_drop_replication_slot('regression_slot');

contrib/test_decoding/sql/twophase.sql

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,32 @@ COMMIT PREPARED 'test_prepared_nodecode';
101101
-- should be decoded now
102102
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
103103

104+
-- Test that accessing a TOAST table is permitted during the decoding of a
105+
-- prepared transaction.
106+
107+
-- Create a table with a column that uses a TOASTed default value.
108+
-- (temporarily hide query, to avoid the long CREATE TABLE stmt)
109+
\set ECHO none
110+
SELECT 'CREATE TABLE test_tab (a text DEFAULT ''' || string_agg('toast value', '') || ''');' FROM generate_series(1, 4000)
111+
\gexec
112+
\set ECHO all
113+
114+
BEGIN;
115+
INSERT INTO test_tab VALUES('test');
116+
PREPARE TRANSACTION 'test_toast_table_access';
117+
118+
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1', 'stream-changes', '1');
119+
120+
COMMIT PREPARED 'test_toast_table_access';
121+
122+
-- consume commit prepared
123+
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1', 'stream-changes', '1');
124+
104125
-- Test 8:
105126
-- cleanup and make sure results are also empty
106127
DROP TABLE test_prepared1;
107128
DROP TABLE test_prepared2;
129+
DROP TABLE test_tab;
108130
-- show results. There should be nothing to show
109131
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
110132

0 commit comments

Comments
 (0)