@@ -77,14 +77,24 @@ def test_exclude_temp_tables(self):
77
77
self .del_test_dir (module_name , fname )
78
78
79
79
# @unittest.skip("skip")
80
- def test_exclude_unlogged_tables (self ):
81
- """make node without archiving, create temp table, take full backup, check that temp table not present in backup catalogue"""
80
+ def test_exclude_unlogged_tables_1 (self ):
81
+ """
82
+ make node without archiving, create unlogged table, take full backup,
83
+ alter table to unlogged, take ptrack backup, restore ptrack backup,
84
+ check that PGDATA`s are physically the same
85
+ """
82
86
fname = self .id ().split ('.' )[3 ]
83
87
backup_dir = os .path .join (self .tmp_path , module_name , fname , 'backup' )
84
- node = self .make_simple_node (base_dir = "{0}/{1}/node" .format (module_name , fname ),
88
+ node = self .make_simple_node (
89
+ base_dir = "{0}/{1}/node" .format (module_name , fname ),
85
90
set_replication = True ,
86
91
initdb_params = ['--data-checksums' ],
87
- pg_options = {'wal_level' : 'replica' , 'max_wal_senders' : '2' , "shared_buffers" : "1GB" , "fsync" : "off" , 'ptrack_enable' : 'on' }
92
+ pg_options = {
93
+ 'wal_level' : 'replica' ,
94
+ 'max_wal_senders' : '2' ,
95
+ "shared_buffers" : "1GB" ,
96
+ "fsync" : "off" ,
97
+ 'ptrack_enable' : 'on' }
88
98
)
89
99
90
100
self .init_pb (backup_dir )
@@ -94,75 +104,38 @@ def test_exclude_unlogged_tables(self):
94
104
conn = node .connect ()
95
105
with node .connect ("postgres" ) as conn :
96
106
97
- conn .execute ("create unlogged table test as select generate_series(0,5005000)::text" )
107
+ conn .execute (
108
+ "create unlogged table test as "
109
+ "select generate_series(0,5005000)::text" )
98
110
conn .commit ()
99
111
100
112
conn .execute ("create index test_idx on test (generate_series)" )
101
113
conn .commit ()
102
114
103
- heap_path = conn .execute ("select pg_relation_filepath('test')" )[0 ][0 ]
104
- conn .commit ()
115
+ self .backup_node (
116
+ backup_dir , 'node' , node ,
117
+ backup_type = 'full' , options = ['--stream' ])
105
118
106
- index_path = conn .execute ("select pg_relation_filepath('test_idx')" )[0 ][0 ]
107
- conn .commit ()
108
- index_init_path = index_path + "_init"
119
+ node .safe_psql ('postgres' , "alter table test set logged" )
109
120
110
- heap_oid = conn .execute ("select 'test'::regclass::oid" )[0 ][0 ]
111
- conn .commit ()
121
+ self .backup_node (
122
+ backup_dir , 'node' , node , backup_type = 'ptrack' ,
123
+ options = ['--stream' , '--log-level-file=verbose' ]
124
+ )
112
125
113
- toast_path = conn .execute ("select pg_relation_filepath('{0}.{1}')" .format ("pg_toast" , "pg_toast_" + str (heap_oid )))[0 ][0 ]
114
- conn .commit ()
115
- toast_init_path = toast_path + "_init"
126
+ pgdata = self .pgdata_content (node .data_dir )
116
127
117
- toast_idx_path = conn .execute ("select pg_relation_filepath('{0}.{1}')" .format ("pg_toast" , "pg_toast_" + str (heap_oid ) + "_index" ))[0 ][0 ]
118
- conn .commit ()
119
- toast_index_idx_path = toast_idx_path + "_init"
120
-
121
- unlogged_heap_filename = os .path .basename (heap_path )
122
- unlogged_heap_init_filename = unlogged_heap_filename + "_init"
123
-
124
- unlogged_idx_filename = os .path .basename (index_path )
125
- unlogged_idx_init_filename = unlogged_idx_filename + "_init"
126
-
127
- unlogged_toast_filename = os .path .basename (toast_path )
128
- unlogged_toast_init_filename = unlogged_toast_filename + "_init"
128
+ node_restored = self .make_simple_node (
129
+ base_dir = "{0}/{1}/node_restored" .format (module_name , fname ),
130
+ )
131
+ node_restored .cleanup ()
129
132
130
- unlogged_idx_toast_filename = os . path . basename ( toast_idx_path )
131
- unlogged_idx_toast_init_filename = unlogged_idx_toast_filename + "_init"
133
+ self . restore_node (
134
+ backup_dir , 'node' , node_restored , options = [ "-j" , "4" ])
132
135
133
- self .backup_node (backup_dir , 'node' , node , backup_type = 'full' , options = ['--stream' ])
134
-
135
- found_unlogged_heap_init = False
136
- found_unlogged_idx_init = False
137
- found_unlogged_toast = False
138
- found_unlogged_idx_toast_init = False
139
- for root , dirs , files in os .walk (backup_dir ):
140
- for file in files :
141
- if file in [unlogged_heap_filename , unlogged_heap_filename + ".1" ,
142
- unlogged_idx_filename ,
143
- unlogged_idx_filename + ".1" ,
144
- unlogged_toast_filename ,
145
- unlogged_toast_filename + ".1" ,
146
- unlogged_idx_toast_filename ,
147
- unlogged_idx_toast_filename + ".1" ]:
148
- self .assertTrue (False , "Found unlogged table file in backup catalogue.\n Filepath: {0}" .format (file ))
149
-
150
- if file == unlogged_heap_init_filename :
151
- found_unlogged_heap_init = True
152
-
153
- if file == unlogged_idx_init_filename :
154
- found_unlogged_idx_init = True
155
-
156
- if file == unlogged_toast_init_filename :
157
- found_unlogged_toast = True
158
-
159
- if file == unlogged_idx_toast_init_filename :
160
- found_unlogged_idx_toast_init = True
161
-
162
- self .assertTrue (found_unlogged_heap_init , "{0} is not found in backup catalogue" .format (unlogged_heap_init_filename ));
163
- self .assertTrue (found_unlogged_idx_init , "{0} is not found in backup catalogue" .format (unlogged_idx_init_filename ));
164
- self .assertTrue (found_unlogged_toast , "{0} is not found in backup catalogue" .format (unlogged_toast_filename ));
165
- self .assertTrue (found_unlogged_idx_toast_init , "{0} is not found in backup catalogue" .format (unlogged_idx_toast_init_filename ));
136
+ # Physical comparison
137
+ pgdata_restored = self .pgdata_content (node_restored .data_dir )
138
+ self .compare_pgdata (pgdata , pgdata_restored )
166
139
167
140
# Clean after yourself
168
141
self .del_test_dir (module_name , fname )
0 commit comments