@@ -112,13 +112,20 @@ def utils_log_name(self):
112
112
def pg_log_name (self ):
113
113
return os .path .join (self .data_dir , _PG_LOG_FILE )
114
114
115
- @property
116
- def connstr (self ):
117
- return "port={}" .format (self .port )
115
+ def _create_recovery_conf (self , username , master ):
116
+ # yapf: disable
117
+ conninfo = (
118
+ u"user={} "
119
+ u"port={} "
120
+ u"host={} "
121
+ u"application_name={}"
122
+ ).format (username , master .port , master .host , master .name )
118
123
119
- def _create_recovery_conf (self , root_node ):
120
- line = ("primary_conninfo='{} application_name={}'\n "
121
- "standby_mode=on\n " ).format (root_node .connstr , self .name )
124
+ # yapf: disable
125
+ line = (
126
+ "primary_conninfo='{}'\n "
127
+ "standby_mode=on\n "
128
+ ).format (conninfo )
122
129
123
130
self .append_conf ("recovery.conf" , line )
124
131
@@ -175,13 +182,18 @@ def print_node_file(node_file):
175
182
176
183
return error_text
177
184
178
- def init (self , allow_streaming = False , fsync = False , initdb_params = []):
185
+ def init (self ,
186
+ fsync = False ,
187
+ unix_sockets = True ,
188
+ allow_streaming = False ,
189
+ initdb_params = []):
179
190
"""
180
191
Perform initdb for this node.
181
192
182
193
Args:
183
- allow_streaming: should this node add a hba entry for replication?
184
194
fsync: should this node use fsync to keep data safe?
195
+ unix_sockets: should we enable UNIX sockets?
196
+ allow_streaming: should this node add a hba entry for replication?
185
197
initdb_params: parameters for initdb (list).
186
198
187
199
Returns:
@@ -196,22 +208,25 @@ def init(self, allow_streaming=False, fsync=False, initdb_params=[]):
196
208
_cached_initdb (self .data_dir , initdb_log , initdb_params )
197
209
198
210
# initialize default config files
199
- self .default_conf (allow_streaming = allow_streaming , fsync = fsync )
211
+ self .default_conf (fsync = fsync ,
212
+ unix_sockets = unix_sockets ,
213
+ allow_streaming = allow_streaming )
200
214
201
215
return self
202
216
203
217
def default_conf (self ,
204
- allow_streaming = False ,
205
218
fsync = False ,
219
+ unix_sockets = True ,
220
+ allow_streaming = False ,
206
221
log_statement = 'all' ):
207
222
"""
208
223
Apply default settings to this node.
209
224
210
225
Args:
211
- allow_streaming: should this node add a hba entry for replication?
212
226
fsync: should this node use fsync to keep data safe?
213
- log_statement: one of ('all', 'off', 'mod', 'ddl'), look at
214
- PostgreSQL docs for more information
227
+ unix_sockets: should we enable UNIX sockets?
228
+ allow_streaming: should this node add a hba entry for replication?
229
+ log_statement: one of ('all', 'off', 'mod', 'ddl').
215
230
216
231
Returns:
217
232
This instance of PostgresNode.
@@ -258,6 +273,9 @@ def get_auth_method(t):
258
273
259
274
# overwrite postgresql.conf file
260
275
with io .open (postgres_conf , "w" ) as conf :
276
+ # remove old lines
277
+ conf .truncate ()
278
+
261
279
if not fsync :
262
280
conf .write (u"fsync = off\n " )
263
281
@@ -287,6 +305,10 @@ def get_auth_method(t):
287
305
wal_keep_segments ,
288
306
wal_level ))
289
307
308
+ # disable UNIX sockets if asked to
309
+ if not unix_sockets :
310
+ conf .write (u"unix_socket_directories = ''\n " )
311
+
290
312
return self
291
313
292
314
def append_conf (self , filename , string ):
@@ -784,7 +806,7 @@ def replicate(self,
784
806
"""
785
807
786
808
backup = self .backup (username = username , xlog_method = xlog_method )
787
- return backup .spawn_replica (name , use_logging = use_logging )
809
+ return backup .spawn_replica (name = name , use_logging = use_logging )
788
810
789
811
def catchup (self , dbname = 'postgres' , username = None ):
790
812
"""
0 commit comments