1
+ # !/usr/bin/perl
2
+
3
+ use strict;
4
+ use warnings;
5
+ use File::Basename;
6
+ use Test::More;
7
+ use lib ' t' ;
8
+ use pgtde;
9
+
10
+ PGTDE::setup_files_dir(basename($0 ));
11
+
12
+ my $node = PostgreSQL::Test::Cluster-> new(' main' );
13
+ $node -> init;
14
+ $node -> append_conf(' postgresql.conf' , " shared_preload_libraries = 'pg_tde'" );
15
+ $node -> start;
16
+
17
+ PGTDE::psql($node , ' postgres' , ' CREATE EXTENSION IF NOT EXISTS pg_tde;' );
18
+ PGTDE::psql($node , ' postgres' ,
19
+ " SELECT pg_tde_add_global_key_provider_file('global_keyring', '/tmp/crash_recovery.per');"
20
+ );
21
+ PGTDE::psql($node , ' postgres' ,
22
+ " SELECT pg_tde_set_server_key_using_global_key_provider('wal_encryption_key', 'global_keyring');"
23
+ );
24
+ PGTDE::psql($node , ' postgres' ,
25
+ " SELECT pg_tde_add_database_key_provider_file('db_keyring', '/tmp/crash_recovery.per');"
26
+ );
27
+ PGTDE::psql($node , ' postgres' ,
28
+ " SELECT pg_tde_set_key_using_database_key_provider('db_key', 'db_keyring');"
29
+ );
30
+
31
+ PGTDE::psql($node , ' postgres' ,
32
+ " CREATE TABLE test_enc (x int PRIMARY KEY) USING tde_heap;" );
33
+ PGTDE::psql($node , ' postgres' ,
34
+ " INSERT INTO test_enc (x) VALUES (1), (2);" );
35
+
36
+ PGTDE::psql($node , ' postgres' ,
37
+ " CREATE TABLE test_plain (x int PRIMARY KEY) USING heap;" );
38
+ PGTDE::psql($node , ' postgres' ,
39
+ " INSERT INTO test_plain (x) VALUES (3), (4);" );
40
+
41
+ PGTDE::psql($node , ' postgres' ,
42
+ " ALTER SYSTEM SET pg_tde.wal_encrypt = 'on';"
43
+ );
44
+
45
+ PGTDE::append_to_result_file(" -- kill -9" );
46
+ $node -> kill9;
47
+
48
+ PGTDE::append_to_result_file(" -- server start" );
49
+ $node -> start;
50
+
51
+ PGTDE::append_to_result_file(" -- rotate wal key" );
52
+ PGTDE::psql($node , ' postgres' ,
53
+ " SELECT pg_tde_set_server_key_using_global_key_provider('wal_encryption_key_1', 'global_keyring', true);"
54
+ );
55
+ PGTDE::psql($node , ' postgres' ,
56
+ " SELECT pg_tde_set_key_using_database_key_provider('db_key_1', 'db_keyring');"
57
+ );
58
+ PGTDE::psql($node , ' postgres' ,
59
+ " INSERT INTO test_enc (x) VALUES (3), (4);" );
60
+ PGTDE::append_to_result_file(" -- kill -9" );
61
+ $node -> kill9;
62
+ PGTDE::append_to_result_file(" -- server start" );
63
+ PGTDE::append_to_result_file(" -- check the recovery redo and the fix in PR #217 ('Failed to verify principal key header...' error)" );
64
+ $node -> start;
65
+
66
+ PGTDE::append_to_result_file(" -- rotate wal key" );
67
+ PGTDE::psql($node , ' postgres' ,
68
+ " SELECT pg_tde_set_server_key_using_global_key_provider('wal_encryption_key_2', 'global_keyring', true);"
69
+ );
70
+ PGTDE::psql($node , ' postgres' ,
71
+ " SELECT pg_tde_set_key_using_database_key_provider('db_key_2', 'db_keyring');"
72
+ );
73
+ PGTDE::psql($node , ' postgres' ,
74
+ " INSERT INTO test_enc (x) VALUES (5), (6);" );
75
+ PGTDE::append_to_result_file(" -- kill -9" );
76
+ $node -> kill9;
77
+ PGTDE::append_to_result_file(" -- server start" );
78
+ PGTDE::append_to_result_file(" -- check the fix of PG-1468, PG-1541 in PR #225 ('invalid magic number XXXX in WAL segment' error)" );
79
+ $node -> start;
80
+
81
+ PGTDE::psql($node , ' postgres' , " TABLE test_enc;" );
82
+
83
+ $node -> stop;
84
+
85
+ # Compare the expected and out file
86
+ my $compare = PGTDE-> compare_results();
87
+
88
+ is($compare , 0,
89
+ " Compare Files: $PGTDE::expected_filename_with_path and $PGTDE::out_filename_with_path files."
90
+ );
91
+
92
+ done_testing();
0 commit comments