@@ -411,12 +411,13 @@ def _create_recovery_conf(self, root_node):
411411
412412 self .append_conf ("recovery.conf" , line )
413413
414- def init (self , allow_streaming = False , initdb_params = []):
414+ def init (self , allow_streaming = False , fsync = False , initdb_params = []):
415415 """
416416 Perform initdb for this node.
417417
418418 Args:
419419 allow_streaming: should this node add a hba entry for replication?
420+ fsync: should this node use fsync to keep data safe?
420421 initdb_params: parameters for initdb (list).
421422
422423 Returns:
@@ -447,27 +448,26 @@ def init(self, allow_streaming=False, initdb_params=[]):
447448
448449 # add parameters to config file
449450 with open (postgres_conf , "w" ) as conf :
450- conf .write ("fsync = off\n "
451- "log_statement = all\n "
451+ if not fsync :
452+ conf .write ("fsync = off\n " )
453+
454+ conf .write ("log_statement = all\n "
452455 "port = {}\n " .format (self .port ))
453456
454457 conf .write ("listen_addresses = '{}'\n " .format (self .host ))
455458
456459 if allow_streaming :
457- # TODO: wal_level = hot_standby (9.5)
458- conf .write ("max_wal_senders = 5\n "
459- "wal_keep_segments = 20\n "
460- "wal_log_hints = on\n "
461- "hot_standby = on\n "
462- "max_connections = 10\n " )
463-
464460 cur_ver = LooseVersion (get_pg_config ().get ("VERSION_NUM" ))
465461 min_ver = LooseVersion ('9.6.0' )
466462
467- if cur_ver < min_ver :
468- conf .write ("wal_level = hot_standby\n " )
469- else :
470- conf .write ("wal_level = replica\n " )
463+ # select a proper wal_level for PostgreSQL
464+ wal_level = "hot_standby" if cur_ver < min_ver else "replica"
465+
466+ conf .write ("max_wal_senders = 5\n "
467+ "wal_keep_segments = 20\n "
468+ "hot_standby = on\n "
469+ "max_connections = 10\n "
470+ "wal_level = {}\n " .format (wal_level ))
471471
472472 return self
473473
0 commit comments