@@ -302,10 +302,6 @@ def __init__(self,
302302 username = username or default_username ()
303303 base_dir = base_dir or tempfile .mkdtemp ()
304304
305- # Create directory if needed
306- if base_dir and not os .path .exists (base_dir ):
307- os .makedirs (base_dir )
308-
309305 # public
310306 self .original_node = node
311307 self .base_dir = base_dir
@@ -1095,7 +1091,7 @@ def replicate(self, name, username=None,
10951091 backup = self .backup (username = username , xlog_method = xlog_method )
10961092 return backup .spawn_replica (name , use_logging = use_logging )
10971093
1098- def catchup (self , username = None ):
1094+ def catchup (self , dbname = 'postgres' , username = None ):
10991095 """
11001096 Wait until async replica catches up with its master.
11011097 """
@@ -1116,8 +1112,13 @@ def catchup(self, username=None):
11161112 raise CatchUpException ("Master node is not specified" )
11171113
11181114 try :
1119- lsn = master .execute ('postgres' , poll_lsn )[0 ][0 ]
1120- self .poll_query_until (dbname = 'postgres' ,
1115+ # fetch latest LSN
1116+ lsn = master .execute (dbname = dbname ,
1117+ username = username ,
1118+ query = poll_lsn )[0 ][0 ]
1119+
1120+ # wait until this LSN reaches replica
1121+ self .poll_query_until (dbname = dbname ,
11211122 username = username ,
11221123 query = wait_lsn .format (lsn ),
11231124 max_attempts = 0 ) # infinite
@@ -1249,41 +1250,39 @@ def _execute_utility(util, args, logfile):
12491250 stdout of executed utility.
12501251 """
12511252
1252- # we can't use subprocess.DEVNULL on 2.7
1253- with open (os .devnull , "w" ) as devnull :
1254- # run utility
1255- process = subprocess .Popen ([get_bin_path (util )] + args ,
1256- stdout = subprocess .PIPE ,
1257- stderr = subprocess .STDOUT )
1253+ # run utility
1254+ process = subprocess .Popen ([get_bin_path (util )] + args ,
1255+ stdout = subprocess .PIPE ,
1256+ stderr = subprocess .STDOUT )
12581257
1259- # get result
1260- out , _ = process .communicate ()
1258+ # get result
1259+ out , _ = process .communicate ()
12611260
1262- # write new log entry if possible
1263- try :
1264- with open (logfile , "a" ) as file_out :
1265- # write util name and args
1266- file_out .write (' ' .join ([util ] + args ))
1267- file_out .write ('\n ' )
1268- if out :
1269- with open (logfile , "ab" ) as file_out :
1270- # write output
1271- file_out .write (out )
1272- except IOError :
1273- pass
1274-
1275- # decode output
1276- out = '' if not out else out .decode ('utf-8' )
1277-
1278- if process .returncode :
1279- error_text = (
1280- u"{} failed\n "
1281- u"log:\n ----\n {}\n "
1282- ).format (util , out )
1283-
1284- raise ExecUtilException (error_text , process .returncode )
1261+ # write new log entry if possible
1262+ try :
1263+ with open (logfile , "a" ) as file_out :
1264+ # write util name and args
1265+ file_out .write (' ' .join ([util ] + args ))
1266+ file_out .write ('\n ' )
1267+ if out :
1268+ with open (logfile , "ab" ) as file_out :
1269+ # write output
1270+ file_out .write (out )
1271+ except IOError :
1272+ pass
1273+
1274+ # decode output
1275+ out = '' if not out else out .decode ('utf-8' )
1276+
1277+ if process .returncode :
1278+ error_text = (
1279+ u"{} failed\n "
1280+ u"log:\n ----\n {}\n "
1281+ ).format (util , out )
12851282
1286- return out
1283+ raise ExecUtilException (error_text , process .returncode )
1284+
1285+ return out
12871286
12881287
12891288def default_username ():
0 commit comments