11
11
import select
12
12
import psycopg2
13
13
from time import sleep
14
-
14
+ import re
15
15
16
16
idx_ptrack = {
17
17
't_heap' : {
@@ -156,6 +156,14 @@ def __init__(self, *args, **kwargs):
156
156
if 'ARCHIVE_COMPRESSION' in self .test_env :
157
157
if self .test_env ['ARCHIVE_COMPRESSION' ] == 'ON' :
158
158
self .archive_compress = True
159
+ try :
160
+ testgres .configure_testgres (
161
+ cache_initdb = False ,
162
+ cached_initdb_dir = False ,
163
+ cache_pg_config = False ,
164
+ node_cleanup_full = False )
165
+ except :
166
+ pass
159
167
160
168
self .helpers_path = os .path .dirname (os .path .realpath (__file__ ))
161
169
self .dir_path = os .path .abspath (
@@ -193,11 +201,16 @@ def make_simple_node(
193
201
194
202
real_base_dir = os .path .join (self .tmp_path , base_dir )
195
203
shutil .rmtree (real_base_dir , ignore_errors = True )
204
+ os .makedirs (real_base_dir )
196
205
197
206
node = testgres .get_new_node ('test' , base_dir = real_base_dir )
198
- node .init (initdb_params = initdb_params )
207
+ node .should_rm_dirs = True
208
+ node .init (
209
+ initdb_params = initdb_params , allow_streaming = set_replication )
210
+ print (node .data_dir )
199
211
200
212
# Sane default parameters, not a shit with fsync = off from testgres
213
+ node .append_conf ("postgresql.auto.conf" , "max_connections = 100" )
201
214
node .append_conf ("postgresql.auto.conf" , "shared_buffers = 10MB" )
202
215
node .append_conf ("postgresql.auto.conf" , "fsync = on" )
203
216
node .append_conf ("postgresql.auto.conf" , "wal_level = minimal" )
@@ -217,8 +230,13 @@ def make_simple_node(
217
230
218
231
# Allow replication in pg_hba.conf
219
232
if set_replication :
220
- node .set_replication_conf ()
221
- node .append_conf ("postgresql.auto.conf" , "max_wal_senders = 10" )
233
+ node .append_conf (
234
+ "pg_hba.conf" ,
235
+ "local replication all trust\n " )
236
+ node .append_conf (
237
+ "postgresql.auto.conf" ,
238
+ "max_wal_senders = 10" )
239
+
222
240
return node
223
241
224
242
def create_tblspace_in_node (self , node , tblspc_name , tblspc_path = None , cfs = False ):
@@ -235,7 +253,8 @@ def create_tblspace_in_node(self, node, tblspc_name, tblspc_path=None, cfs=False
235
253
)
236
254
237
255
if not tblspc_path :
238
- tblspc_path = os .path .join (node .base_dir , '{0}' .format (tblspc_name ))
256
+ tblspc_path = os .path .join (
257
+ node .base_dir , '{0}' .format (tblspc_name ))
239
258
cmd = "CREATE TABLESPACE {0} LOCATION '{1}'" .format (
240
259
tblspc_name , tblspc_path )
241
260
if cfs :
@@ -272,11 +291,11 @@ def get_md5_per_page_for_fork(self, file, size_in_pages):
272
291
273
292
size = size_in_pages
274
293
for segment_number in range (nsegments ):
275
- if size - 131072 > 0 :
294
+ if size - 131072 > 0 :
276
295
pages_per_segment [segment_number ] = 131072
277
296
else :
278
297
pages_per_segment [segment_number ] = size
279
- size = size - 131072
298
+ size = size - 131072
280
299
281
300
for segment_number in range (nsegments ):
282
301
offset = 0
@@ -369,6 +388,7 @@ def check_ptrack_sanity(self, idx_dict):
369
388
idx_dict ['ptrack' ][PageNum ])
370
389
)
371
390
continue
391
+
372
392
# Ok, all pages in new_pages that do not have
373
393
# corresponding page in old_pages are been dealt with.
374
394
# We can now safely proceed to comparing old and new pages
@@ -394,7 +414,7 @@ def check_ptrack_sanity(self, idx_dict):
394
414
if PageNum == 0 and idx_dict ['type' ] == 'spgist' :
395
415
if self .verbose :
396
416
print (
397
- 'SPGIST is a special snowflake, so don`t'
417
+ 'SPGIST is a special snowflake, so don`t '
398
418
'fret about losing ptrack for blknum 0'
399
419
)
400
420
continue
@@ -721,9 +741,9 @@ def set_archiving(
721
741
archive_mode = 'on'
722
742
723
743
node .append_conf (
724
- "postgresql.auto.conf" ,
725
- "wal_level = archive"
726
- )
744
+ "postgresql.auto.conf" ,
745
+ "wal_level = archive"
746
+ )
727
747
node .append_conf (
728
748
"postgresql.auto.conf" ,
729
749
"archive_mode = {0}" .format (archive_mode )
@@ -817,7 +837,15 @@ def get_username(self):
817
837
return pwd .getpwuid (os .getuid ())[0 ]
818
838
819
839
def version_to_num (self , version ):
820
- return testgres .version_to_num (version )
840
+ if not version :
841
+ return 0
842
+ parts = version .split ("." )
843
+ while len (parts ) < 3 :
844
+ parts .append ("0" )
845
+ num = 0
846
+ for part in parts :
847
+ num = num * 100 + int (re .sub ("[^\d]" , "" , part ))
848
+ return num
821
849
822
850
def switch_wal_segment (self , node ):
823
851
""" Execute pg_switch_wal/xlog() in given node"""
@@ -829,7 +857,11 @@ def switch_wal_segment(self, node):
829
857
node .safe_psql ("postgres" , "select pg_switch_xlog()" )
830
858
831
859
def get_version (self , node ):
832
- return testgres .get_config ()["VERSION_NUM" ]
860
+ return self .version_to_num (
861
+ testgres .get_pg_config ()["VERSION" ].split (" " )[1 ])
862
+
863
+ def get_bin_path (self , binary ):
864
+ return testgres .get_bin_path (binary )
833
865
834
866
def del_test_dir (self , module_name , fname ):
835
867
""" Del testdir and optimistically try to del module dir"""
@@ -960,7 +992,11 @@ def compare_pgdata(self, original_pgdata, restored_pgdata):
960
992
)
961
993
for page in restored_pgdata ['files' ][file ]['md5_per_page' ]:
962
994
if page not in original_pgdata ['files' ][file ]['md5_per_page' ]:
963
- error_message += '\n Extra page {0}\n File: {1}\n ' .format (page , os .path .join (restored_pgdata ['pgdata' ], file ))
995
+ error_message += '\n Extra page {0}\n '
996
+ 'File: {1}\n ' .format (
997
+ page ,
998
+ os .path .join (
999
+ restored_pgdata ['pgdata' ], file ))
964
1000
965
1001
else :
966
1002
error_message += (
0 commit comments