@@ -539,7 +539,7 @@ def default_conf(self, allow_streaming=True, fsync=False, log_statement='all'):
539539 self .port ))
540540
541541 if allow_streaming :
542- cur_ver = LooseVersion (get_pg_config ()[ "VERSION_NUM" ] )
542+ cur_ver = LooseVersion (get_pg_version () )
543543 min_ver = LooseVersion ('9.6' )
544544
545545 # select a proper wal_level for PostgreSQL
@@ -609,7 +609,10 @@ def get_control_data(self):
609609 Return contents of pg_control file.
610610 """
611611
612- if get_pg_config ()["VERSION_NUM" ] < '9.5.0' :
612+ cur_ver = LooseVersion (get_pg_version ())
613+ min_ver = LooseVersion ('9.5' )
614+
615+ if cur_ver < min_ver :
613616 _params = [self .data_dir ]
614617 else :
615618 _params = ["-D" , self .data_dir ]
@@ -1002,7 +1005,7 @@ def catchup(self):
10021005
10031006 master = self .master
10041007
1005- cur_ver = LooseVersion (get_pg_config ()[ "VERSION_NUM" ] )
1008+ cur_ver = LooseVersion (get_pg_version () )
10061009 min_ver = LooseVersion ('10' )
10071010
10081011 if cur_ver >= min_ver :
@@ -1166,9 +1169,14 @@ def default_username():
11661169
11671170def get_bin_path (filename ):
11681171 """
1169- Return full path to an executable using get_pg_config() .
1172+ Return full path to an executable using PG_BIN or PG_CONFIG .
11701173 """
11711174
1175+ pg_bin_path = os .environ .get ("PG_BIN" )
1176+
1177+ if pg_bin_path :
1178+ return os .path .join (pg_bin_path , filename )
1179+
11721180 pg_config = get_pg_config ()
11731181
11741182 if pg_config and "BINDIR" in pg_config :
@@ -1177,6 +1185,28 @@ def get_bin_path(filename):
11771185 return filename
11781186
11791187
1188+ def get_pg_version ():
1189+ """
1190+ Return PostgreSQL version using PG_BIN or PG_CONFIG.
1191+ """
1192+
1193+ pg_bin_path = os .environ .get ("PG_BIN" )
1194+
1195+ if pg_bin_path :
1196+ _params = ['--version' ]
1197+ raw_ver = _execute_utility ('psql' , _params , os .devnull )
1198+ else :
1199+ raw_ver = get_pg_config ()["VERSION" ]
1200+
1201+ # Cook version of PostgreSQL
1202+ version = raw_ver .strip ().split (" " )[- 1 ] \
1203+ .partition ('devel' )[0 ] \
1204+ .partition ('beta' )[0 ] \
1205+ .partition ('rc' )[0 ]
1206+
1207+ return version
1208+
1209+
11801210def reserve_port ():
11811211 """
11821212 Generate a new port and add it to 'bound_ports'.
@@ -1215,14 +1245,6 @@ def get_pg_config():
12151245 key , value = line .split ("=" , 1 )
12161246 data [key .strip ()] = value .strip ()
12171247
1218- # Fetch version of PostgreSQL and save it as VERSION_NUM
1219- version = data ["VERSION" ]
1220- version = version .split (" " )[- 1 ] \
1221- .partition ('devel' )[0 ] \
1222- .partition ('beta' )[0 ] \
1223- .partition ('rc' )[0 ]
1224- data ["VERSION_NUM" ] = version
1225-
12261248 if TestgresConfig .cache_pg_config :
12271249 pg_config_data .clear ()
12281250 pg_config_data .update (data )
0 commit comments