Stabilize the test added by commit 022564f60c.
authorAmit Kapila <[email protected]>
Tue, 8 Oct 2024 06:55:52 +0000 (12:25 +0530)
committerAmit Kapila <[email protected]>
Tue, 8 Oct 2024 06:55:52 +0000 (12:25 +0530)
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 022564f60c.

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

contrib/test_decoding/expected/stream.out
contrib/test_decoding/expected/twophase.out
contrib/test_decoding/sql/stream.sql
contrib/test_decoding/sql/twophase.sql

index 6a8a00a65ba24f6a751f77ae1f126df0c4e792e2..a76f77601e26f7333565aea78503074a6bd99b16 100644 (file)
@@ -128,28 +128,6 @@ SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL,
      5
 (1 row)
 
--- Test that accessing a TOAST table in streaming mode is allowed.
--- Create a table with a column that uses a TOASTed default value.
--- (temporarily hide query, to avoid the long CREATE TABLE stmt)
-\set ECHO none
-SET debug_logical_replication_streaming = immediate;
-BEGIN;
-INSERT INTO test_tab VALUES(1);
--- Force WAL flush, so that the above changes will be streamed.
-SELECT 'force flush' FROM pg_switch_wal();
-  ?column?   
--------------
- force flush
-(1 row)
-
-SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1', 'stream-changes', '1');
- count 
--------
-     3
-(1 row)
-
-COMMIT;
-RESET debug_logical_replication_streaming;
 DROP TABLE stream_test;
 SELECT pg_drop_replication_slot('regression_slot');
  pg_drop_replication_slot 
index 517f20bc37e7a66a9c4d52cfbdcc86b1b55272a6..08a7c56b5dfb56755611c86019782f9a45946a1b 100644 (file)
@@ -205,11 +205,34 @@ SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'inc
  COMMIT
 (3 rows)
 
+-- Test that accessing a TOAST table is permitted during the decoding of a
+-- prepared transaction.
+-- Create a table with a column that uses a TOASTed default value.
+-- (temporarily hide query, to avoid the long CREATE TABLE stmt)
+\set ECHO none
+BEGIN;
+INSERT INTO test_tab VALUES('test');
+PREPARE TRANSACTION 'test_toast_table_access';
+SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1', 'stream-changes', '1');
+ count 
+-------
+     3
+(1 row)
+
+COMMIT PREPARED 'test_toast_table_access';
+-- consume commit prepared
+SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1', 'stream-changes', '1');
+                   data                    
+-------------------------------------------
+ COMMIT PREPARED 'test_toast_table_access'
+(1 row)
+
 -- Test 8:
 -- cleanup and make sure results are also empty
 DROP TABLE test_prepared1;
 DROP TABLE test_prepared2;
 DROP TABLE test_prepared_savepoint;
+DROP TABLE test_tab;
 -- show results. There should be nothing to show
 SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
  data 
index d7a696586e9ed2f79f8b44ea5a4183acbbbc1ddd..7f43f0c2ab72a0a437298ed7d3d9553ebfb38eec 100644 (file)
@@ -59,27 +59,5 @@ ROLLBACK TO s1;
 COMMIT;
 SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1', 'stream-changes', '1');
 
--- Test that accessing a TOAST table in streaming mode is allowed.
-
--- Create a table with a column that uses a TOASTed default value.
--- (temporarily hide query, to avoid the long CREATE TABLE stmt)
-\set ECHO none
-SELECT 'CREATE TABLE test_tab (a text DEFAULT ''' || string_agg('toast value', '') || ''');' FROM generate_series(1, 4000)
-\gexec
-\set ECHO all
-
-SET debug_logical_replication_streaming = immediate;
-
-BEGIN;
-INSERT INTO test_tab VALUES(1);
-
--- Force WAL flush, so that the above changes will be streamed.
-SELECT 'force flush' FROM pg_switch_wal();
-
-SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1', 'stream-changes', '1');
-COMMIT;
-
-RESET debug_logical_replication_streaming;
-
 DROP TABLE stream_test;
 SELECT pg_drop_replication_slot('regression_slot');
index 0244795f3d9e1442fa42ab86c6d5f6726aeefc99..4b9ef0c0c449913c2188f133f6654d7ebf44ccb8 100644 (file)
@@ -104,11 +104,33 @@ COMMIT PREPARED 'test_prepared_nodecode';
 -- should be decoded now
 SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
 
+-- Test that accessing a TOAST table is permitted during the decoding of a
+-- prepared transaction.
+
+-- Create a table with a column that uses a TOASTed default value.
+-- (temporarily hide query, to avoid the long CREATE TABLE stmt)
+\set ECHO none
+SELECT 'CREATE TABLE test_tab (a text DEFAULT ''' || string_agg('toast value', '') || ''');' FROM generate_series(1, 4000)
+\gexec
+\set ECHO all
+
+BEGIN;
+INSERT INTO test_tab VALUES('test');
+PREPARE TRANSACTION 'test_toast_table_access';
+
+SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1', 'stream-changes', '1');
+
+COMMIT PREPARED 'test_toast_table_access';
+
+-- consume commit prepared
+SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1', 'stream-changes', '1');
+
 -- Test 8:
 -- cleanup and make sure results are also empty
 DROP TABLE test_prepared1;
 DROP TABLE test_prepared2;
 DROP TABLE test_prepared_savepoint;
+DROP TABLE test_tab;
 -- show results. There should be nothing to show
 SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');