Subject: [PATCH v23 5/5] Additional test for new GUC setting.

From: Kyotaro Horiguchi <[email-masked]>
Date: Wed, 28 Aug 2019 14:12:18 +0900

This patchset adds new GUC variable effective_io_block_size that
controls wheter WAL-skipped tables are finally WAL-logged or
fcync'ed. All of the TAP test performs WAL-logging so this adds an
item that performs file sync.
---
 src/test/recovery/t/018_wal_optimize.pl | 38 ++++++++++++++++++++++++-
 1 file changed, 37 insertions(+), 1 deletion(-)

diff --git a/src/test/recovery/t/018_wal_optimize.pl b/src/test/recovery/t/018_wal_optimize.pl
index ac62c77a42..470d4f048c 100644
--- a/src/test/recovery/t/018_wal_optimize.pl
+++ b/src/test/recovery/t/018_wal_optimize.pl
@@ -18,7 +18,7 @@ use warnings;
 
 use PostgresNode;
 use TestLib;
-use Test::More tests => 26;
+use Test::More tests => 32;
 
 # Make sure no orphan relfilenode files exist.
 sub check_orphan_relfilenodes
@@ -52,6 +52,8 @@ sub run_wal_optimize
 	$node->append_conf('postgresql.conf', qq(
 wal_level = $wal_level
 max_prepared_transactions = 1
+wal_log_hints = on
+wal_skip_threshold = 0
 ));
 	$node->start;
 
@@ -111,7 +113,23 @@ max_prepared_transactions = 1
 	$result = $node->safe_psql('postgres', "SELECT count(*) FROM test2a;");
 	is($result, qq(1),
 	   "wal_level = $wal_level, optimized truncation with prepared transaction");
+	# Same for file sync mode
+	# Tuples inserted after the truncation should be seen.
+	$node->safe_psql('postgres', "
+		SET wal_skip_threshold to 0;
+		BEGIN;
+		CREATE TABLE test2b (id serial PRIMARY KEY);
+		INSERT INTO test2b VALUES (DEFAULT);
+		TRUNCATE test2b;
+		INSERT INTO test2b VALUES (DEFAULT);
+		COMMIT;");
+
+	$node->stop('immediate');
+	$node->start;
 
+	$result = $node->safe_psql('postgres', "SELECT count(*) FROM test2b;");
+	is($result, qq(1),
+	   "wal_level = $wal_level, optimized truncation with file-sync");
 
 	# Data file for COPY query in follow-up tests.
 	my $basedir = $node->basedir;
@@ -187,6 +205,24 @@ max_prepared_transactions = 1
 	is($result, qq(3),
 	   "wal_level = $wal_level, SET TABLESPACE in subtransaction");
 
+	$node->safe_psql('postgres', "
+		BEGIN;
+		CREATE TABLE test3a5 (c int PRIMARY KEY);
+		SAVEPOINT q; INSERT INTO test3a5 VALUES (1); ROLLBACK TO q;
+		CHECKPOINT;
+		INSERT INTO test3a5 VALUES (1);  -- set index hint bit
+		INSERT INTO test3a5 VALUES (2);
+		COMMIT;");
+	$node->stop('immediate');
+	$node->start;
+	$result = $node->psql('postgres', );
+	my($ret, $stdout, $stderr) = $node->psql(
+		'postgres', "INSERT INTO test3a5 VALUES (2);");
+	is($ret, qq(3),
+	   "wal_level = $wal_level, unique index LP_DEAD");
+	like($stderr, qr/violates unique/,
+	   "wal_level = $wal_level, unique index LP_DEAD message");
+
 	# UPDATE touches two buffers; one is BufferNeedsWAL(); the other is not.
 	$node->safe_psql('postgres', "
 		BEGIN;
-- 
2.23.0

----Next_Part(Wed_Nov__6_17_29_27_2019_575)----