Repository: percona/postgres
Pull request #216: Improve TAP tests
Author: login: jeltz
Created: 2025-04-14T16:12:56Z | Merged: 2025-04-16T22:32:50Z

Having worked a bit too much with out TAP tests during the last week I realized that one way they could be improved while still using this way of prepending we are like `pg_regress` is to do it more properly instead of halfhearted so I added a `PGTDE::psql()` helper which calls runs the query and then appends both stderr and stdout to the file when later will diff.

The reason for this is because right now when something goes wrong and some query fails you just get a truncated output file and then have to start modifying the test case to add debug output. Ideally we should have the error message of the failing query easily visible when the test run fails.

What do you think? The alternative would to abandon the idea of diffing the two files and instead aim for more idiomatic TAP tests instead because just running `safe_psql()` does not seem to give us much.

Edit: This is ready for review now.


Diff:
diff --git a/contrib/pg_tde/t/001_basic.pl b/contrib/pg_tde/t/001_basic.pl
index 4740992f03257..87146f1cdaf8a 100644
--- a/contrib/pg_tde/t/001_basic.pl
+++ b/contrib/pg_tde/t/001_basic.pl
@@ -3,67 +3,49 @@
 use strict;
 use warnings;
 use File::Basename;
-use File::Compare;
-use File::Copy;
 use Test::More;
 use lib 't';
 use pgtde;
 
-# Get file name and CREATE out file name and dirs WHERE requried
 PGTDE::setup_files_dir(basename($0));
 
-# CREATE new PostgreSQL node and do initdb
 my $node = PGTDE->pgtde_init_pg();
 my $pgdata = $node->data_dir;
 
-# UPDATE postgresql.conf to include/load pg_tde library
 open my $conf, '>>', "$pgdata/postgresql.conf";
 print $conf "shared_preload_libraries = 'pg_tde'\n";
 close $conf;
 
-# Start server
 my $rt_value = $node->start;
 ok($rt_value == 1, "Start Server");
 
-# CREATE EXTENSION IF NOT EXISTS and change out file permissions
-my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION IF NOT EXISTS pg_tde;', extra_params => ['-a']);
-ok($cmdret == 0, "CREATE PGTDE EXTENSION");
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'CREATE EXTENSION IF NOT EXISTS pg_tde;');
 
-my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT extname, extversion FROM pg_extension WHERE extname = \'pg_tde\';', extra_params => ['-a']);
-ok($cmdret == 0, "SELECT PGTDE VERSION");
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'SELECT extname, extversion FROM pg_extension WHERE extname = \'pg_tde\';');
 
-$rt_value = $node->psql('postgres', 'CREATE TABLE test_enc(id SERIAL,k INTEGER,PRIMARY KEY (id)) USING tde_heap;', extra_params => ['-a']);
-ok($rt_value == 3, "Failing query");
+PGTDE::psql($node, 'postgres', 'CREATE TABLE test_enc(id SERIAL,k INTEGER,PRIMARY KEY (id)) USING tde_heap;');
 
-
-# Restart the server
-PGTDE::append_to_file("-- server restart");
+PGTDE::append_to_result_file("-- server restart");
 $node->stop();
-
 $rt_value = $node->start();
 ok($rt_value == 1, "Restart Server");
 
-$rt_value = $node->psql('postgres', "SELECT pg_tde_add_database_key_provider_file('file-vault','/tmp/pg_tde_test_keyring.per');", extra_params => ['-a']);
-$rt_value = $node->psql('postgres', "SELECT pg_tde_set_key_using_database_key_provider('test-db-key','file-vault');", extra_params => ['-a']);
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_add_database_key_provider_file('file-vault','/tmp/pg_tde_test_keyring.per');");
+
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_set_key_using_database_key_provider('test-db-key','file-vault');");
 
-$stdout = $node->safe_psql('postgres', 'CREATE TABLE test_enc(id SERIAL,k VARCHAR(32),PRIMARY KEY (id)) USING tde_heap;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'CREATE TABLE test_enc(id SERIAL,k VARCHAR(32),PRIMARY KEY (id)) USING tde_heap;');
 
-$stdout = $node->safe_psql('postgres', 'INSERT INTO test_enc (k) VALUES (\'foobar\'),(\'barfoo\');', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'INSERT INTO test_enc (k) VALUES (\'foobar\'),(\'barfoo\');');
 
-$stdout = $node->safe_psql('postgres', 'SELECT * FROM test_enc ORDER BY id ASC;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'SELECT * FROM test_enc ORDER BY id ASC;');
 
-# Restart the server
-PGTDE::append_to_file("-- server restart");
-$rt_value = $node->stop();
+PGTDE::append_to_result_file("-- server restart");
+$node->stop();
 $rt_value = $node->start();
+ok($rt_value == 1, "Restart Server");
 
-$stdout = $node->safe_psql('postgres', 'SELECT * FROM test_enc ORDER BY id ASC;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'SELECT * FROM test_enc ORDER BY id ASC;');
 
 # Verify that we can't see the data in the file
 my $tablefile = $node->safe_psql('postgres', 'SHOW data_directory;');
@@ -72,27 +54,21 @@
 
 my $strings = 'TABLEFILE FOUND: ';
 $strings .= `(ls  $tablefile >/dev/null && echo yes) || echo no`;
-PGTDE::append_to_file($strings);
+PGTDE::append_to_result_file($strings);
 
 $strings = 'CONTAINS FOO (should be empty): ';
 $strings .= `strings $tablefile | grep foo`;
-PGTDE::append_to_file($strings);
+PGTDE::append_to_result_file($strings);
+
+PGTDE::psql($node, 'postgres', 'DROP TABLE test_enc;');
 
-$stdout = $node->safe_psql('postgres', 'DROP TABLE test_enc;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'DROP EXTENSION pg_tde;');
 
-# DROP EXTENSION
-$stdout = $node->safe_psql('postgres', 'DROP EXTENSION pg_tde;', extra_params => ['-a']);
-ok($cmdret == 0, "DROP PGTDE EXTENSION");
-PGTDE::append_to_file($stdout);
-# Stop the server
 $node->stop();
 
-# compare the expected and out file
+# Compare the expected and out file
 my $compare = PGTDE->compare_results();
 
-# Test/check if expected and result/out file match. If Yes, test passes.
 is($compare,0,"Compare Files: $PGTDE::expected_filename_with_path and $PGTDE::out_filename_with_path files.");
 
-# Done testing for this testcase file.
 done_testing();
diff --git a/contrib/pg_tde/t/002_rotate_key.pl b/contrib/pg_tde/t/002_rotate_key.pl
index 31b99250dadec..38cd31075706f 100644
--- a/contrib/pg_tde/t/002_rotate_key.pl
+++ b/contrib/pg_tde/t/002_rotate_key.pl
@@ -3,199 +3,134 @@
 use strict;
 use warnings;
 use File::Basename;
-use File::Compare;
-use File::Copy;
 use Test::More;
 use lib 't';
 use pgtde;
 
-# Get file name and CREATE out file name and dirs WHERE requried
 PGTDE::setup_files_dir(basename($0));
 
-# CREATE new PostgreSQL node and do initdb
 my $node = PGTDE->pgtde_init_pg();
 my $pgdata = $node->data_dir;
 
-# UPDATE postgresql.conf to include/load pg_tde library
 open my $conf, '>>', "$pgdata/postgresql.conf";
 print $conf "shared_preload_libraries = 'pg_tde'\n";
 close $conf;
 
-# Start server
 my $rt_value = $node->start;
 ok($rt_value == 1, "Start Server");
 
-# CREATE EXTENSION IF NOT EXISTS and change out file permissions
-my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION IF NOT EXISTS pg_tde;', extra_params => ['-a']);
-ok($cmdret == 0, "CREATE PGTDE EXTENSION");
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'CREATE EXTENSION IF NOT EXISTS pg_tde;');
 
+PGTDE::psql($node, 'postgres', 'CREATE TABLE test_enc(id SERIAL,k INTEGER,PRIMARY KEY (id)) USING tde_heap;');
 
-$rt_value = $node->psql('postgres', 'CREATE TABLE test_enc(id SERIAL,k INTEGER,PRIMARY KEY (id)) USING tde_heap;', extra_params => ['-a']);
-ok($rt_value == 3, "Failing query");
-
-
-# Restart the server
-PGTDE::append_to_file("-- server restart");
+PGTDE::append_to_result_file("-- server restart");
 $node->stop();
-
 $rt_value = $node->start();
 ok($rt_value == 1, "Restart Server");
 
-$stdout = $node->safe_psql('postgres', "SELECT pg_tde_add_database_key_provider_file('file-vault','/tmp/pg_tde_test_keyring.per');", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-$stdout = $node->safe_psql('postgres', "SELECT pg_tde_add_database_key_provider_file('file-2','/tmp/pg_tde_test_keyring_2.per');", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-$stdout = $node->safe_psql('postgres', "SELECT pg_tde_add_global_key_provider_file('file-2','/tmp/pg_tde_test_keyring_2g.per');", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-$stdout = $node->safe_psql('postgres', "SELECT pg_tde_add_global_key_provider_file('file-3','/tmp/pg_tde_test_keyring_3.per');", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_add_database_key_provider_file('file-vault','/tmp/pg_tde_test_keyring.per');");
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_add_database_key_provider_file('file-2','/tmp/pg_tde_test_keyring_2.per');");
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_add_global_key_provider_file('file-2','/tmp/pg_tde_test_keyring_2g.per');");
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_add_global_key_provider_file('file-3','/tmp/pg_tde_test_keyring_3.per');");
 
-$stdout = $node->safe_psql('postgres', "SELECT pg_tde_list_all_database_key_providers();", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_list_all_database_key_providers();");
 
-$stdout = $node->safe_psql('postgres', "SELECT pg_tde_set_key_using_database_key_provider('test-db-key','file-vault');", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_set_key_using_database_key_provider('test-db-key','file-vault');");
 
-$stdout = $node->safe_psql('postgres', 'CREATE TABLE test_enc(id SERIAL,k INTEGER,PRIMARY KEY (id)) USING tde_heap;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'CREATE TABLE test_enc(id SERIAL,k INTEGER,PRIMARY KEY (id)) USING tde_heap;');
 
-$stdout = $node->safe_psql('postgres', 'INSERT INTO test_enc (k) VALUES (5),(6);', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'INSERT INTO test_enc (k) VALUES (5),(6);');
 
-$stdout = $node->safe_psql('postgres', 'SELECT * FROM test_enc ORDER BY id ASC;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'SELECT * FROM test_enc ORDER BY id ASC;');
 
-#rotate key
-$stdout = $node->psql('postgres', "SELECT pg_tde_set_key_using_database_key_provider('rotated-key1');", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-$stdout = $node->safe_psql('postgres', 'SELECT * FROM test_enc ORDER BY id ASC;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+# Rotate key
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_set_key_using_database_key_provider('rotated-key1');");
+PGTDE::psql($node, 'postgres', 'SELECT * FROM test_enc ORDER BY id ASC;');
 
-# Restart the server
-PGTDE::append_to_file("-- server restart");
-$rt_value = $node->stop();
+PGTDE::append_to_result_file("-- server restart");
+$node->stop();
 $rt_value = $node->start();
+ok($rt_value == 1, "Restart Server");
 
-$stdout = $node->safe_psql('postgres', "SELECT key_provider_id, key_provider_name, key_name FROM pg_tde_key_info();", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT key_provider_id, key_provider_name, key_name FROM pg_tde_server_key_info();", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-PGTDE::append_to_file($stderr);
-$stdout = $node->safe_psql('postgres', 'SELECT * FROM test_enc ORDER BY id ASC;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-
+PGTDE::psql($node, 'postgres', "SELECT key_provider_id, key_provider_name, key_name FROM pg_tde_key_info();");
+PGTDE::psql($node, 'postgres', "SELECT key_provider_id, key_provider_name, key_name FROM pg_tde_server_key_info();");
+PGTDE::psql($node, 'postgres', 'SELECT * FROM test_enc ORDER BY id ASC;');
 
-#Again rotate key
-$stdout = $node->safe_psql('postgres', "SELECT pg_tde_set_key_using_database_key_provider('rotated-key2','file-2');", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-$stdout = $node->safe_psql('postgres', 'SELECT * FROM test_enc ORDER BY id ASC;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+# Again rotate key
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_set_key_using_database_key_provider('rotated-key2','file-2');");
+PGTDE::psql($node, 'postgres', 'SELECT * FROM test_enc ORDER BY id ASC;');
 
-# Restart the server
-PGTDE::append_to_file("-- server restart");
-$rt_value = $node->stop();
+PGTDE::append_to_result_file("-- server restart");
+$node->stop();
 $rt_value = $node->start();
+ok($rt_value == 1, "Restart Server");
+
+PGTDE::psql($node, 'postgres', "SELECT key_provider_id, key_provider_name, key_name FROM pg_tde_key_info();");
+PGTDE::psql($node, 'postgres', "SELECT key_provider_id, key_provider_name, key_name FROM pg_tde_server_key_info();");
+PGTDE::psql($node, 'postgres', 'SELECT * FROM test_enc ORDER BY id ASC;');
 
-$stdout = $node->safe_psql('postgres', "SELECT key_provider_id, key_provider_name, key_name FROM pg_tde_key_info();", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT key_provider_id, key_provider_name, key_name FROM pg_tde_server_key_info();", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-PGTDE::append_to_file($stderr);
-$stdout = $node->safe_psql('postgres', 'SELECT * FROM test_enc ORDER BY id ASC;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-
-#Again rotate key
-$stdout = $node->safe_psql('postgres', "SELECT pg_tde_set_key_using_global_key_provider('rotated-key', 'file-3', false);", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-$stdout = $node->safe_psql('postgres', 'SELECT * FROM test_enc ORDER BY id ASC;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-
-# Restart the server
-PGTDE::append_to_file("-- server restart");
-$rt_value = $node->stop();
+# Again rotate key
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_set_key_using_global_key_provider('rotated-key', 'file-3', false);");
+PGTDE::psql($node, 'postgres', 'SELECT * FROM test_enc ORDER BY id ASC;');
+
+PGTDE::append_to_result_file("-- server restart");
+$node->stop();
 $rt_value = $node->start();
+ok($rt_value == 1, "Restart Server");
 
-$stdout = $node->safe_psql('postgres', "SELECT key_provider_id, key_provider_name, key_name FROM pg_tde_key_info();", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT key_provider_id, key_provider_name, key_name FROM pg_tde_server_key_info();", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-PGTDE::append_to_file($stderr);
-$stdout = $node->safe_psql('postgres', 'SELECT * FROM test_enc ORDER BY id ASC;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', "SELECT key_provider_id, key_provider_name, key_name FROM pg_tde_key_info();");
+PGTDE::psql($node, 'postgres', "SELECT key_provider_id, key_provider_name, key_name FROM pg_tde_server_key_info();");
+PGTDE::psql($node, 'postgres', 'SELECT * FROM test_enc ORDER BY id ASC;');
 
 # TODO: add method to query current info
 # And maybe debug tools to show what's in a file keyring?
 
-#Again rotate key
-$stdout = $node->safe_psql('postgres', "SELECT pg_tde_set_key_using_global_key_provider('rotated-keyX', 'file-2', false);", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-$stdout = $node->safe_psql('postgres', 'SELECT * FROM test_enc ORDER BY id ASC;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+# Again rotate key
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_set_key_using_global_key_provider('rotated-keyX', 'file-2', false);");
+PGTDE::psql($node, 'postgres', 'SELECT * FROM test_enc ORDER BY id ASC;');
 
-# Restart the server
-PGTDE::append_to_file("-- server restart");
-$rt_value = $node->stop();
+PGTDE::append_to_result_file("-- server restart");
+$node->stop();
 $rt_value = $node->start();
+ok($rt_value == 1, "Restart Server");
 
-$stdout = $node->safe_psql('postgres', "SELECT key_provider_id, key_provider_name, key_name FROM pg_tde_key_info();", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT key_provider_id, key_provider_name, key_name FROM pg_tde_server_key_info();", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-PGTDE::append_to_file($stderr);
-$stdout = $node->safe_psql('postgres', 'SELECT * FROM test_enc ORDER BY id ASC;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', "SELECT key_provider_id, key_provider_name, key_name FROM pg_tde_key_info();");
+PGTDE::psql($node, 'postgres', "SELECT key_provider_id, key_provider_name, key_name FROM pg_tde_server_key_info();");
+PGTDE::psql($node, 'postgres', 'SELECT * FROM test_enc ORDER BY id ASC;');
 
-$stdout = $node->safe_psql('postgres', 'ALTER SYSTEM SET pg_tde.inherit_global_providers = OFF;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'ALTER SYSTEM SET pg_tde.inherit_global_providers = OFF;');
 
 # Things still work after a restart
-# Restart the server
-PGTDE::append_to_file("-- server restart");
-$rt_value = $node->stop();
+PGTDE::append_to_result_file("-- server restart");
+$node->stop();
 $rt_value = $node->start();
+ok($rt_value == 1, "Restart Server");
 
 # But now can't be changed to another global provider
-($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT pg_tde_set_key_using_global_key_provider('rotated-keyX2', 'file-2', false);", extra_params => ['-a']);
-PGTDE::append_to_file($stderr);
-$stdout = $node->safe_psql('postgres', "SELECT key_provider_id, key_provider_name, key_name FROM pg_tde_key_info();", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT key_provider_id, key_provider_name, key_name FROM pg_tde_server_key_info();", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-PGTDE::append_to_file($stderr);
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_set_key_using_global_key_provider('rotated-keyX2', 'file-2', false);");
+PGTDE::psql($node, 'postgres', "SELECT key_provider_id, key_provider_name, key_name FROM pg_tde_key_info();");
+PGTDE::psql($node, 'postgres', "SELECT key_provider_id, key_provider_name, key_name FROM pg_tde_server_key_info();");
 
-$stdout = $node->safe_psql('postgres', "SELECT pg_tde_set_key_using_database_key_provider('rotated-key2','file-2');", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-$stdout = $node->safe_psql('postgres', "SELECT key_provider_id, key_provider_name, key_name FROM pg_tde_key_info();", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT key_provider_id, key_provider_name, key_name FROM pg_tde_server_key_info();", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-PGTDE::append_to_file($stderr);
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_set_key_using_database_key_provider('rotated-key2','file-2');");
+PGTDE::psql($node, 'postgres', "SELECT key_provider_id, key_provider_name, key_name FROM pg_tde_key_info();");
+PGTDE::psql($node, 'postgres', "SELECT key_provider_id, key_provider_name, key_name FROM pg_tde_server_key_info();");
 
+PGTDE::psql($node, 'postgres', 'DROP TABLE test_enc;');
 
-# end
+PGTDE::psql($node, 'postgres', 'ALTER SYSTEM RESET pg_tde.inherit_global_providers;');
 
-$stdout = $node->safe_psql('postgres', 'DROP TABLE test_enc;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-
-$stdout = $node->safe_psql('postgres', 'ALTER SYSTEM RESET pg_tde.inherit_global_providers;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-
-$rt_value = $node->stop();
+PGTDE::append_to_result_file("-- server restart");
+$node->stop();
 $rt_value = $node->start();
+ok($rt_value == 1, "Restart Server");
+
+PGTDE::psql($node, 'postgres', 'DROP EXTENSION pg_tde CASCADE;');
 
-# DROP EXTENSION
-($cmdret, $stdout, $stderr) = $node->psql('postgres', 'DROP EXTENSION pg_tde CASCADE;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-PGTDE::append_to_file($stderr);
-# Stop the server
 $node->stop();
 
-# compare the expected and out file
+# Compare the expected and out file
 my $compare = PGTDE->compare_results();
 
-# Test/check if expected and result/out file match. If Yes, test passes.
 is($compare,0,"Compare Files: $PGTDE::expected_filename_with_path and $PGTDE::out_filename_with_path files.");
 
-# Done testing for this testcase file.
 done_testing();
diff --git a/contrib/pg_tde/t/003_remote_config.pl b/contrib/pg_tde/t/003_remote_config.pl
index 40fb1be7c0d72..2cfd35e9052a0 100644
--- a/contrib/pg_tde/t/003_remote_config.pl
+++ b/contrib/pg_tde/t/003_remote_config.pl
@@ -3,16 +3,12 @@
 use strict;
 use warnings;
 use File::Basename;
-use File::Compare;
-use File::Copy;
 use Test::More;
 use lib 't';
 use pgtde;
 
-# Get file name and CREATE out file name and dirs WHERE requried
 PGTDE::setup_files_dir(basename($0));
 
-# CREATE new PostgreSQL node and do initdb
 my $node = PGTDE->pgtde_init_pg();
 my $pgdata = $node->data_dir;
 
@@ -24,7 +20,6 @@ package MyWebServer;
  
 my %dispatch = (
     '/hello' => \&resp_hello,
-    # ...
 );
  
 sub handle_request {
@@ -54,59 +49,45 @@ sub resp_hello {
 }
  
 }
-my $pid = MyWebServer->new(8888)->background();
 
+my $pid = MyWebServer->new(8888)->background();
 
-# UPDATE postgresql.conf to include/load pg_tde library
 open my $conf, '>>', "$pgdata/postgresql.conf";
 print $conf "shared_preload_libraries = 'pg_tde'\n";
 close $conf;
 
-my $rt_value = $node->stop();
-$rt_value = $node->start();
-ok($rt_value == 1, "Restart Server");
+my $rt_value = $node->start();
+ok($rt_value == 1, "Start Server");
 
-my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION IF NOT EXISTS pg_tde;', extra_params => ['-a']);
-ok($cmdret == 0, "CREATE PGTDE EXTENSION");
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'CREATE EXTENSION IF NOT EXISTS pg_tde;');
 
-$rt_value = $node->psql('postgres', "SELECT pg_tde_add_database_key_provider_file('file-provider', json_object( 'type' VALUE 'remote', 'url' VALUE 'http://localhost:8888/hello' ));", extra_params => ['-a']);
-$rt_value = $node->psql('postgres', "SELECT pg_tde_set_key_using_database_key_provider('test-db-key','file-provider');", extra_params => ['-a']);
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_add_database_key_provider_file('file-provider', json_object( 'type' VALUE 'remote', 'url' VALUE 'http://localhost:8888/hello' ));");
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_set_key_using_database_key_provider('test-db-key','file-provider');");
 
-$stdout = $node->safe_psql('postgres', 'CREATE TABLE test_enc2(id SERIAL,k INTEGER,PRIMARY KEY (id)) USING tde_heap;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'CREATE TABLE test_enc2(id SERIAL,k INTEGER,PRIMARY KEY (id)) USING tde_heap;');
 
-$stdout = $node->safe_psql('postgres', 'INSERT INTO test_enc2 (k) VALUES (5),(6);', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'INSERT INTO test_enc2 (k) VALUES (5),(6);');
 
-$stdout = $node->safe_psql('postgres', 'SELECT * FROM test_enc2 ORDER BY id ASC;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'SELECT * FROM test_enc2 ORDER BY id ASC;');
 
-# Restart the server
-PGTDE::append_to_file("-- server restart");
-$rt_value = $node->stop();
+PGTDE::append_to_result_file("-- server restart");
+$node->stop();
 $rt_value = $node->start();
+ok($rt_value == 1, "Restart Server");
+
+PGTDE::psql($node, 'postgres', 'SELECT * FROM test_enc2 ORDER BY id ASC;');
 
-$stdout = $node->safe_psql('postgres', 'SELECT * FROM test_enc2 ORDER BY id ASC;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'DROP TABLE test_enc2;');
 
-$stdout = $node->safe_psql('postgres', 'DROP TABLE test_enc2;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'DROP EXTENSION pg_tde;');
 
-# DROP EXTENSION
-$stdout = $node->safe_psql('postgres', 'DROP EXTENSION pg_tde;', extra_params => ['-a']);
-ok($cmdret == 0, "DROP PGTDE EXTENSION");
-PGTDE::append_to_file($stdout);
-# Stop the server
 $node->stop();
 
 system("kill $pid");
 
-# compare the expected and out file
+# Compare the expected and out file
 my $compare = PGTDE->compare_results();
 
-# Test/check if expected and result/out file match. If Yes, test passes.
 is($compare,0,"Compare Files: $PGTDE::expected_filename_with_path and $PGTDE::out_filename_with_path files.");
 
-# Done testing for this testcase file.
 done_testing();
diff --git a/contrib/pg_tde/t/004_file_config.pl b/contrib/pg_tde/t/004_file_config.pl
index 4bf359d04d5df..8fe8178ce5508 100644
--- a/contrib/pg_tde/t/004_file_config.pl
+++ b/contrib/pg_tde/t/004_file_config.pl
@@ -3,22 +3,15 @@
 use strict;
 use warnings;
 use File::Basename;
-use File::Compare;
-use File::Copy;
 use Test::More;
 use lib 't';
 use pgtde;
 
-# Get file name and CREATE out file name and dirs WHERE requried
 PGTDE::setup_files_dir(basename($0));
 
-# CREATE new PostgreSQL node and do initdb
 my $node = PGTDE->pgtde_init_pg();
 my $pgdata = $node->data_dir;
 
-copy("$pgdata/postgresql.conf", "$pgdata/postgresql.conf.bak");
-
-# UPDATE postgresql.conf to include/load pg_tde library
 open my $conf, '>>', "$pgdata/postgresql.conf";
 print $conf "shared_preload_libraries = 'pg_tde'\n";
 close $conf;
@@ -30,45 +23,33 @@
 my $rt_value = $node->start();
 ok($rt_value == 1, "Start Server");
 
-my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION IF NOT EXISTS pg_tde;', extra_params => ['-a']);
-ok($cmdret == 0, "CREATE PGTDE EXTENSION");
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'CREATE EXTENSION IF NOT EXISTS pg_tde;');
 
-$rt_value = $node->psql('postgres', "SELECT pg_tde_add_database_key_provider_file('file-provider', json_object( 'type' VALUE 'file', 'path' VALUE '/tmp/datafile-location' ));", extra_params => ['-a']);
-$rt_value = $node->psql('postgres', "SELECT pg_tde_set_key_using_database_key_provider('test-db-key','file-provider');", extra_params => ['-a']);
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_add_database_key_provider_file('file-provider', json_object( 'type' VALUE 'file', 'path' VALUE '/tmp/datafile-location' ));");
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_set_key_using_database_key_provider('test-db-key','file-provider');");
 
-$stdout = $node->safe_psql('postgres', 'CREATE TABLE test_enc1(id SERIAL,k INTEGER,PRIMARY KEY (id)) USING tde_heap;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'CREATE TABLE test_enc1(id SERIAL,k INTEGER,PRIMARY KEY (id)) USING tde_heap;');
 
-$stdout = $node->safe_psql('postgres', 'INSERT INTO test_enc1 (k) VALUES (5),(6);', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'INSERT INTO test_enc1 (k) VALUES (5),(6);');
 
-$stdout = $node->safe_psql('postgres', 'SELECT * FROM test_enc1 ORDER BY id ASC;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'SELECT * FROM test_enc1 ORDER BY id ASC;');
 
-# Restart the server
-PGTDE::append_to_file("-- server restart");
-$rt_value = $node->stop();
+PGTDE::append_to_result_file("-- server restart");
+$node->stop();
 $rt_value = $node->start();
+ok($rt_value == 1, "Restart Server");
+
+PGTDE::psql($node, 'postgres', 'SELECT * FROM test_enc1 ORDER BY id ASC;');
 
-$stdout = $node->safe_psql('postgres', 'SELECT * FROM test_enc1 ORDER BY id ASC;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'DROP TABLE test_enc1;');
 
-$stdout = $node->safe_psql('postgres', 'DROP TABLE test_enc1;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'DROP EXTENSION pg_tde;');
 
-# DROP EXTENSION
-$stdout = $node->safe_psql('postgres', 'DROP EXTENSION pg_tde;', extra_params => ['-a']);
-ok($cmdret == 0, "DROP PGTDE EXTENSION");
-PGTDE::append_to_file($stdout);
-# Stop the server
 $node->stop();
 
-# compare the expected and out file
+# Compare the expected and out file
 my $compare = PGTDE->compare_results();
 
-# Test/check if expected and result/out file match. If Yes, test passes.
 is($compare,0,"Compare Files: $PGTDE::expected_filename_with_path and $PGTDE::out_filename_with_path files.");
 
-# Done testing for this testcase file.
 done_testing();
diff --git a/contrib/pg_tde/t/005_multiple_extensions.pl b/contrib/pg_tde/t/005_multiple_extensions.pl
index d3beecb8843fb..309d68a3f2ed3 100644
--- a/contrib/pg_tde/t/005_multiple_extensions.pl
+++ b/contrib/pg_tde/t/005_multiple_extensions.pl
@@ -3,13 +3,10 @@
 use strict;
 use warnings;
 use File::Basename;
-use File::Compare;
-use File::Copy;
 use Test::More;
 use lib 't';
 use pgtde;
 
-# Get file name and CREATE out file name and dirs WHERE requried
 PGTDE::setup_files_dir(basename($0));
 
 my $PG_VERSION_STRING = `pg_config --version`;
@@ -19,13 +16,9 @@
     plan skip_all => "pg_tde test case only for PPG server package install with extensions.";
 }
 
-# CREATE new PostgreSQL node and do initdb
 my $node = PGTDE->pgtde_init_pg();
 my $pgdata = $node->data_dir;
 
-copy("$pgdata/postgresql.conf", "$pgdata/postgresql.conf.bak");
-
-# UPDATE postgresql.conf to include/load pg_stat_monitor library
 open my $conf, '>>', "$pgdata/postgresql.conf";
 print $conf "shared_preload_libraries = 'pg_tde, pg_stat_monitor, pgaudit, set_user, pg_repack'\n";
 print $conf "pg_stat_monitor.pgsm_bucket_time = 360000\n";
@@ -36,7 +29,6 @@
 print $conf2 "/tmp/keyring_data_file\n";
 close $conf2;
 
-# Start server
 my $rt_value = $node->start;
 ok($rt_value == 1, "Start Server");
 
@@ -52,7 +44,7 @@
 # Create pg_tde extension
 ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION IF NOT EXISTS pg_tde;', extra_params => ['-a']);
 ok($cmdret == 0, "CREATE PGTDE EXTENSION");
-PGTDE::append_to_file($stdout);
+PGTDE::append_to_result_file($stdout);
 
 # Create Other extensions
 ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION IF NOT EXISTS IF NOT EXISTS pgaudit;', extra_params => ['-a']);
@@ -90,24 +82,24 @@
 $rt_value = $node->psql('postgres', "SELECT pg_tde_set_key_using_database_key_provider('test-db-key','file-provider');", extra_params => ['-a']);
 
 $stdout = $node->safe_psql('postgres', 'CREATE TABLE test_enc1(id SERIAL,k INTEGER,PRIMARY KEY (id)) USING tde_heap;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::append_to_result_file($stdout);
 
 $stdout = $node->safe_psql('postgres', 'INSERT INTO test_enc1 (k) VALUES (5),(6);', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::append_to_result_file($stdout);
 
 $stdout = $node->safe_psql('postgres', 'SELECT * FROM test_enc1 ORDER BY id ASC;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::append_to_result_file($stdout);
 
-# Restart the server
-PGTDE::append_to_file("-- server restart");
-$rt_value = $node->stop();
+PGTDE::append_to_result_file("-- server restart");
+$node->stop();
 $rt_value = $node->start();
+ok($rt_value == 1, "Restart Server");
 
 $stdout = $node->safe_psql('postgres', 'SELECT * FROM test_enc1 ORDER BY id ASC;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::append_to_result_file($stdout);
 
 $stdout = $node->safe_psql('postgres', 'DROP TABLE test_enc1;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::append_to_result_file($stdout);
 
 # Print PGSM settings 
 ($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT name, setting, unit, context, vartype, source, min_val, max_val, enumvals, boot_val, reset_val, pending_restart FROM pg_settings WHERE name='pg_stat_monitor.pgsm_query_shared_buffer';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
@@ -135,24 +127,19 @@
 ok($cmdret == 0, "SELECT XXX FROM pg_stat_monitor");
 PGTDE::append_to_debug_file($stdout);
 
-# DROP EXTENSION
 $stdout = $node->safe_psql('postgres', 'DROP EXTENSION pg_tde;', extra_params => ['-a']);
 ok($cmdret == 0, "DROP PGTDE EXTENSION");
-PGTDE::append_to_file($stdout);
+PGTDE::append_to_result_file($stdout);
 
-# DROP EXTENSION
 $stdout = $node->safe_psql('postgres', 'DROP EXTENSION pg_stat_monitor;', extra_params => ['-a']);
 ok($cmdret == 0, "DROP PGTDE EXTENSION");
 PGTDE::append_to_debug_file($stdout);
 
-# Stop the server
 $node->stop();
 
-# compare the expected and out file
+# Compare the expected and out file
 my $compare = PGTDE->compare_results();
 
-# Test/check if expected and result/out file match. If Yes, test passes.
 is($compare,0,"Compare Files: $PGTDE::expected_filename_with_path and $PGTDE::out_filename_with_path files.");
 
-# Done testing for this testcase file.
 done_testing();
diff --git a/contrib/pg_tde/t/006_remote_vault_config.pl b/contrib/pg_tde/t/006_remote_vault_config.pl
index c0fb84b3d159c..db50f2e4a69bd 100644
--- a/contrib/pg_tde/t/006_remote_vault_config.pl
+++ b/contrib/pg_tde/t/006_remote_vault_config.pl
@@ -2,18 +2,14 @@
 
 use strict;
 use warnings;
+use Env;
 use File::Basename;
-use File::Compare;
-use File::Copy;
 use Test::More;
 use lib 't';
 use pgtde;
-use Env;
 
-# Get file name and CREATE out file name and dirs WHERE requried
 PGTDE::setup_files_dir(basename($0));
 
-# CREATE new PostgreSQL node and do initdb
 my $node = PGTDE->pgtde_init_pg();
 my $pgdata = $node->data_dir;
 
@@ -26,7 +22,6 @@ package MyWebServer;
 my %dispatch = (
     '/token' => \&resp_token,
     '/url' => \&resp_url,
-    # ...
 );
  
 sub handle_request {
@@ -62,59 +57,45 @@ sub resp_url {
 }
  
 }
-my $pid = MyWebServer->new(8889)->background();
 
+my $pid = MyWebServer->new(8889)->background();
 
-# UPDATE postgresql.conf to include/load pg_tde library
 open my $conf, '>>', "$pgdata/postgresql.conf";
 print $conf "shared_preload_libraries = 'pg_tde'\n";
 close $conf;
 
-my $rt_value = $node->stop();
-$rt_value = $node->start();
-ok($rt_value == 1, "Restart Server");
+my $rt_value = $node->start();
+ok($rt_value == 1, "Start Server");
 
-my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION IF NOT EXISTS pg_tde;', extra_params => ['-a']);
-ok($cmdret == 0, "CREATE PGTDE EXTENSION");
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'CREATE EXTENSION IF NOT EXISTS pg_tde;');
 
-$rt_value = $node->psql('postgres', "SELECT pg_tde_add_database_key_provider_vault_v2('vault-provider', json_object( 'type' VALUE 'remote', 'url' VALUE 'http://localhost:8889/token' ), json_object( 'type' VALUE 'remote', 'url' VALUE 'http://localhost:8889/url' ), to_json('secret'::text), NULL);", extra_params => ['-a']);
-$rt_value = $node->psql('postgres', "SELECT pg_tde_set_key_using_database_key_provider('test-db-key','vault-provider');", extra_params => ['-a']);
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_add_database_key_provider_vault_v2('vault-provider', json_object( 'type' VALUE 'remote', 'url' VALUE 'http://localhost:8889/token' ), json_object( 'type' VALUE 'remote', 'url' VALUE 'http://localhost:8889/url' ), to_json('secret'::text), NULL);");
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_set_key_using_database_key_provider('test-db-key','vault-provider');");
 
-$stdout = $node->safe_psql('postgres', 'CREATE TABLE test_enc2(id SERIAL,k INTEGER,PRIMARY KEY (id)) USING tde_heap;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'CREATE TABLE test_enc2(id SERIAL,k INTEGER,PRIMARY KEY (id)) USING tde_heap;');
 
-$stdout = $node->safe_psql('postgres', 'INSERT INTO test_enc2 (k) VALUES (5),(6);', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'INSERT INTO test_enc2 (k) VALUES (5),(6);');
 
-$stdout = $node->safe_psql('postgres', 'SELECT * FROM test_enc2 ORDER BY id ASC;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'SELECT * FROM test_enc2 ORDER BY id ASC;');
 
-# Restart the server
-PGTDE::append_to_file("-- server restart");
-$rt_value = $node->stop();
+PGTDE::append_to_result_file("-- server restart");
+$node->stop();
 $rt_value = $node->start();
+ok($rt_value == 1, "Restart Server");
+
+PGTDE::psql($node, 'postgres', 'SELECT * FROM test_enc2 ORDER BY id ASC;');
 
-$stdout = $node->safe_psql('postgres', 'SELECT * FROM test_enc2 ORDER BY id ASC;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'DROP TABLE test_enc2;');
 
-$stdout = $node->safe_psql('postgres', 'DROP TABLE test_enc2;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'DROP EXTENSION pg_tde;');
 
-# DROP EXTENSION
-$stdout = $node->safe_psql('postgres', 'DROP EXTENSION pg_tde;', extra_params => ['-a']);
-ok($cmdret == 0, "DROP PGTDE EXTENSION");
-PGTDE::append_to_file($stdout);
-# Stop the server
 $node->stop();
 
 system("kill -9 $pid");
 
-# compare the expected and out file
+# Compare the expected and out file
 my $compare = PGTDE->compare_results();
 
-# Test/check if expected and result/out file match. If Yes, test passes.
 is($compare,0,"Compare Files: $PGTDE::expected_filename_with_path and $PGTDE::out_filename_with_path files.");
 
-# Done testing for this testcase file.
 done_testing();
diff --git a/contrib/pg_tde/t/007_tde_heap.pl b/contrib/pg_tde/t/007_tde_heap.pl
index be006eb7a3898..f2018382f6586 100644
--- a/contrib/pg_tde/t/007_tde_heap.pl
+++ b/contrib/pg_tde/t/007_tde_heap.pl
@@ -3,13 +3,10 @@
 use strict;
 use warnings;
 use File::Basename;
-use File::Compare;
-use File::Copy;
 use Test::More;
 use lib 't';
 use pgtde;
 
-# Get file name and CREATE out file name and dirs WHERE requried
 PGTDE::setup_files_dir(basename($0));
 
 my $PG_VERSION_STRING = `pg_config --version`;
@@ -19,118 +16,86 @@
     plan skip_all => "pg_tde test case only for Percona Server for PostgreSQL";
 }
 
-# CREATE new PostgreSQL node and do initdb
 my $node = PGTDE->pgtde_init_pg();
 my $pgdata = $node->data_dir;
 
-# UPDATE postgresql.conf to include/load pg_tde library
 open my $conf, '>>', "$pgdata/postgresql.conf";
 print $conf "shared_preload_libraries = 'pg_tde'\n";
 close $conf;
 
-# Start server
 my $rt_value = $node->start;
 ok($rt_value == 1, "Start Server");
 
-# CREATE EXTENSION IF NOT EXISTS and change out file permissions
-my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION IF NOT EXISTS pg_tde;', extra_params => ['-a']);
-ok($cmdret == 0, "CREATE PGTDE EXTENSION");
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'CREATE EXTENSION IF NOT EXISTS pg_tde;');
 
+PGTDE::psql($node, 'postgres', 'CREATE TABLE test_enc(id SERIAL,k INTEGER,PRIMARY KEY (id)) USING tde_heap;');
 
-$rt_value = $node->psql('postgres', 'CREATE TABLE test_enc(id SERIAL,k INTEGER,PRIMARY KEY (id)) USING tde_heap;', extra_params => ['-a']);
-ok($rt_value == 3, "Failing query");
-
-
-# Restart the server
-PGTDE::append_to_file("-- server restart");
+PGTDE::append_to_result_file("-- server restart");
 $node->stop();
-
 $rt_value = $node->start();
 ok($rt_value == 1, "Restart Server");
 
-$rt_value = $node->psql('postgres', "SELECT pg_tde_add_database_key_provider_file('file-vault','/tmp/pg_tde_test_keyring.per');", extra_params => ['-a']);
-$rt_value = $node->psql('postgres', "SELECT pg_tde_set_key_using_database_key_provider('test-db-key','file-vault');", extra_params => ['-a']);
-
-
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_add_database_key_provider_file('file-vault','/tmp/pg_tde_test_keyring.per');");
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_set_key_using_database_key_provider('test-db-key','file-vault');");
 
 ######################### test_enc1 (simple create table w tde_heap)
 
+PGTDE::psql($node, 'postgres', 'CREATE TABLE test_enc1(id SERIAL,k VARCHAR(32),PRIMARY KEY (id)) USING tde_heap;');
 
-$stdout = $node->safe_psql('postgres', 'CREATE TABLE test_enc1(id SERIAL,k VARCHAR(32),PRIMARY KEY (id)) USING tde_heap;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'INSERT INTO test_enc1 (k) VALUES (\'foobar\'),(\'barfoo\');');
 
-$stdout = $node->safe_psql('postgres', 'INSERT INTO test_enc1 (k) VALUES (\'foobar\'),(\'barfoo\');', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-
-$stdout = $node->safe_psql('postgres', 'SELECT * FROM test_enc1 ORDER BY id ASC;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'SELECT * FROM test_enc1 ORDER BY id ASC;');
 
 ######################### test_enc2 (create heap + alter to tde_heap)
 
-$stdout = $node->safe_psql('postgres', 'CREATE TABLE test_enc2(id SERIAL,k VARCHAR(32),PRIMARY KEY (id));', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'CREATE TABLE test_enc2(id SERIAL,k VARCHAR(32),PRIMARY KEY (id));');
 
-$stdout = $node->safe_psql('postgres', 'INSERT INTO test_enc2 (k) VALUES (\'foobar\'),(\'barfoo\');', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'INSERT INTO test_enc2 (k) VALUES (\'foobar\'),(\'barfoo\');');
 
-$stdout = $node->safe_psql('postgres', 'ALTER TABLE test_enc2 SET ACCESS METHOD tde_heap;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'ALTER TABLE test_enc2 SET ACCESS METHOD tde_heap;');
 
-$stdout = $node->safe_psql('postgres', 'SELECT * FROM test_enc2 ORDER BY id ASC;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'SELECT * FROM test_enc2 ORDER BY id ASC;');
 
 ######################### test_enc3 (default_table_access_method)
 
-$stdout = $node->safe_psql('postgres', 'SET default_table_access_method = "tde_heap"; CREATE TABLE test_enc3(id SERIAL,k VARCHAR(32),PRIMARY KEY (id));', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'SET default_table_access_method = "tde_heap"; CREATE TABLE test_enc3(id SERIAL,k VARCHAR(32),PRIMARY KEY (id));');
 
-$stdout = $node->safe_psql('postgres', 'INSERT INTO test_enc3 (k) VALUES (\'foobar\'),(\'barfoo\');', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'INSERT INTO test_enc3 (k) VALUES (\'foobar\'),(\'barfoo\');');
 
-$stdout = $node->safe_psql('postgres', 'SELECT * FROM test_enc3 ORDER BY id ASC;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'SELECT * FROM test_enc3 ORDER BY id ASC;');
 
 ######################### test_enc4 (create heap + alter default)
 
-$stdout = $node->safe_psql('postgres', 'CREATE TABLE test_enc4(id SERIAL,k VARCHAR(32),PRIMARY KEY (id)) USING heap;', extra_params => ['-a']);
+PGTDE::psql($node, 'postgres', 'CREATE TABLE test_enc4(id SERIAL,k VARCHAR(32),PRIMARY KEY (id)) USING heap;');
 
-$stdout = $node->safe_psql('postgres', 'INSERT INTO test_enc4 (k) VALUES (\'foobar\'),(\'barfoo\');', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-$stdout = $node->safe_psql('postgres', 'SET default_table_access_method = "tde_heap"; ALTER TABLE test_enc4 SET ACCESS METHOD DEFAULT;', extra_params => ['-a']);
+PGTDE::psql($node, 'postgres', 'INSERT INTO test_enc4 (k) VALUES (\'foobar\'),(\'barfoo\');');
 
-$stdout = $node->safe_psql('postgres', 'SELECT * FROM test_enc4 ORDER BY id ASC;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'SET default_table_access_method = "tde_heap"; ALTER TABLE test_enc4 SET ACCESS METHOD DEFAULT;');
 
+PGTDE::psql($node, 'postgres', 'SELECT * FROM test_enc4 ORDER BY id ASC;');
 
 ######################### test_enc5 (create tde_heap + truncate)
 
-$stdout = $node->safe_psql('postgres', 'CREATE TABLE test_enc5(id SERIAL,k VARCHAR(32),PRIMARY KEY (id)) USING tde_heap;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'CREATE TABLE test_enc5(id SERIAL,k VARCHAR(32),PRIMARY KEY (id)) USING tde_heap;');
 
-$stdout = $node->safe_psql('postgres', 'INSERT INTO test_enc5 (k) VALUES (\'foobar\'),(\'barfoo\');', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'INSERT INTO test_enc5 (k) VALUES (\'foobar\'),(\'barfoo\');');
 
-$stdout = $node->safe_psql('postgres', 'CHECKPOINT;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'CHECKPOINT;');
 
-$stdout = $node->safe_psql('postgres', 'TRUNCATE test_enc5;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'TRUNCATE test_enc5;');
 
-$stdout = $node->safe_psql('postgres', 'INSERT INTO test_enc5 (k) VALUES (\'foobar\'),(\'barfoo\');', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'INSERT INTO test_enc5 (k) VALUES (\'foobar\'),(\'barfoo\');');
 
-$stdout = $node->safe_psql('postgres', 'SELECT * FROM test_enc5 ORDER BY id ASC;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'SELECT * FROM test_enc5 ORDER BY id ASC;');
 
-# Restart the server
-PGTDE::append_to_file("-- server restart");
-$rt_value = $node->stop();
+PGTDE::append_to_result_file("-- server restart");
+$node->stop();
 $rt_value = $node->start();
+ok($rt_value == 1, "Restart Server");
 
 sub verify_table
 {
-    PGTDE::append_to_file('###########################');
+    PGTDE::append_to_result_file('###########################');
 
     my ($table) = @_;
 
@@ -138,16 +103,15 @@ sub verify_table
     $tablefile .= '/';
     $tablefile .= $node->safe_psql('postgres', 'SELECT pg_relation_filepath(\''.$table.'\');');
 
-    $stdout = $node->safe_psql('postgres', 'SELECT * FROM ' . $table . ' ORDER BY id ASC;', extra_params => ['-a']);
-    PGTDE::append_to_file($stdout);
+    PGTDE::psql($node, 'postgres', 'SELECT * FROM ' . $table . ' ORDER BY id ASC;');
 
     my $strings = 'TABLEFILE FOR ' . $table . ' FOUND: ';
     $strings .= `(ls  $tablefile >/dev/null && echo -n yes) || echo -n no`;
-    PGTDE::append_to_file($strings);
+    PGTDE::append_to_result_file($strings);
 
     $strings = 'CONTAINS FOO (should be empty): ';
     $strings .= `strings $tablefile | grep foo`;
-    PGTDE::append_to_file($strings);
+    PGTDE::append_to_result_file($strings);
 }
 
 verify_table('test_enc1');
@@ -163,14 +127,11 @@ sub verify_table
 
 my  $strings = 'TABLEFILE2 FOUND: ';
 $strings .= `(ls  $tablefile2 >/dev/null && echo yes) || echo no`;
-PGTDE::append_to_file($strings);
+PGTDE::append_to_result_file($strings);
 
 $strings = 'CONTAINS FOO (should be empty): ';
 $strings .= `strings $tablefile2 | grep foo`;
-PGTDE::append_to_file($strings);
-
-
-
+PGTDE::append_to_result_file($strings);
 
 # Verify that we can't see the data in the file
 my $tablefile3 = $node->safe_psql('postgres', 'SHOW data_directory;');
@@ -179,14 +140,11 @@ sub verify_table
 
 $strings = 'TABLEFILE3 FOUND: ';
 $strings .= `(ls  $tablefile3 >/dev/null && echo yes) || echo no`;
-PGTDE::append_to_file($strings);
+PGTDE::append_to_result_file($strings);
 
 $strings = 'CONTAINS FOO (should be empty): ';
 $strings .= `strings $tablefile3 | grep foo`;
-PGTDE::append_to_file($strings);
-
-
-
+PGTDE::append_to_result_file($strings);
 
 # Verify that we can't see the data in the file
 my $tablefile4 = $node->safe_psql('postgres', 'SHOW data_directory;');
@@ -195,41 +153,25 @@ sub verify_table
 
 $strings = 'TABLEFILE4 FOUND: ';
 $strings .= `(ls  $tablefile4 >/dev/null && echo yes) || echo no`;
-PGTDE::append_to_file($strings);
+PGTDE::append_to_result_file($strings);
 
 $strings = 'CONTAINS FOO (should be empty): ';
 $strings .= `strings $tablefile4 | grep foo`;
-PGTDE::append_to_file($strings);
-
-
-
-$stdout = $node->safe_psql('postgres', 'DROP TABLE test_enc1;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-
-$stdout = $node->safe_psql('postgres', 'DROP TABLE test_enc2;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-
-$stdout = $node->safe_psql('postgres', 'DROP TABLE test_enc3;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::append_to_result_file($strings);
 
-$stdout = $node->safe_psql('postgres', 'DROP TABLE test_enc4;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'DROP TABLE test_enc1;');
+PGTDE::psql($node, 'postgres', 'DROP TABLE test_enc2;');
+PGTDE::psql($node, 'postgres', 'DROP TABLE test_enc3;');
+PGTDE::psql($node, 'postgres', 'DROP TABLE test_enc4;');
+PGTDE::psql($node, 'postgres', 'DROP TABLE test_enc5;');
 
-$stdout = $node->safe_psql('postgres', 'DROP TABLE test_enc5;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'DROP EXTENSION pg_tde;');
 
-# DROP EXTENSION
-$stdout = $node->safe_psql('postgres', 'DROP EXTENSION pg_tde;', extra_params => ['-a']);
-ok($cmdret == 0, "DROP PGTDE EXTENSION");
-PGTDE::append_to_file($stdout);
-# Stop the server
 $node->stop();
 
-# compare the expected and out file
+# Compare the expected and out file
 my $compare = PGTDE->compare_results();
 
-# Test/check if expected and result/out file match. If Yes, test passes.
 is($compare,0,"Compare Files: $PGTDE::expected_filename_with_path and $PGTDE::out_filename_with_path files.");
 
-# Done testing for this testcase file.
 done_testing();
diff --git a/contrib/pg_tde/t/008_key_rotate_tablespace.pl b/contrib/pg_tde/t/008_key_rotate_tablespace.pl
index 3203da3db72bd..a7e93a693fc53 100644
--- a/contrib/pg_tde/t/008_key_rotate_tablespace.pl
+++ b/contrib/pg_tde/t/008_key_rotate_tablespace.pl
@@ -3,94 +3,65 @@
 use strict;
 use warnings;
 use File::Basename;
-use File::Compare;
-use File::Copy;
 use Test::More;
 use lib 't';
 use pgtde;
 
-# Get file name and CREATE out file name and dirs WHERE requried
 PGTDE::setup_files_dir(basename($0));
 
-my ($cmdret, $stdout);
-
-# CREATE new PostgreSQL node and do initdb
 my $node = PGTDE->pgtde_init_pg();
 my $pgdata = $node->data_dir;
 
-# UPDATE postgresql.conf to include/load pg_tde library
 open my $conf, '>>', "$pgdata/postgresql.conf";
 print $conf "shared_preload_libraries = 'pg_tde'\n";
 close $conf;
 
-# Start server
 my $rt_value = $node->start;
 ok($rt_value == 1, "Start Server");
 
-$node->safe_psql('postgres',
-	q{
-SET allow_in_place_tablespaces = true;
-CREATE TABLESPACE test_tblspace LOCATION '';
-CREATE DATABASE tbc TABLESPACE = test_tblspace;
-});
+PGTDE::psql($node, 'postgres', "SET allow_in_place_tablespaces = true; CREATE TABLESPACE test_tblspace LOCATION '';");
+PGTDE::psql($node, 'postgres', 'CREATE DATABASE tbc TABLESPACE = test_tblspace;');
 
-$stdout = $node->safe_psql('tbc',
-	q{
-CREATE EXTENSION IF NOT EXISTS pg_tde;
-SELECT pg_tde_add_database_key_provider_file('file-vault','/tmp/pg_tde_test_keyring.per');
-SELECT pg_tde_set_key_using_database_key_provider('test-db-key','file-vault');
+PGTDE::psql($node, 'tbc', 'CREATE EXTENSION IF NOT EXISTS pg_tde;');
+PGTDE::psql($node, 'tbc', "SELECT pg_tde_add_database_key_provider_file('file-vault','/tmp/pg_tde_test_keyring.per');");
+PGTDE::psql($node, 'tbc', "SELECT pg_tde_set_key_using_database_key_provider('test-db-key','file-vault');");
 
+PGTDE::psql($node, 'tbc', "
 CREATE TABLE country_table (
      country_id        serial primary key,
      country_name    text unique not null,
      continent        text not null
 ) USING tde_heap;
+");
 
+PGTDE::psql($node, 'tbc', "
 INSERT INTO country_table (country_name, continent)
      VALUES ('Japan', 'Asia'),
             ('UK', 'Europe'),
             ('USA', 'North America');
+");
 
-SELECT * FROM country_table;
-
-}, extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'tbc', 'SELECT * FROM country_table;');
 
+PGTDE::psql($node, 'tbc', "SELECT pg_tde_set_key_using_database_key_provider('new-k', 'file-vault');");
 
-$cmdret = $node->psql('tbc', "SELECT pg_tde_set_key_using_database_key_provider('new-k', 'file-vault');", extra_params => ['-a']);
-ok($cmdret == 0, "ROTATE KEY");
-PGTDE::append_to_file($stdout);
-
-# Restart the server
-PGTDE::append_to_file("-- server restart");
+PGTDE::append_to_result_file("-- server restart");
 $node->stop();
-
 $rt_value = $node->start();
 ok($rt_value == 1, "Restart Server");
 
-$stdout = $node->safe_psql('tbc', 'SELECT * FROM country_table;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'tbc', 'SELECT * FROM country_table;');
 
+PGTDE::psql($node, 'tbc', 'DROP EXTENSION pg_tde CASCADE;');
 
-# DROP EXTENSION
-$stdout = $node->safe_psql('tbc', 'DROP EXTENSION pg_tde CASCADE;', extra_params => ['-a']);
-ok($cmdret == 0, "DROP PGTDE EXTENSION");
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'DROP DATABASE tbc;');
+PGTDE::psql($node, 'postgres', 'DROP TABLESPACE test_tblspace;');
 
-$stdout = $node->safe_psql('postgres', q{
-DROP DATABASE tbc;
-DROP TABLESPACE test_tblspace;
-}, extra_params => ['-a']);
-ok($cmdret == 0, "DROP DATABSE");
-PGTDE::append_to_file($stdout);
-# Stop the server
 $node->stop();
 
-# compare the expected and out file
+# Compare the expected and out file
 my $compare = PGTDE->compare_results();
 
-# Test/check if expected and result/out file match. If Yes, test passes.
 is($compare,0,"Compare Files: $PGTDE::expected_filename_with_path and $PGTDE::out_filename_with_path files.");
 
-# Done testing for this testcase file.
 done_testing();
diff --git a/contrib/pg_tde/t/009_wal_encrypt.pl b/contrib/pg_tde/t/009_wal_encrypt.pl
index 88fece2e24d58..4528a34445427 100644
--- a/contrib/pg_tde/t/009_wal_encrypt.pl
+++ b/contrib/pg_tde/t/009_wal_encrypt.pl
@@ -3,20 +3,15 @@
 use strict;
 use warnings;
 use File::Basename;
-use File::Compare;
-use File::Copy;
 use Test::More;
 use lib 't';
 use pgtde;
 
-# Get file name and CREATE out file name and dirs WHERE requried
 PGTDE::setup_files_dir(basename($0));
 
-# CREATE new PostgreSQL node and do initdb
 my $node = PGTDE->pgtde_init_pg();
 my $pgdata = $node->data_dir;
 
-# UPDATE postgresql.conf to include/load pg_tde library
 open my $conf, '>>', "$pgdata/postgresql.conf";
 print $conf "shared_preload_libraries = 'pg_tde'\n";
 print $conf "wal_level = 'logical'\n";
@@ -27,93 +22,69 @@
 my $rt_value = $node->start;
 ok($rt_value == 1, "Start Server");
 
-my $stdout = $node->safe_psql('postgres', "CREATE EXTENSION IF NOT EXISTS pg_tde;", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', "CREATE EXTENSION IF NOT EXISTS pg_tde;");
 
-$stdout = $node->safe_psql('postgres', "SELECT pg_tde_add_global_key_provider_file('file-keyring-010','/tmp/pg_tde_test_keyring010.per');", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_add_global_key_provider_file('file-keyring-010','/tmp/pg_tde_test_keyring010.per');");
 
-$stdout = $node->safe_psql('postgres', "SELECT pg_tde_set_server_key_using_global_key_provider('server-key', 'file-keyring-010');", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_set_server_key_using_global_key_provider('server-key', 'file-keyring-010');");
 
-$stdout = $node->safe_psql('postgres', 'ALTER SYSTEM SET pg_tde.wal_encrypt = on;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'ALTER SYSTEM SET pg_tde.wal_encrypt = on;');
 
-# Restart the server, it should work with encryption now
-PGTDE::append_to_file("-- server restart with wal encryption");
+PGTDE::append_to_result_file("-- server restart with wal encryption");
 $node->stop();
 $rt_value = $node->start();
 ok($rt_value == 1, "Restart Server");
 
-$stdout = $node->safe_psql('postgres', "SHOW pg_tde.wal_encrypt;", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', "SHOW pg_tde.wal_encrypt;");
 
-$stdout = $node->safe_psql('postgres', "SELECT slot_name FROM pg_create_logical_replication_slot('tde_slot', 'test_decoding');", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', "SELECT slot_name FROM pg_create_logical_replication_slot('tde_slot', 'test_decoding');");
 
-$stdout = $node->safe_psql('postgres', 'CREATE TABLE test_wal (id SERIAL, k INTEGER, PRIMARY KEY (id));', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'CREATE TABLE test_wal (id SERIAL, k INTEGER, PRIMARY KEY (id));');
 
-$stdout = $node->safe_psql('postgres', 'INSERT INTO test_wal (k) VALUES (1), (2);', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'INSERT INTO test_wal (k) VALUES (1), (2);');
 
-$stdout = $node->safe_psql('postgres', 'ALTER SYSTEM SET pg_tde.wal_encrypt = off;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'ALTER SYSTEM SET pg_tde.wal_encrypt = off;');
 
-PGTDE::append_to_file("-- server restart without wal encryption");
+PGTDE::append_to_result_file("-- server restart without wal encryption");
 $node->stop();
 $rt_value = $node->start();
 ok($rt_value == 1, "Restart Server");
 
-$stdout = $node->safe_psql('postgres', "SHOW pg_tde.wal_encrypt;", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', "SHOW pg_tde.wal_encrypt;");
 
-$stdout = $node->safe_psql('postgres', 'INSERT INTO test_wal (k) VALUES (3), (4);', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'INSERT INTO test_wal (k) VALUES (3), (4);');
 
-$stdout = $node->safe_psql('postgres', 'ALTER SYSTEM SET pg_tde.wal_encrypt = on;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'ALTER SYSTEM SET pg_tde.wal_encrypt = on;');
 
-
-PGTDE::append_to_file("-- server restart with wal encryption");
+PGTDE::append_to_result_file("-- server restart with wal encryption");
 $node->stop();
 $rt_value = $node->start();
 ok($rt_value == 1, "Restart Server");
 
-$stdout = $node->safe_psql('postgres', "SHOW pg_tde.wal_encrypt;", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', "SHOW pg_tde.wal_encrypt;");
 
-$stdout = $node->safe_psql('postgres', 'INSERT INTO test_wal (k) VALUES (5), (6);', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'INSERT INTO test_wal (k) VALUES (5), (6);');
 
-PGTDE::append_to_file("-- server restart with still wal encryption");
+PGTDE::append_to_result_file("-- server restart with still wal encryption");
 $node->stop();
 $rt_value = $node->start();
 ok($rt_value == 1, "Restart Server");
 
-$stdout = $node->safe_psql('postgres', "SHOW pg_tde.wal_encrypt;", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', "SHOW pg_tde.wal_encrypt;");
+
+PGTDE::psql($node, 'postgres', 'INSERT INTO test_wal (k) VALUES (7), (8);');
 
-$stdout = $node->safe_psql('postgres', 'INSERT INTO test_wal (k) VALUES (7), (8);', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', "SELECT data FROM pg_logical_slot_get_changes('tde_slot', NULL, NULL);");
 
-$stdout = $node->safe_psql('postgres', "SELECT data FROM pg_logical_slot_get_changes('tde_slot', NULL, NULL);", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', "SELECT pg_drop_replication_slot('tde_slot');");
 
-$stdout = $node->safe_psql('postgres', "SELECT pg_drop_replication_slot('tde_slot');", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'DROP EXTENSION pg_tde;');
 
-# DROP EXTENSION
-$stdout = $node->safe_psql('postgres', 'DROP EXTENSION pg_tde;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-# Stop the server
 $node->stop();
 
-# compare the expected and out file
+# Compare the expected and out file
 my $compare = PGTDE->compare_results();
 
-# Test/check if expected and result/out file match. If Yes, test passes.
 is($compare,0,"Compare Files: $PGTDE::expected_filename_with_path and $PGTDE::out_filename_with_path files.");
 
-# Done testing for this testcase file.
 done_testing();
diff --git a/contrib/pg_tde/t/010_change_key_provider.pl b/contrib/pg_tde/t/010_change_key_provider.pl
index a59ecab9d7dad..c94f82089b4a5 100644
--- a/contrib/pg_tde/t/010_change_key_provider.pl
+++ b/contrib/pg_tde/t/010_change_key_provider.pl
@@ -3,20 +3,16 @@
 use strict;
 use warnings;
 use File::Basename;
-use File::Compare;
 use File::Copy;
 use Test::More;
 use lib 't';
 use pgtde;
 
-# Get file name and CREATE out file name and dirs WHERE requried
 PGTDE::setup_files_dir(basename($0));
 
-# CREATE new PostgreSQL node and do initdb
 my $node = PGTDE->pgtde_init_pg();
 my $pgdata = $node->data_dir;
 
-# UPDATE postgresql.conf to include/load pg_tde library
 open my $conf, '>>', "$pgdata/postgresql.conf";
 print $conf "shared_preload_libraries = 'pg_tde'\n";
 close $conf;
@@ -26,182 +22,115 @@
 unlink('/tmp/change_key_provider_3.per');
 unlink('/tmp/change_key_provider_4.per');
 
-# Start server
 my $rt_value = $node->start;
 ok($rt_value == 1, "Start Server");
 
-# CREATE EXTENSION IF NOT EXISTS and change out file permissions
-my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION IF NOT EXISTS pg_tde;', extra_params => ['-a']);
-ok($cmdret == 0, "CREATE PGTDE EXTENSION");
-PGTDE::append_to_file($stdout);
-
-$stdout = $node->safe_psql('postgres', "SELECT pg_tde_add_database_key_provider_file('file-vault', '/tmp/change_key_provider_1.per');", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-$stdout = $node->safe_psql('postgres', "SELECT pg_tde_list_all_database_key_providers();", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-$stdout = $node->safe_psql('postgres', "SELECT pg_tde_set_key_using_database_key_provider('test-key', 'file-vault');", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-
-$stdout = $node->safe_psql('postgres', 'CREATE TABLE test_enc (id serial, k integer, PRIMARY KEY (id)) USING tde_heap;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-$stdout = $node->safe_psql('postgres', 'INSERT INTO test_enc (k) VALUES (5), (6);', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-
-$stdout = $node->safe_psql('postgres', "SELECT pg_tde_verify_key();", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-$stdout = $node->safe_psql('postgres', "SELECT pg_tde_is_encrypted('test_enc');", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-$stdout = $node->safe_psql('postgres', 'SELECT * FROM test_enc ORDER BY id;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'CREATE EXTENSION IF NOT EXISTS pg_tde;');
+
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_add_database_key_provider_file('file-vault', '/tmp/change_key_provider_1.per');");
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_list_all_database_key_providers();");
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_set_key_using_database_key_provider('test-key', 'file-vault');");
+
+PGTDE::psql($node, 'postgres', 'CREATE TABLE test_enc (id serial, k integer, PRIMARY KEY (id)) USING tde_heap;');
+PGTDE::psql($node, 'postgres', 'INSERT INTO test_enc (k) VALUES (5), (6);');
+
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_verify_key();");
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_is_encrypted('test_enc');");
+PGTDE::psql($node, 'postgres', 'SELECT * FROM test_enc ORDER BY id;');
 
 # Change provider and move file
-PGTDE::append_to_file("-- mv /tmp/change_key_provider_1.per /tmp/change_key_provider_2.per");
+PGTDE::append_to_result_file("-- mv /tmp/change_key_provider_1.per /tmp/change_key_provider_2.per");
 move('/tmp/change_key_provider_1.per', '/tmp/change_key_provider_2.per');
-$stdout = $node->safe_psql('postgres', "SELECT pg_tde_change_database_key_provider_file('file-vault', '/tmp/change_key_provider_2.per');", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-$stdout = $node->safe_psql('postgres', "SELECT pg_tde_list_all_database_key_providers();", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-
-$stdout = $node->safe_psql('postgres', "SELECT pg_tde_verify_key();", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-$stdout = $node->safe_psql('postgres', "SELECT pg_tde_is_encrypted('test_enc');", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-$stdout = $node->safe_psql('postgres', 'SELECT * FROM test_enc ORDER BY id;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-
-# Restart the server
-PGTDE::append_to_file("-- server restart");
-$rt_value = $node->stop();
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_change_database_key_provider_file('file-vault', '/tmp/change_key_provider_2.per');");
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_list_all_database_key_providers();");
+
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_verify_key();");
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_is_encrypted('test_enc');");
+PGTDE::psql($node, 'postgres', 'SELECT * FROM test_enc ORDER BY id;');
+
+PGTDE::append_to_result_file("-- server restart");
+$node->stop();
 $rt_value = $node->start();
+ok($rt_value == 1, "Restart Server");
 
 # Verify
-$stdout = $node->safe_psql('postgres', "SELECT pg_tde_verify_key();", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-$stdout = $node->safe_psql('postgres', "SELECT pg_tde_is_encrypted('test_enc');", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-$stdout = $node->safe_psql('postgres', 'SELECT * FROM test_enc ORDER BY id;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_verify_key();");
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_is_encrypted('test_enc');");
+PGTDE::psql($node, 'postgres', 'SELECT * FROM test_enc ORDER BY id;');
 
 # Change provider and do not move file
-$stdout = $node->safe_psql('postgres', "SELECT pg_tde_change_database_key_provider_file('file-vault', '/tmp/change_key_provider_3.per');", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-$stdout = $node->safe_psql('postgres', "SELECT pg_tde_list_all_database_key_providers();", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-
-(undef, $stdout, $stderr) = $node->psql('postgres', "SELECT pg_tde_verify_key();", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-PGTDE::append_to_file($stderr);
-$stdout = $node->safe_psql('postgres', "SELECT pg_tde_is_encrypted('test_enc');", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-$stdout = $node->safe_psql('postgres', 'SELECT * FROM test_enc ORDER BY id;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-
-# Restart the server
-PGTDE::append_to_file("-- server restart");
-$rt_value = $node->stop();
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_change_database_key_provider_file('file-vault', '/tmp/change_key_provider_3.per');");
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_list_all_database_key_providers();");
+
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_verify_key();");
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_is_encrypted('test_enc');");
+PGTDE::psql($node, 'postgres', 'SELECT * FROM test_enc ORDER BY id;');
+
+PGTDE::append_to_result_file("-- server restart");
+$node->stop();
 $rt_value = $node->start();
+ok($rt_value == 1, "Restart Server");
 
 # Verify
-(undef, $stdout, $stderr) = $node->psql('postgres', "SELECT pg_tde_verify_key();", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-PGTDE::append_to_file($stderr);
-(undef, $stdout, $stderr) = $node->psql('postgres', "SELECT pg_tde_is_encrypted('test_enc');", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-PGTDE::append_to_file($stderr);
-(undef, $stdout, $stderr) = $node->psql('postgres', 'SELECT * FROM test_enc ORDER BY id;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-PGTDE::append_to_file($stderr);
-
-PGTDE::append_to_file("-- mv /tmp/change_key_provider_2.per /tmp/change_key_provider_3.per");
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_verify_key();");
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_is_encrypted('test_enc');");
+PGTDE::psql($node, 'postgres', 'SELECT * FROM test_enc ORDER BY id;');
+
+PGTDE::append_to_result_file("-- mv /tmp/change_key_provider_2.per /tmp/change_key_provider_3.per");
 move('/tmp/change_key_provider_2.per', '/tmp/change_key_provider_3.per');
 
-# Restart the server
-PGTDE::append_to_file("-- server restart");
-$rt_value = $node->stop();
+PGTDE::append_to_result_file("-- server restart");
+$node->stop();
 $rt_value = $node->start();
+ok($rt_value == 1, "Restart Server");
 
 # Verify
-$stdout = $node->safe_psql('postgres', "SELECT pg_tde_verify_key();", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-$stdout = $node->safe_psql('postgres', "SELECT pg_tde_is_encrypted('test_enc');", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-$stdout = $node->safe_psql('postgres', 'SELECT * FROM test_enc ORDER BY id;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-
-# DROP EXTENSION
-(undef, $stdout, $stderr) = $node->psql('postgres', 'DROP EXTENSION pg_tde CASCADE;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-PGTDE::append_to_file($stderr);
-
-# CREATE EXTENSION
-($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION IF NOT EXISTS pg_tde;', extra_params => ['-a']);
-ok($cmdret == 0, "CREATE PGTDE EXTENSION");
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_verify_key();");
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_is_encrypted('test_enc');");
+PGTDE::psql($node, 'postgres', 'SELECT * FROM test_enc ORDER BY id;');
+
+PGTDE::psql($node, 'postgres', 'DROP EXTENSION pg_tde CASCADE;');
+
+PGTDE::psql($node, 'postgres', 'CREATE EXTENSION IF NOT EXISTS pg_tde;');
 
 # Change provider and generate a new principal key
-$stdout = $node->safe_psql('postgres', "SELECT pg_tde_add_database_key_provider_file('file-vault', '/tmp/change_key_provider_4.per');", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-$stdout = $node->psql('postgres', "SELECT pg_tde_set_key_using_database_key_provider('test-key', 'file-vault');", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-
-$stdout = $node->safe_psql('postgres', 'CREATE TABLE test_enc (id serial, k integer, PRIMARY KEY (id)) USING tde_heap;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-$stdout = $node->safe_psql('postgres', 'INSERT INTO test_enc (k) VALUES (5), (6);', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-
-$stdout = $node->safe_psql('postgres', "SELECT pg_tde_verify_key();", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-$stdout = $node->safe_psql('postgres', "SELECT pg_tde_is_encrypted('test_enc');", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-$stdout = $node->safe_psql('postgres', 'SELECT * FROM test_enc ORDER BY id;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-
-$stdout = $node->safe_psql('postgres', "SELECT pg_tde_change_database_key_provider_file('file-vault', '/tmp/change_key_provider_3.per');", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-
-# Restart the server
-PGTDE::append_to_file("-- server restart");
-$rt_value = $node->stop();
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_add_database_key_provider_file('file-vault', '/tmp/change_key_provider_4.per');");
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_set_key_using_database_key_provider('test-key', 'file-vault');");
+
+PGTDE::psql($node, 'postgres', 'CREATE TABLE test_enc (id serial, k integer, PRIMARY KEY (id)) USING tde_heap;');
+PGTDE::psql($node, 'postgres', 'INSERT INTO test_enc (k) VALUES (5), (6);');
+
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_verify_key();");
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_is_encrypted('test_enc');");
+PGTDE::psql($node, 'postgres', 'SELECT * FROM test_enc ORDER BY id;');
+
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_change_database_key_provider_file('file-vault', '/tmp/change_key_provider_3.per');");
+
+PGTDE::append_to_result_file("-- server restart");
+$node->stop();
 $rt_value = $node->start();
+ok($rt_value == 1, "Restart Server");
 
 # Verify
-(undef, $stdout, $stderr) = $node->psql('postgres', "SELECT pg_tde_verify_key();", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-PGTDE::append_to_file($stderr);
-(undef, $stdout, $stderr) = $node->psql('postgres', "SELECT pg_tde_is_encrypted('test_enc');", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-PGTDE::append_to_file($stderr);
-(undef, $stdout, $stderr) = $node->psql('postgres', 'SELECT * FROM test_enc ORDER BY id;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-PGTDE::append_to_file($stderr);
-(undef, $stdout, $stderr) = $node->psql('postgres', 'CREATE TABLE test_enc2 (id serial, k integer, PRIMARY KEY (id)) USING tde_heap;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-PGTDE::append_to_file($stderr);
-
-$stdout = $node->safe_psql('postgres', "SELECT pg_tde_change_database_key_provider_file('file-vault', '/tmp/change_key_provider_4.per');", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_verify_key();");
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_is_encrypted('test_enc');");
+PGTDE::psql($node, 'postgres', 'SELECT * FROM test_enc ORDER BY id;');
+PGTDE::psql($node, 'postgres', 'CREATE TABLE test_enc2 (id serial, k integer, PRIMARY KEY (id)) USING tde_heap;');
+
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_change_database_key_provider_file('file-vault', '/tmp/change_key_provider_4.per');");
 
 # Verify
-$stdout = $node->safe_psql('postgres', "SELECT pg_tde_verify_key();", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-$stdout = $node->safe_psql('postgres', "SELECT pg_tde_is_encrypted('test_enc');", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-$stdout = $node->safe_psql('postgres', 'SELECT * FROM test_enc ORDER BY id;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-
-# DROP EXTENSION
-(undef, $stdout, $stderr) = $node->psql('postgres', 'DROP EXTENSION pg_tde CASCADE;', extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-PGTDE::append_to_file($stderr);
-
-# Stop the server
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_verify_key();");
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_is_encrypted('test_enc');");
+PGTDE::psql($node, 'postgres', 'SELECT * FROM test_enc ORDER BY id;');
+
+PGTDE::psql($node, 'postgres', 'DROP EXTENSION pg_tde CASCADE;');
+
 $node->stop();
 
-# compare the expected and out file
+# Compare the expected and out file
 my $compare = PGTDE->compare_results();
 
-# Test/check if expected and result/out file match. If Yes, test passes.
 is($compare, 0, "Compare Files: $PGTDE::expected_filename_with_path and $PGTDE::out_filename_with_path files.");
 
-# Done testing for this testcase file.
 done_testing();
diff --git a/contrib/pg_tde/t/011_unlogged_tables.pl b/contrib/pg_tde/t/011_unlogged_tables.pl
index 22e7c5f10c680..fcfa26addb672 100644
--- a/contrib/pg_tde/t/011_unlogged_tables.pl
+++ b/contrib/pg_tde/t/011_unlogged_tables.pl
@@ -3,67 +3,48 @@
 use strict;
 use warnings;
 use File::Basename;
-use File::Compare;
-use File::Copy;
 use Test::More;
 use lib 't';
 use pgtde;
 
-# Get file name and CREATE out file name and dirs WHERE requried
 PGTDE::setup_files_dir(basename($0));
 
-# CREATE new PostgreSQL node and do initdb
 my $node = PGTDE->pgtde_init_pg();
 my $pgdata = $node->data_dir;
 
-# UPDATE postgresql.conf to include/load pg_tde library
 open my $conf, '>>', "$pgdata/postgresql.conf";
 print $conf "shared_preload_libraries = 'pg_tde'\n";
 close $conf;
 
-# Start server
 my $rt_value = $node->start;
 ok($rt_value == 1, "Start Server");
 
-my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION IF NOT EXISTS pg_tde;', extra_params => ['-a']);
-ok($cmdret == 0, "CREATE PGTDE EXTENSION");
-PGTDE::append_to_file($stdout);
-$stdout = $node->safe_psql('postgres', "SELECT pg_tde_add_database_key_provider_file('file-vault', '/tmp/unlogged_tables.per');", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
-$stdout = $node->safe_psql('postgres', "SELECT pg_tde_set_key_using_database_key_provider('test-key', 'file-vault');", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', 'CREATE EXTENSION IF NOT EXISTS pg_tde;');
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_add_database_key_provider_file('file-vault', '/tmp/unlogged_tables.per');");
+PGTDE::psql($node, 'postgres', "SELECT pg_tde_set_key_using_database_key_provider('test-key', 'file-vault');");
 
-$stdout = $node->safe_psql('postgres', "CREATE UNLOGGED TABLE t (x int PRIMARY KEY) USING tde_heap;", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', "CREATE UNLOGGED TABLE t (x int PRIMARY KEY) USING tde_heap;");
 
-$stdout = $node->safe_psql('postgres', "INSERT INTO t SELECT generate_series(1, 4);", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', "INSERT INTO t SELECT generate_series(1, 4);");
 
-$stdout = $node->safe_psql('postgres', "CHECKPOINT;", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', "CHECKPOINT;");
 
-PGTDE::append_to_file("-- kill -9");
+PGTDE::append_to_result_file("-- kill -9");
 $node->kill9();
 
-# Start server
-PGTDE::append_to_file("-- server start");
+PGTDE::append_to_result_file("-- server start");
 $rt_value = $node->start;
 ok($rt_value == 1, "Start Server");
 
-$stdout = $node->safe_psql('postgres', "TABLE t;", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', "TABLE t;");
 
-$stdout = $node->safe_psql('postgres', "INSERT INTO t SELECT generate_series(1, 4);", extra_params => ['-a']);
-PGTDE::append_to_file($stdout);
+PGTDE::psql($node, 'postgres', "INSERT INTO t SELECT generate_series(1, 4);");
 
-# Stop the server
 $node->stop();
 
-# compare the expected and out file
+# Compare the expected and out file
 my $compare = PGTDE->compare_results();
 
-# Test/check if expected and result/out file match. If Yes, test passes.
 is($compare, 0, "Compare Files: $PGTDE::expected_filename_with_path and $PGTDE::out_filename_with_path files.");
 
-# Done testing for this testcase file.
 done_testing();
diff --git a/contrib/pg_tde/t/expected/001_basic.out b/contrib/pg_tde/t/expected/001_basic.out
index 0ea866e83ebc8..c1e385741b99f 100644
--- a/contrib/pg_tde/t/expected/001_basic.out
+++ b/contrib/pg_tde/t/expected/001_basic.out
@@ -1,16 +1,43 @@
 CREATE EXTENSION IF NOT EXISTS pg_tde;
 SELECT extname, extversion FROM pg_extension WHERE extname = 'pg_tde';
-pg_tde|1.0-rc
+ extname | extversion 
+---------+------------
+ pg_tde  | 1.0-rc
+(1 row)
+
+CREATE TABLE test_enc(id SERIAL,k INTEGER,PRIMARY KEY (id)) USING tde_heap;
+psql:<stdin>:1: ERROR:  principal key not configured
+HINT:  create one using pg_tde_set_key before using encrypted tables
 -- server restart
+SELECT pg_tde_add_database_key_provider_file('file-vault','/tmp/pg_tde_test_keyring.per');
+ pg_tde_add_database_key_provider_file 
+---------------------------------------
+                                     1
+(1 row)
+
+SELECT pg_tde_set_key_using_database_key_provider('test-db-key','file-vault');
+ pg_tde_set_key_using_database_key_provider 
+--------------------------------------------
+ 
+(1 row)
+
 CREATE TABLE test_enc(id SERIAL,k VARCHAR(32),PRIMARY KEY (id)) USING tde_heap;
 INSERT INTO test_enc (k) VALUES ('foobar'),('barfoo');
 SELECT * FROM test_enc ORDER BY id ASC;
-1|foobar
-2|barfoo
+ id |   k    
+----+--------
+  1 | foobar
+  2 | barfoo
+(2 rows)
+
 -- server restart
 SELECT * FROM test_enc ORDER BY id ASC;
-1|foobar
-2|barfoo
+ id |   k    
+----+--------
+  1 | foobar
+  2 | barfoo
+(2 rows)
+
 TABLEFILE FOUND: yes
 
 CONTAINS FOO (should be empty): 
diff --git a/contrib/pg_tde/t/expected/002_rotate_key.out b/contrib/pg_tde/t/expected/002_rotate_key.out
index 19f435e287eb8..12129902d2d3d 100644
--- a/contrib/pg_tde/t/expected/002_rotate_key.out
+++ b/contrib/pg_tde/t/expected/002_rotate_key.out
@@ -1,94 +1,203 @@
 CREATE EXTENSION IF NOT EXISTS pg_tde;
+CREATE TABLE test_enc(id SERIAL,k INTEGER,PRIMARY KEY (id)) USING tde_heap;
+psql:<stdin>:1: ERROR:  principal key not configured
+HINT:  create one using pg_tde_set_key before using encrypted tables
 -- server restart
 SELECT pg_tde_add_database_key_provider_file('file-vault','/tmp/pg_tde_test_keyring.per');
-1
+ pg_tde_add_database_key_provider_file 
+---------------------------------------
+                                     1
+(1 row)
+
 SELECT pg_tde_add_database_key_provider_file('file-2','/tmp/pg_tde_test_keyring_2.per');
-2
+ pg_tde_add_database_key_provider_file 
+---------------------------------------
+                                     2
+(1 row)
+
 SELECT pg_tde_add_global_key_provider_file('file-2','/tmp/pg_tde_test_keyring_2g.per');
--1
+ pg_tde_add_global_key_provider_file 
+-------------------------------------
+                                  -1
+(1 row)
+
 SELECT pg_tde_add_global_key_provider_file('file-3','/tmp/pg_tde_test_keyring_3.per');
--2
+ pg_tde_add_global_key_provider_file 
+-------------------------------------
+                                  -2
+(1 row)
+
 SELECT pg_tde_list_all_database_key_providers();
-(1,file-vault,file,"{""type"" : ""file"", ""path"" : ""/tmp/pg_tde_test_keyring.per""}")
-(2,file-2,file,"{""type"" : ""file"", ""path"" : ""/tmp/pg_tde_test_keyring_2.per""}")
+                          pg_tde_list_all_database_key_providers                          
+------------------------------------------------------------------------------------------
+ (1,file-vault,file,"{""type"" : ""file"", ""path"" : ""/tmp/pg_tde_test_keyring.per""}")
+ (2,file-2,file,"{""type"" : ""file"", ""path"" : ""/tmp/pg_tde_test_keyring_2.per""}")
+(2 rows)
+
 SELECT pg_tde_set_key_using_database_key_provider('test-db-key','file-vault');
+ pg_tde_set_key_using_database_key_provider 
+--------------------------------------------
+ 
+(1 row)
 
 CREATE TABLE test_enc(id SERIAL,k INTEGER,PRIMARY KEY (id)) USING tde_heap;
 INSERT INTO test_enc (k) VALUES (5),(6);
 SELECT * FROM test_enc ORDER BY id ASC;
-1|5
-2|6
-0
+ id | k 
+----+---
+  1 | 5
+  2 | 6
+(2 rows)
+
+SELECT pg_tde_set_key_using_database_key_provider('rotated-key1');
+ pg_tde_set_key_using_database_key_provider 
+--------------------------------------------
+ 
+(1 row)
+
 SELECT * FROM test_enc ORDER BY id ASC;
-1|5
-2|6
+ id | k 
+----+---
+  1 | 5
+  2 | 6
+(2 rows)
+
 -- server restart
 SELECT key_provider_id, key_provider_name, key_name FROM pg_tde_key_info();
-1|file-vault|rotated-key1
+ key_provider_id | key_provider_name |   key_name   
+-----------------+-------------------+--------------
+               1 | file-vault        | rotated-key1
+(1 row)
+
 SELECT key_provider_id, key_provider_name, key_name FROM pg_tde_server_key_info();
 psql:<stdin>:1: ERROR:  Principal key does not exists for the database
 HINT:  Use set_key interface to set the principal key
 SELECT * FROM test_enc ORDER BY id ASC;
-1|5
-2|6
+ id | k 
+----+---
+  1 | 5
+  2 | 6
+(2 rows)
+
 SELECT pg_tde_set_key_using_database_key_provider('rotated-key2','file-2');
+ pg_tde_set_key_using_database_key_provider 
+--------------------------------------------
+ 
+(1 row)
 
 SELECT * FROM test_enc ORDER BY id ASC;
-1|5
-2|6
+ id | k 
+----+---
+  1 | 5
+  2 | 6
+(2 rows)
+
 -- server restart
 SELECT key_provider_id, key_provider_name, key_name FROM pg_tde_key_info();
-2|file-2|rotated-key2
+ key_provider_id | key_provider_name |   key_name   
+-----------------+-------------------+--------------
+               2 | file-2            | rotated-key2
+(1 row)
+
 SELECT key_provider_id, key_provider_name, key_name FROM pg_tde_server_key_info();
 psql:<stdin>:1: ERROR:  Principal key does not exists for the database
 HINT:  Use set_key interface to set the principal key
 SELECT * FROM test_enc ORDER BY id ASC;
-1|5
-2|6
+ id | k 
+----+---
+  1 | 5
+  2 | 6
+(2 rows)
+
 SELECT pg_tde_set_key_using_global_key_provider('rotated-key', 'file-3', false);
+ pg_tde_set_key_using_global_key_provider 
+------------------------------------------
+ 
+(1 row)
 
 SELECT * FROM test_enc ORDER BY id ASC;
-1|5
-2|6
+ id | k 
+----+---
+  1 | 5
+  2 | 6
+(2 rows)
+
 -- server restart
 SELECT key_provider_id, key_provider_name, key_name FROM pg_tde_key_info();
--2|file-3|rotated-key
+ key_provider_id | key_provider_name |  key_name   
+-----------------+-------------------+-------------
+              -2 | file-3            | rotated-key
+(1 row)
+
 SELECT key_provider_id, key_provider_name, key_name FROM pg_tde_server_key_info();
 psql:<stdin>:1: ERROR:  Principal key does not exists for the database
 HINT:  Use set_key interface to set the principal key
 SELECT * FROM test_enc ORDER BY id ASC;
-1|5
-2|6
+ id | k 
+----+---
+  1 | 5
+  2 | 6
+(2 rows)
+
 SELECT pg_tde_set_key_using_global_key_provider('rotated-keyX', 'file-2', false);
+ pg_tde_set_key_using_global_key_provider 
+------------------------------------------
+ 
+(1 row)
 
 SELECT * FROM test_enc ORDER BY id ASC;
-1|5
-2|6
+ id | k 
+----+---
+  1 | 5
+  2 | 6
+(2 rows)
+
 -- server restart
 SELECT key_provider_id, key_provider_name, key_name FROM pg_tde_key_info();
--1|file-2|rotated-keyX
+ key_provider_id | key_provider_name |   key_name   
+-----------------+-------------------+--------------
+              -1 | file-2            | rotated-keyX
+(1 row)
+
 SELECT key_provider_id, key_provider_name, key_name FROM pg_tde_server_key_info();
 psql:<stdin>:1: ERROR:  Principal key does not exists for the database
 HINT:  Use set_key interface to set the principal key
 SELECT * FROM test_enc ORDER BY id ASC;
-1|5
-2|6
+ id | k 
+----+---
+  1 | 5
+  2 | 6
+(2 rows)
+
 ALTER SYSTEM SET pg_tde.inherit_global_providers = OFF;
 -- server restart
+SELECT pg_tde_set_key_using_global_key_provider('rotated-keyX2', 'file-2', false);
 psql:<stdin>:1: ERROR:  Usage of global key providers is disabled. Enable it with pg_tde.inherit_global_providers = ON
 SELECT key_provider_id, key_provider_name, key_name FROM pg_tde_key_info();
--1|file-2|rotated-keyX
+ key_provider_id | key_provider_name |   key_name   
+-----------------+-------------------+--------------
+              -1 | file-2            | rotated-keyX
+(1 row)
+
 SELECT key_provider_id, key_provider_name, key_name FROM pg_tde_server_key_info();
 psql:<stdin>:1: ERROR:  Principal key does not exists for the database
 HINT:  Use set_key interface to set the principal key
 SELECT pg_tde_set_key_using_database_key_provider('rotated-key2','file-2');
+ pg_tde_set_key_using_database_key_provider 
+--------------------------------------------
+ 
+(1 row)
 
 SELECT key_provider_id, key_provider_name, key_name FROM pg_tde_key_info();
-2|file-2|rotated-key2
+ key_provider_id | key_provider_name |   key_name   
+-----------------+-------------------+--------------
+               2 | file-2            | rotated-key2
+(1 row)
+
 SELECT key_provider_id, key_provider_name, key_name FROM pg_tde_server_key_info();
 psql:<stdin>:1: ERROR:  Principal key does not exists for the database
 HINT:  Use set_key interface to set the principal key
 DROP TABLE test_enc;
 ALTER SYSTEM RESET pg_tde.inherit_global_providers;
+-- server restart
 DROP EXTENSION pg_tde CASCADE;
-
diff --git a/contrib/pg_tde/t/expected/003_remote_config.out b/contrib/pg_tde/t/expected/003_remote_config.out
index 35bcd3f49651a..fc4208ba360ed 100644
--- a/contrib/pg_tde/t/expected/003_remote_config.out
+++ b/contrib/pg_tde/t/expected/003_remote_config.out
@@ -1,12 +1,32 @@
 CREATE EXTENSION IF NOT EXISTS pg_tde;
+SELECT pg_tde_add_database_key_provider_file('file-provider', json_object( 'type' VALUE 'remote', 'url' VALUE 'http://localhost:8888/hello' ));
+ pg_tde_add_database_key_provider_file 
+---------------------------------------
+                                     1
+(1 row)
+
+SELECT pg_tde_set_key_using_database_key_provider('test-db-key','file-provider');
+ pg_tde_set_key_using_database_key_provider 
+--------------------------------------------
+ 
+(1 row)
+
 CREATE TABLE test_enc2(id SERIAL,k INTEGER,PRIMARY KEY (id)) USING tde_heap;
 INSERT INTO test_enc2 (k) VALUES (5),(6);
 SELECT * FROM test_enc2 ORDER BY id ASC;
-1|5
-2|6
+ id | k 
+----+---
+  1 | 5
+  2 | 6
+(2 rows)
+
 -- server restart
 SELECT * FROM test_enc2 ORDER BY id ASC;
-1|5
-2|6
+ id | k 
+----+---
+  1 | 5
+  2 | 6
+(2 rows)
+
 DROP TABLE test_enc2;
 DROP EXTENSION pg_tde;
diff --git a/contrib/pg_tde/t/expected/004_file_config.out b/contrib/pg_tde/t/expected/004_file_config.out
index e5f705d3137c3..878e2d3621ea0 100644
--- a/contrib/pg_tde/t/expected/004_file_config.out
+++ b/contrib/pg_tde/t/expected/004_file_config.out
@@ -1,12 +1,32 @@
 CREATE EXTENSION IF NOT EXISTS pg_tde;
+SELECT pg_tde_add_database_key_provider_file('file-provider', json_object( 'type' VALUE 'file', 'path' VALUE '/tmp/datafile-location' ));
+ pg_tde_add_database_key_provider_file 
+---------------------------------------
+                                     1
+(1 row)
+
+SELECT pg_tde_set_key_using_database_key_provider('test-db-key','file-provider');
+ pg_tde_set_key_using_database_key_provider 
+--------------------------------------------
+ 
+(1 row)
+
 CREATE TABLE test_enc1(id SERIAL,k INTEGER,PRIMARY KEY (id)) USING tde_heap;
 INSERT INTO test_enc1 (k) VALUES (5),(6);
 SELECT * FROM test_enc1 ORDER BY id ASC;
-1|5
-2|6
+ id | k 
+----+---
+  1 | 5
+  2 | 6
+(2 rows)
+
 -- server restart
 SELECT * FROM test_enc1 ORDER BY id ASC;
-1|5
-2|6
+ id | k 
+----+---
+  1 | 5
+  2 | 6
+(2 rows)
+
 DROP TABLE test_enc1;
 DROP EXTENSION pg_tde;
diff --git a/contrib/pg_tde/t/expected/006_remote_vault_config.out b/contrib/pg_tde/t/expected/006_remote_vault_config.out
index 35bcd3f49651a..8fe7b12360bc0 100644
--- a/contrib/pg_tde/t/expected/006_remote_vault_config.out
+++ b/contrib/pg_tde/t/expected/006_remote_vault_config.out
@@ -1,12 +1,32 @@
 CREATE EXTENSION IF NOT EXISTS pg_tde;
+SELECT pg_tde_add_database_key_provider_vault_v2('vault-provider', json_object( 'type' VALUE 'remote', 'url' VALUE 'http://localhost:8889/token' ), json_object( 'type' VALUE 'remote', 'url' VALUE 'http://localhost:8889/url' ), to_json('secret'::text), NULL);
+ pg_tde_add_database_key_provider_vault_v2 
+-------------------------------------------
+                                         1
+(1 row)
+
+SELECT pg_tde_set_key_using_database_key_provider('test-db-key','vault-provider');
+ pg_tde_set_key_using_database_key_provider 
+--------------------------------------------
+ 
+(1 row)
+
 CREATE TABLE test_enc2(id SERIAL,k INTEGER,PRIMARY KEY (id)) USING tde_heap;
 INSERT INTO test_enc2 (k) VALUES (5),(6);
 SELECT * FROM test_enc2 ORDER BY id ASC;
-1|5
-2|6
+ id | k 
+----+---
+  1 | 5
+  2 | 6
+(2 rows)
+
 -- server restart
 SELECT * FROM test_enc2 ORDER BY id ASC;
-1|5
-2|6
+ id | k 
+----+---
+  1 | 5
+  2 | 6
+(2 rows)
+
 DROP TABLE test_enc2;
 DROP EXTENSION pg_tde;
diff --git a/contrib/pg_tde/t/expected/007_tde_heap.out b/contrib/pg_tde/t/expected/007_tde_heap.out
index 867f714c9fb16..6a5aef32bf731 100644
--- a/contrib/pg_tde/t/expected/007_tde_heap.out
+++ b/contrib/pg_tde/t/expected/007_tde_heap.out
@@ -1,62 +1,119 @@
 CREATE EXTENSION IF NOT EXISTS pg_tde;
+CREATE TABLE test_enc(id SERIAL,k INTEGER,PRIMARY KEY (id)) USING tde_heap;
+psql:<stdin>:1: ERROR:  principal key not configured
+HINT:  create one using pg_tde_set_key before using encrypted tables
 -- server restart
+SELECT pg_tde_add_database_key_provider_file('file-vault','/tmp/pg_tde_test_keyring.per');
+ pg_tde_add_database_key_provider_file 
+---------------------------------------
+                                     1
+(1 row)
+
+SELECT pg_tde_set_key_using_database_key_provider('test-db-key','file-vault');
+ pg_tde_set_key_using_database_key_provider 
+--------------------------------------------
+ 
+(1 row)
+
 CREATE TABLE test_enc1(id SERIAL,k VARCHAR(32),PRIMARY KEY (id)) USING tde_heap;
 INSERT INTO test_enc1 (k) VALUES ('foobar'),('barfoo');
 SELECT * FROM test_enc1 ORDER BY id ASC;
-1|foobar
-2|barfoo
+ id |   k    
+----+--------
+  1 | foobar
+  2 | barfoo
+(2 rows)
+
 CREATE TABLE test_enc2(id SERIAL,k VARCHAR(32),PRIMARY KEY (id));
 INSERT INTO test_enc2 (k) VALUES ('foobar'),('barfoo');
 ALTER TABLE test_enc2 SET ACCESS METHOD tde_heap;
 SELECT * FROM test_enc2 ORDER BY id ASC;
-1|foobar
-2|barfoo
+ id |   k    
+----+--------
+  1 | foobar
+  2 | barfoo
+(2 rows)
+
 SET default_table_access_method = "tde_heap"; CREATE TABLE test_enc3(id SERIAL,k VARCHAR(32),PRIMARY KEY (id));
 INSERT INTO test_enc3 (k) VALUES ('foobar'),('barfoo');
 SELECT * FROM test_enc3 ORDER BY id ASC;
-1|foobar
-2|barfoo
+ id |   k    
+----+--------
+  1 | foobar
+  2 | barfoo
+(2 rows)
+
+CREATE TABLE test_enc4(id SERIAL,k VARCHAR(32),PRIMARY KEY (id)) USING heap;
 INSERT INTO test_enc4 (k) VALUES ('foobar'),('barfoo');
+SET default_table_access_method = "tde_heap"; ALTER TABLE test_enc4 SET ACCESS METHOD DEFAULT;
 SELECT * FROM test_enc4 ORDER BY id ASC;
-1|foobar
-2|barfoo
+ id |   k    
+----+--------
+  1 | foobar
+  2 | barfoo
+(2 rows)
+
 CREATE TABLE test_enc5(id SERIAL,k VARCHAR(32),PRIMARY KEY (id)) USING tde_heap;
 INSERT INTO test_enc5 (k) VALUES ('foobar'),('barfoo');
 CHECKPOINT;
 TRUNCATE test_enc5;
 INSERT INTO test_enc5 (k) VALUES ('foobar'),('barfoo');
 SELECT * FROM test_enc5 ORDER BY id ASC;
-3|foobar
-4|barfoo
+ id |   k    
+----+--------
+  3 | foobar
+  4 | barfoo
+(2 rows)
+
 -- server restart
 ###########################
 SELECT * FROM test_enc1 ORDER BY id ASC;
-1|foobar
-2|barfoo
+ id |   k    
+----+--------
+  1 | foobar
+  2 | barfoo
+(2 rows)
+
 TABLEFILE FOR test_enc1 FOUND: yes
 CONTAINS FOO (should be empty): 
 ###########################
 SELECT * FROM test_enc2 ORDER BY id ASC;
-1|foobar
-2|barfoo
+ id |   k    
+----+--------
+  1 | foobar
+  2 | barfoo
+(2 rows)
+
 TABLEFILE FOR test_enc2 FOUND: yes
 CONTAINS FOO (should be empty): 
 ###########################
 SELECT * FROM test_enc3 ORDER BY id ASC;
-1|foobar
-2|barfoo
+ id |   k    
+----+--------
+  1 | foobar
+  2 | barfoo
+(2 rows)
+
 TABLEFILE FOR test_enc3 FOUND: yes
 CONTAINS FOO (should be empty): 
 ###########################
 SELECT * FROM test_enc4 ORDER BY id ASC;
-1|foobar
-2|barfoo
+ id |   k    
+----+--------
+  1 | foobar
+  2 | barfoo
+(2 rows)
+
 TABLEFILE FOR test_enc4 FOUND: yes
 CONTAINS FOO (should be empty): 
 ###########################
 SELECT * FROM test_enc5 ORDER BY id ASC;
-3|foobar
-4|barfoo
+ id |   k    
+----+--------
+  3 | foobar
+  4 | barfoo
+(2 rows)
+
 TABLEFILE FOR test_enc5 FOUND: yes
 CONTAINS FOO (should be empty): 
 TABLEFILE2 FOUND: yes
diff --git a/contrib/pg_tde/t/expected/008_key_rotate_tablespace.out b/contrib/pg_tde/t/expected/008_key_rotate_tablespace.out
index 58600feeeb367..7d88a74e1c47d 100644
--- a/contrib/pg_tde/t/expected/008_key_rotate_tablespace.out
+++ b/contrib/pg_tde/t/expected/008_key_rotate_tablespace.out
@@ -1,25 +1,17 @@
+SET allow_in_place_tablespaces = true; CREATE TABLESPACE test_tblspace LOCATION '';
+CREATE DATABASE tbc TABLESPACE = test_tblspace;
 CREATE EXTENSION IF NOT EXISTS pg_tde;
 SELECT pg_tde_add_database_key_provider_file('file-vault','/tmp/pg_tde_test_keyring.per');
-1
-SELECT pg_tde_set_key_using_database_key_provider('test-db-key','file-vault');
+ pg_tde_add_database_key_provider_file 
+---------------------------------------
+                                     1
+(1 row)
 
-CREATE TABLE country_table (
-     country_id        serial primary key,
-     country_name    text unique not null,
-     continent        text not null
-) USING tde_heap;
-INSERT INTO country_table (country_name, continent)
-     VALUES ('Japan', 'Asia'),
-            ('UK', 'Europe'),
-            ('USA', 'North America');
-SELECT * FROM country_table;
-1|Japan|Asia
-2|UK|Europe
-3|USA|North America
-CREATE EXTENSION IF NOT EXISTS pg_tde;
-SELECT pg_tde_add_database_key_provider_file('file-vault','/tmp/pg_tde_test_keyring.per');
-1
 SELECT pg_tde_set_key_using_database_key_provider('test-db-key','file-vault');
+ pg_tde_set_key_using_database_key_provider 
+--------------------------------------------
+ 
+(1 row)
 
 CREATE TABLE country_table (
      country_id        serial primary key,
@@ -31,14 +23,29 @@ INSERT INTO country_table (country_name, continent)
             ('UK', 'Europe'),
             ('USA', 'North America');
 SELECT * FROM country_table;
-1|Japan|Asia
-2|UK|Europe
-3|USA|North America
+ country_id | country_name |   continent   
+------------+--------------+---------------
+          1 | Japan        | Asia
+          2 | UK           | Europe
+          3 | USA          | North America
+(3 rows)
+
+SELECT pg_tde_set_key_using_database_key_provider('new-k', 'file-vault');
+ pg_tde_set_key_using_database_key_provider 
+--------------------------------------------
+ 
+(1 row)
+
 -- server restart
 SELECT * FROM country_table;
-1|Japan|Asia
-2|UK|Europe
-3|USA|North America
+ country_id | country_name |   continent   
+------------+--------------+---------------
+          1 | Japan        | Asia
+          2 | UK           | Europe
+          3 | USA          | North America
+(3 rows)
+
 DROP EXTENSION pg_tde CASCADE;
+psql:<stdin>:1: NOTICE:  drop cascades to table country_table
 DROP DATABASE tbc;
 DROP TABLESPACE test_tblspace;
diff --git a/contrib/pg_tde/t/expected/009_wal_encrypt.out b/contrib/pg_tde/t/expected/009_wal_encrypt.out
index 7d7c57268913d..c0df1e2a03110 100644
--- a/contrib/pg_tde/t/expected/009_wal_encrypt.out
+++ b/contrib/pg_tde/t/expected/009_wal_encrypt.out
@@ -1,49 +1,85 @@
 CREATE EXTENSION IF NOT EXISTS pg_tde;
 SELECT pg_tde_add_global_key_provider_file('file-keyring-010','/tmp/pg_tde_test_keyring010.per');
--1
+ pg_tde_add_global_key_provider_file 
+-------------------------------------
+                                  -1
+(1 row)
+
 SELECT pg_tde_set_server_key_using_global_key_provider('server-key', 'file-keyring-010');
+ pg_tde_set_server_key_using_global_key_provider 
+-------------------------------------------------
+ 
+(1 row)
 
 ALTER SYSTEM SET pg_tde.wal_encrypt = on;
 -- server restart with wal encryption
 SHOW pg_tde.wal_encrypt;
-on
+ pg_tde.wal_encrypt 
+--------------------
+ on
+(1 row)
+
 SELECT slot_name FROM pg_create_logical_replication_slot('tde_slot', 'test_decoding');
-tde_slot
+ slot_name 
+-----------
+ tde_slot
+(1 row)
+
 CREATE TABLE test_wal (id SERIAL, k INTEGER, PRIMARY KEY (id));
 INSERT INTO test_wal (k) VALUES (1), (2);
 ALTER SYSTEM SET pg_tde.wal_encrypt = off;
 -- server restart without wal encryption
 SHOW pg_tde.wal_encrypt;
-off
+ pg_tde.wal_encrypt 
+--------------------
+ off
+(1 row)
+
 INSERT INTO test_wal (k) VALUES (3), (4);
 ALTER SYSTEM SET pg_tde.wal_encrypt = on;
 -- server restart with wal encryption
 SHOW pg_tde.wal_encrypt;
-on
+ pg_tde.wal_encrypt 
+--------------------
+ on
+(1 row)
+
 INSERT INTO test_wal (k) VALUES (5), (6);
 -- server restart with still wal encryption
 SHOW pg_tde.wal_encrypt;
-on
+ pg_tde.wal_encrypt 
+--------------------
+ on
+(1 row)
+
 INSERT INTO test_wal (k) VALUES (7), (8);
 SELECT data FROM pg_logical_slot_get_changes('tde_slot', NULL, NULL);
-BEGIN 739
-COMMIT 739
-BEGIN 740
-table public.test_wal: INSERT: id[integer]:1 k[integer]:1
-table public.test_wal: INSERT: id[integer]:2 k[integer]:2
-COMMIT 740
-BEGIN 741
-table public.test_wal: INSERT: id[integer]:3 k[integer]:3
-table public.test_wal: INSERT: id[integer]:4 k[integer]:4
-COMMIT 741
-BEGIN 742
-table public.test_wal: INSERT: id[integer]:5 k[integer]:5
-table public.test_wal: INSERT: id[integer]:6 k[integer]:6
-COMMIT 742
-BEGIN 743
-table public.test_wal: INSERT: id[integer]:7 k[integer]:7
-table public.test_wal: INSERT: id[integer]:8 k[integer]:8
-COMMIT 743
+                           data                            
+-----------------------------------------------------------
+ BEGIN 739
+ COMMIT 739
+ BEGIN 740
+ table public.test_wal: INSERT: id[integer]:1 k[integer]:1
+ table public.test_wal: INSERT: id[integer]:2 k[integer]:2
+ COMMIT 740
+ BEGIN 741
+ table public.test_wal: INSERT: id[integer]:3 k[integer]:3
+ table public.test_wal: INSERT: id[integer]:4 k[integer]:4
+ COMMIT 741
+ BEGIN 742
+ table public.test_wal: INSERT: id[integer]:5 k[integer]:5
+ table public.test_wal: INSERT: id[integer]:6 k[integer]:6
+ COMMIT 742
+ BEGIN 743
+ table public.test_wal: INSERT: id[integer]:7 k[integer]:7
+ table public.test_wal: INSERT: id[integer]:8 k[integer]:8
+ COMMIT 743
+(18 rows)
+
 SELECT pg_drop_replication_slot('tde_slot');
+ pg_drop_replication_slot 
+--------------------------
+ 
+(1 row)
 
 DROP EXTENSION pg_tde;
diff --git a/contrib/pg_tde/t/expected/010_change_key_provider.out b/contrib/pg_tde/t/expected/010_change_key_provider.out
index d7cfbd2a394b0..ca988c6259919 100644
--- a/contrib/pg_tde/t/expected/010_change_key_provider.out
+++ b/contrib/pg_tde/t/expected/010_change_key_provider.out
@@ -1,50 +1,122 @@
 CREATE EXTENSION IF NOT EXISTS pg_tde;
 SELECT pg_tde_add_database_key_provider_file('file-vault', '/tmp/change_key_provider_1.per');
-1
+ pg_tde_add_database_key_provider_file 
+---------------------------------------
+                                     1
+(1 row)
+
 SELECT pg_tde_list_all_database_key_providers();
-(1,file-vault,file,"{""type"" : ""file"", ""path"" : ""/tmp/change_key_provider_1.per""}")
+                           pg_tde_list_all_database_key_providers                           
+--------------------------------------------------------------------------------------------
+ (1,file-vault,file,"{""type"" : ""file"", ""path"" : ""/tmp/change_key_provider_1.per""}")
+(1 row)
+
 SELECT pg_tde_set_key_using_database_key_provider('test-key', 'file-vault');
+ pg_tde_set_key_using_database_key_provider 
+--------------------------------------------
+ 
+(1 row)
 
 CREATE TABLE test_enc (id serial, k integer, PRIMARY KEY (id)) USING tde_heap;
 INSERT INTO test_enc (k) VALUES (5), (6);
 SELECT pg_tde_verify_key();
+ pg_tde_verify_key 
+-------------------
+ 
+(1 row)
 
 SELECT pg_tde_is_encrypted('test_enc');
-t
+ pg_tde_is_encrypted 
+---------------------
+ t
+(1 row)
+
 SELECT * FROM test_enc ORDER BY id;
-1|5
-2|6
+ id | k 
+----+---
+  1 | 5
+  2 | 6
+(2 rows)
+
 -- mv /tmp/change_key_provider_1.per /tmp/change_key_provider_2.per
 SELECT pg_tde_change_database_key_provider_file('file-vault', '/tmp/change_key_provider_2.per');
-1
+ pg_tde_change_database_key_provider_file 
+------------------------------------------
+                                        1
+(1 row)
+
 SELECT pg_tde_list_all_database_key_providers();
-(1,file-vault,file,"{""type"" : ""file"", ""path"" : ""/tmp/change_key_provider_2.per""}")
+                           pg_tde_list_all_database_key_providers                           
+--------------------------------------------------------------------------------------------
+ (1,file-vault,file,"{""type"" : ""file"", ""path"" : ""/tmp/change_key_provider_2.per""}")
+(1 row)
+
 SELECT pg_tde_verify_key();
+ pg_tde_verify_key 
+-------------------
+ 
+(1 row)
 
 SELECT pg_tde_is_encrypted('test_enc');
-t
+ pg_tde_is_encrypted 
+---------------------
+ t
+(1 row)
+
 SELECT * FROM test_enc ORDER BY id;
-1|5
-2|6
+ id | k 
+----+---
+  1 | 5
+  2 | 6
+(2 rows)
+
 -- server restart
 SELECT pg_tde_verify_key();
+ pg_tde_verify_key 
+-------------------
+ 
+(1 row)
 
 SELECT pg_tde_is_encrypted('test_enc');
-t
+ pg_tde_is_encrypted 
+---------------------
+ t
+(1 row)
+
 SELECT * FROM test_enc ORDER BY id;
-1|5
-2|6
+ id | k 
+----+---
+  1 | 5
+  2 | 6
+(2 rows)
+
 SELECT pg_tde_change_database_key_provider_file('file-vault', '/tmp/change_key_provider_3.per');
-1
+ pg_tde_change_database_key_provider_file 
+------------------------------------------
+                                        1
+(1 row)
+
 SELECT pg_tde_list_all_database_key_providers();
-(1,file-vault,file,"{""type"" : ""file"", ""path"" : ""/tmp/change_key_provider_3.per""}")
+                           pg_tde_list_all_database_key_providers                           
+--------------------------------------------------------------------------------------------
+ (1,file-vault,file,"{""type"" : ""file"", ""path"" : ""/tmp/change_key_provider_3.per""}")
+(1 row)
+
 SELECT pg_tde_verify_key();
 psql:<stdin>:1: ERROR:  failed to retrieve principal key test-key from keyring with ID 1
 SELECT pg_tde_is_encrypted('test_enc');
-t
+ pg_tde_is_encrypted 
+---------------------
+ t
+(1 row)
+
 SELECT * FROM test_enc ORDER BY id;
-1|5
-2|6
+ id | k 
+----+---
+  1 | 5
+  2 | 6
+(2 rows)
+
 -- server restart
 SELECT pg_tde_verify_key();
 psql:<stdin>:1: ERROR:  failed to retrieve principal key test-key from keyring with ID 1
@@ -55,29 +127,66 @@ psql:<stdin>:1: ERROR:  failed to retrieve principal key test-key from keyring w
 -- mv /tmp/change_key_provider_2.per /tmp/change_key_provider_3.per
 -- server restart
 SELECT pg_tde_verify_key();
+ pg_tde_verify_key 
+-------------------
+ 
+(1 row)
 
 SELECT pg_tde_is_encrypted('test_enc');
-t
+ pg_tde_is_encrypted 
+---------------------
+ t
+(1 row)
+
 SELECT * FROM test_enc ORDER BY id;
-1|5
-2|6
+ id | k 
+----+---
+  1 | 5
+  2 | 6
+(2 rows)
+
 DROP EXTENSION pg_tde CASCADE;
 psql:<stdin>:1: NOTICE:  drop cascades to table test_enc
 CREATE EXTENSION IF NOT EXISTS pg_tde;
 SELECT pg_tde_add_database_key_provider_file('file-vault', '/tmp/change_key_provider_4.per');
-1
-0
+ pg_tde_add_database_key_provider_file 
+---------------------------------------
+                                     1
+(1 row)
+
+SELECT pg_tde_set_key_using_database_key_provider('test-key', 'file-vault');
+ pg_tde_set_key_using_database_key_provider 
+--------------------------------------------
+ 
+(1 row)
+
 CREATE TABLE test_enc (id serial, k integer, PRIMARY KEY (id)) USING tde_heap;
 INSERT INTO test_enc (k) VALUES (5), (6);
 SELECT pg_tde_verify_key();
+ pg_tde_verify_key 
+-------------------
+ 
+(1 row)
 
 SELECT pg_tde_is_encrypted('test_enc');
-t
+ pg_tde_is_encrypted 
+---------------------
+ t
+(1 row)
+
 SELECT * FROM test_enc ORDER BY id;
-1|5
-2|6
+ id | k 
+----+---
+  1 | 5
+  2 | 6
+(2 rows)
+
 SELECT pg_tde_change_database_key_provider_file('file-vault', '/tmp/change_key_provider_3.per');
-1
+ pg_tde_change_database_key_provider_file 
+------------------------------------------
+                                        1
+(1 row)
+
 -- server restart
 SELECT pg_tde_verify_key();
 psql:<stdin>:1: ERROR:  Failed to verify principal key header for key test-key, incorrect principal key or corrupted key file
@@ -88,13 +197,29 @@ psql:<stdin>:1: ERROR:  Failed to verify principal key header for key test-key,
 CREATE TABLE test_enc2 (id serial, k integer, PRIMARY KEY (id)) USING tde_heap;
 psql:<stdin>:1: ERROR:  Failed to verify principal key header for key test-key, incorrect principal key or corrupted key file
 SELECT pg_tde_change_database_key_provider_file('file-vault', '/tmp/change_key_provider_4.per');
-1
+ pg_tde_change_database_key_provider_file 
+------------------------------------------
+                                        1
+(1 row)
+
 SELECT pg_tde_verify_key();
+ pg_tde_verify_key 
+-------------------
+ 
+(1 row)
 
 SELECT pg_tde_is_encrypted('test_enc');
-t
+ pg_tde_is_encrypted 
+---------------------
+ t
+(1 row)
+
 SELECT * FROM test_enc ORDER BY id;
-1|5
-2|6
+ id | k 
+----+---
+  1 | 5
+  2 | 6
+(2 rows)
+
 DROP EXTENSION pg_tde CASCADE;
 psql:<stdin>:1: NOTICE:  drop cascades to table test_enc
diff --git a/contrib/pg_tde/t/expected/011_unlogged_tables.out b/contrib/pg_tde/t/expected/011_unlogged_tables.out
index 031fd4f80b24d..71c52786b134f 100644
--- a/contrib/pg_tde/t/expected/011_unlogged_tables.out
+++ b/contrib/pg_tde/t/expected/011_unlogged_tables.out
@@ -1,7 +1,15 @@
 CREATE EXTENSION IF NOT EXISTS pg_tde;
 SELECT pg_tde_add_database_key_provider_file('file-vault', '/tmp/unlogged_tables.per');
-1
+ pg_tde_add_database_key_provider_file 
+---------------------------------------
+                                     1
+(1 row)
+
 SELECT pg_tde_set_key_using_database_key_provider('test-key', 'file-vault');
+ pg_tde_set_key_using_database_key_provider 
+--------------------------------------------
+ 
+(1 row)
 
 CREATE UNLOGGED TABLE t (x int PRIMARY KEY) USING tde_heap;
 INSERT INTO t SELECT generate_series(1, 4);
@@ -9,4 +17,8 @@ CHECKPOINT;
 -- kill -9
 -- server start
 TABLE t;
+ x 
+---
+(0 rows)
+
 INSERT INTO t SELECT generate_series(1, 4);
diff --git a/contrib/pg_tde/t/pgtde.pm b/contrib/pg_tde/t/pgtde.pm
index 67b1709aad749..989b41089c3bf 100644
--- a/contrib/pg_tde/t/pgtde.pm
+++ b/contrib/pg_tde/t/pgtde.pm
@@ -4,13 +4,10 @@ use File::Basename;
 use File::Compare;
 use Test::More;
 
-our @ISA= qw( Exporter );
+our @ISA = qw(Exporter);
 
 # These CAN be exported.
-our @EXPORT = qw( pgtde_init_pg pgtde_start_pg pgtde_stop_pg pgtde_psql_cmd pgtde_setup_pg_tde pgtde_create_extension pgtde_drop_extension );
-
-# Instance of pg server that would be spanwed by TAP testing. A new server will be created for each TAP test.
-our $pg_node;
+our @EXPORT = qw(pgtde_init_pg pgtde_start_pg pgtde_stop_pg pgtde_psql_cmd pgtde_setup_pg_tde pgtde_create_extension pgtde_drop_extension);
 
 # Expected .out filename of TAP testcase being executed. These are already part of repo under t/expected/*.
 our $expected_filename_with_path;
@@ -29,67 +26,64 @@ BEGIN {
     $PG_MAJOR_VERSION = `pg_config --version | awk {'print \$2'} | cut -f1 -d"." | sed -e 's/[^0-9].*\$//g'`;
     $PG_MAJOR_VERSION =~ s/^\s+|\s+$//g;
 
-    # Depending upon PG server version load the required module at runtime when pgtde.pm is loaded.
-    my $node_module = $PG_MAJOR_VERSION > 14 ? "PostgreSQL::Test::Cluster" : "PostgresNode";
-    my $node_module_file = $node_module;
-    $node_module_file =~ s[::][/]g;
-    $node_module_file .= '.pm';
-    require $node_module_file;
-    $node_module->import;
+    if ($PG_MAJOR_VERSION >= 15) {
+        eval {
+            require PostgreSQL::Test::Cluster;
+            import PostgreSQL::Test::Utils;
+        }
+    } else {
+        eval {
+            require PostgresNode;
+            import TestLib;
+        }
+    }
 }
 
 sub pgtde_init_pg
 {
+    my $node;
+
     print "Postgres major version: $PG_MAJOR_VERSION \n";
 
     # For Server version 15 & above, spawn the server using PostgreSQL::Test::Cluster
-    if ($PG_MAJOR_VERSION > 14) {
-        $pg_node = PostgreSQL::Test::Cluster->new('pgtde_regression');
-    }
-    # For Server version 14 & below, spawn the server using PostgresNode
-    elsif ($PG_MAJOR_VERSION < 15) {
-        $pg_node = PostgresNode->get_new_node('pgtde_regression');
+    if ($PG_MAJOR_VERSION >= 15) {
+        $node = PostgreSQL::Test::Cluster->new('pgtde_regression');
+    } else {
+        $node = PostgresNode->get_new_node('pgtde_regression');
     }
 
-    $pg_node->dump_info;
-    $pg_node->init;
-    return $pg_node;
+    $node->dump_info;
+    $node->init;
+    return $node;
 }
 
-sub append_to_file
+sub psql
 {
-    my ($str) = @_;
+    my ($node, $dbname, $sql) = @_;
+
+    my (undef, $stdout, $stderr) = $node->psql($dbname, $sql, extra_params => ['-a', '-Pformat=aligned', '-Ptuples_only=off']);
 
-    # For Server version 15 & above, use PostgreSQL::Test::Utils to write to files
-    if ($PG_MAJOR_VERSION > 14) {
-        PostgreSQL::Test::Utils::append_to_file($out_filename_with_path, $str . "\n");
+    if ($stdout ne '') {
+        append_to_result_file($stdout);
     }
-    # For Server version 14 & below, use PostgresNode to write to files
-    elsif ($PG_MAJOR_VERSION < 15) {
-        TestLib::append_to_file($out_filename_with_path, $str . "\n");
+
+    if ($stderr ne '') {
+        append_to_result_file($stderr);
     }
-    chmod(0640 , $out_filename_with_path)
-    or die("unable to set permissions for $out_filename_with_path");
+}
+
+sub append_to_result_file
+{
+    my ($str) = @_;
 
-    return;
+    append_to_file($out_filename_with_path, $str . "\n");
 }
 
 sub append_to_debug_file
 {
     my ($str) = @_;
 
-    # For Server version 15 & above, use PostgreSQL::Test::Utils to write to files
-    if ($PG_MAJOR_VERSION > 14) {
-        PostgreSQL::Test::Utils::append_to_file($debug_out_filename_with_path, $str . "\n");
-    }
-    # For Server version 14 & below, use PostgresNode to write to files
-    elsif ($PG_MAJOR_VERSION < 15) {
-        TestLib::append_to_file($debug_out_filename_with_path, $str . "\n");
-    }
-    chmod(0640 , $debug_out_filename_with_path)
-    or die("unable to set permissions for $debug_out_filename_with_path");
-
-    return;
+    append_to_file($debug_out_filename_with_path, $str . "\n");
 }
 
 sub setup_files_dir


Reviews:
user: login: AndersAstrand
body: This looks like a great cleanup to me! However I'm not sure I follow the reasoning behind treating TAP tests as pg_regress tests, but without a usable diff. Knowing what's wrong when they fail is much trickier than it would have to be if we just used regular TAP expectations.

state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-04-15T11:35:47Z
user: login: jeltz
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-04-15T12:52:42Z
user: login: Naeem-Akhter
body: It looks much better and is the way to go if we keep the diff-based option intact. 

Regarding whether we should opt for a diff-based approach or idiomatic TAP, I would prefer to have support for both, as we will always have the option to choose depending upon the use case (in case a diff is needed). However, I believe the idiomatic TAP test case should be our preferred approach moving forward. 
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-04-15T20:50:47Z
user: login: Naeem-Akhter
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-04-15T21:03:01Z
user: login: Naeem-Akhter
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-04-15T21:04:47Z
user: login: dutow
body: Looks much better!
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-04-15T21:10:51Z
user: login: jeltz
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-04-16T07:01:34Z
user: login: jeltz
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-04-16T07:02:25Z
user: login: jeltz
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-04-16T08:09:47Z
user: login: AndersAstrand
body: This looks like a great cleanup!
state: APPROVED
author_association: COLLABORATOR
submitted_at: 2025-04-16T18:58:12Z
user: login: Naeem-Akhter
state: APPROVED
author_association: COLLABORATOR
submitted_at: 2025-04-16T19:37:55Z

Review comments:
diff_hunk: @@ -56,20 +56,31 @@ sub pgtde_init_pg
     return $pg_node;
 }
 
+sub psql
+{
+    my ($node, $dbname, $sql) = @_;
+
+    my (undef, $stdout, $stderr) = $node->psql($dbname, $sql, extra_params => ['-a', '-P', 'format=aligned', '-P', 'tuples_only=off']);
+
+    if ($stdout ne '') {
+        append_to_file($stdout);
+    }
+
+    if ($stderr ne '') {
+        append_to_file($stderr);
+    }
+}
+
 sub append_to_file
 {
     my ($str) = @_;
 
-    # For Server version 15 & above, use PostgreSQL::Test::Utils to write to files
-    if ($PG_MAJOR_VERSION > 14) {
+    if ($PG_MAJOR_VERSION >= 15) {
path: contrib/pg_tde/t/pgtde.pm
user: login: AndersAstrand
body: I suspect this is a vestigial from when pg_tde lived in a separate repo, we don't really need to do this at all now since we know for sure what version of postgres we're testing.

otoh it might be nice to keep this for a possible future where we might be able to move pg_tde out of the main repo again. The question is how much of this we should do in our code in general.
created_at: 2025-04-15T11:18:24Z
author_association: COLLABORATOR
diff_hunk: @@ -56,20 +56,31 @@ sub pgtde_init_pg
     return $pg_node;
 }
 
+sub psql
+{
+    my ($node, $dbname, $sql) = @_;
+
+    my (undef, $stdout, $stderr) = $node->psql($dbname, $sql, extra_params => ['-a', '-P', 'format=aligned', '-P', 'tuples_only=off']);
path: contrib/pg_tde/t/pgtde.pm
user: login: AndersAstrand
body: I like that we now would get a readable diff, if we had one :)
created_at: 2025-04-15T11:22:23Z
author_association: COLLABORATOR
diff_hunk: @@ -56,20 +56,31 @@ sub pgtde_init_pg
     return $pg_node;
 }
 
+sub psql
+{
+    my ($node, $dbname, $sql) = @_;
+
+    my (undef, $stdout, $stderr) = $node->psql($dbname, $sql, extra_params => ['-a', '-P', 'format=aligned', '-P', 'tuples_only=off']);
+
+    if ($stdout ne '') {
+        append_to_file($stdout);
+    }
+
+    if ($stderr ne '') {
+        append_to_file($stderr);
+    }
+}
+
 sub append_to_file
 {
     my ($str) = @_;
 
-    # For Server version 15 & above, use PostgreSQL::Test::Utils to write to files
-    if ($PG_MAJOR_VERSION > 14) {
+    if ($PG_MAJOR_VERSION >= 15) {
path: contrib/pg_tde/t/pgtde.pm
user: login: jeltz
body: Yeah, I was going back and forth on that.
created_at: 2025-04-15T12:52:42Z
author_association: COLLABORATOR
diff_hunk: @@ -56,6 +56,21 @@ sub pgtde_init_pg
     return $pg_node;
 }
 
+sub psql
+{
+    my ($node, $dbname, $sql) = @_;
+
+    my (undef, $stdout, $stderr) = $node->psql($dbname, $sql, extra_params => ['-a']);
+
path: contrib/pg_tde/t/pgtde.pm
user: login: Naeem-Akhter
body: IIRC, though, there is no support for function overloading in Perl. It would be nice to have a similar function where we just return the command return code or maybe a full ($ret, $stdout, $stderr). 
created_at: 2025-04-15T21:03:01Z
author_association: COLLABORATOR
diff_hunk: @@ -56,6 +56,21 @@ sub pgtde_init_pg
     return $pg_node;
 }
 
+sub psql
+{
+    my ($node, $dbname, $sql) = @_;
+
+    my (undef, $stdout, $stderr) = $node->psql($dbname, $sql, extra_params => ['-a']);
+
+    if ($stdout ne '') {
+        append_to_file($stdout);
+    }
+
+    if ($stderr ne '') {
+        append_to_file($stderr);
+    }
+}
+
 sub append_to_file
 {
path: contrib/pg_tde/t/pgtde.pm
user: login: Naeem-Akhter
body: Suggestion, Wouldn't changing it to `append_to_result_file `be better?
created_at: 2025-04-15T21:04:47Z
author_association: COLLABORATOR
diff_hunk: @@ -1,16 +1,43 @@
 CREATE EXTENSION IF NOT EXISTS pg_tde;
 SELECT extname, extversion FROM pg_extension WHERE extname = 'pg_tde';
-pg_tde|1.0-rc
+ extname | extversion 
+---------+------------
+ pg_tde  | 1.0-rc
+(1 row)
+
+CREATE TABLE test_enc(id SERIAL,k INTEGER,PRIMARY KEY (id)) USING tde_heap;
+psql:<stdin>:1: ERROR:  principal key not configured
path: contrib/pg_tde/t/expected/001_basic.out
user: login: dutow
body: It would be nice to also show the error codes here, that would give us one more reminder to fix them.
created_at: 2025-04-15T21:10:04Z
author_association: COLLABORATOR
diff_hunk: @@ -56,6 +56,21 @@ sub pgtde_init_pg
     return $pg_node;
 }
 
+sub psql
+{
+    my ($node, $dbname, $sql) = @_;
+
+    my (undef, $stdout, $stderr) = $node->psql($dbname, $sql, extra_params => ['-a']);
+
+    if ($stdout ne '') {
+        append_to_file($stdout);
+    }
+
+    if ($stderr ne '') {
+        append_to_file($stderr);
+    }
+}
+
 sub append_to_file
 {
path: contrib/pg_tde/t/pgtde.pm
user: login: jeltz
body: Yeah, that is a better name.
created_at: 2025-04-16T07:01:34Z
author_association: COLLABORATOR
diff_hunk: @@ -56,6 +56,21 @@ sub pgtde_init_pg
     return $pg_node;
 }
 
+sub psql
+{
+    my ($node, $dbname, $sql) = @_;
+
+    my (undef, $stdout, $stderr) = $node->psql($dbname, $sql, extra_params => ['-a']);
+
path: contrib/pg_tde/t/pgtde.pm
user: login: jeltz
body: Maybe, but until I have a user for it I do not think we should be build it.
created_at: 2025-04-16T07:02:25Z
author_association: COLLABORATOR
diff_hunk: @@ -1,16 +1,43 @@
 CREATE EXTENSION IF NOT EXISTS pg_tde;
 SELECT extname, extversion FROM pg_extension WHERE extname = 'pg_tde';
-pg_tde|1.0-rc
+ extname | extversion 
+---------+------------
+ pg_tde  | 1.0-rc
+(1 row)
+
+CREATE TABLE test_enc(id SERIAL,k INTEGER,PRIMARY KEY (id)) USING tde_heap;
+psql:<stdin>:1: ERROR:  principal key not configured
path: contrib/pg_tde/t/expected/001_basic.out
user: login: jeltz
body: Maybe, the issue is that it is not in our SQL tests where I imagine most of these errors will be. Hmmm.
created_at: 2025-04-16T08:09:47Z
author_association: COLLABORATOR

PR comments:
user: login: dAdAbird
created_at: 2025-04-15T15:15:39Z
body: Looks good to me. It definitely brings much cleaner tests code and it's good to have diff on errors
author_association: MEMBER
user: login: codecov-commenter
created_at: 2025-04-16T07:08:10Z
body: ## [Codecov](https://app.codecov.io/gh/percona/postgres/pull/216?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=percona) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 76.57%. Comparing base [(`033f7ca`)](https://app.codecov.io/gh/percona/postgres/commit/033f7cae77ed65cab369741e4a2b3aec825ad77b?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=percona) to head [(`4e71402`)](https://app.codecov.io/gh/percona/postgres/commit/4e7140246abd96fd14acc617ed625ffd7aebab93?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=percona).

:x: Your project status has failed because the head coverage (76.57%) is below the target coverage (90.00%). You can increase the head coverage or adjust the [target](https://docs.codecov.com/docs/commit-status#target) coverage.

<details><summary>Additional details and impacted files</summary>


```diff
@@                Coverage Diff                 @@
##           TDE_REL_17_STABLE     #216   +/-   ##
==================================================
  Coverage              76.57%   76.57%           
==================================================
  Files                     23       23           
  Lines                   2510     2510           
  Branches                 400      400           
==================================================
  Hits                    1922     1922           
  Misses                   511      511           
  Partials                  77       77           
```

| [Components](https://app.codecov.io/gh/percona/postgres/pull/216/components?src=pr&el=components&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=percona) | Coverage Δ | |
|---|---|---|
| [access](https://app.codecov.io/gh/percona/postgres/pull/216/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=percona) | `72.65% <ø> (ø)` | |
| [catalog](https://app.codecov.io/gh/percona/postgres/pull/216/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=percona) | `85.58% <ø> (ø)` | |
| [common](https://app.codecov.io/gh/percona/postgres/pull/216/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=percona) | `92.50% <ø> (ø)` | |
| [encryption](https://app.codecov.io/gh/percona/postgres/pull/216/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=percona) | `79.16% <ø> (ø)` | |
| [keyring](https://app.codecov.io/gh/percona/postgres/pull/216/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=percona) | `69.87% <ø> (ø)` | |
| [src](https://app.codecov.io/gh/percona/postgres/pull/216/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=percona) | `52.96% <ø> (ø)` | |
| [smgr](https://app.codecov.io/gh/percona/postgres/pull/216/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=percona) | `96.77% <ø> (ø)` | |
| [transam](https://app.codecov.io/gh/percona/postgres/pull/216/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=percona) | `95.91% <ø> (ø)` | |

</details>
<details><summary> :rocket: New features to boost your workflow: </summary>

- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
</details>
author_association: NONE
user: login: jeltz
created_at: 2025-04-16T08:13:20Z
body: @Naeem-Akhter I did not covert `contrib/pg_tde/t/005_multiple_extensions.pl` since I could not run it with a reasonable amout of effort. Plus I am not sure it belongs in this repo in the first place.
author_association: COLLABORATOR
user: login: Naeem-Akhter
created_at: 2025-04-16T13:03:13Z
body: > @Naeem-Akhter I did not covert `contrib/pg_tde/t/005_multiple_extensions.pl` since I could not run it with a reasonable amout of effort. Plus I am not sure it belongs in this repo in the first place.

To make this test case work, we need to add a GH workflow/action where we install all PSP/PPG-supported extensions using packages. This test case won't work and will be skipped against a source build, as we are not building any extension (pg_stat_monitor, plaudit, set_user, pg_repack PostGIS) as part of make process. 

So, please leave this test case as it is. I will take care of it when I add the GH workflow for testing against package installation. 
author_association: COLLABORATOR