55import signal
66import subprocess
77import threading
8+ import tempfile
89from queue import Queue
910
1011import time
@@ -1761,6 +1762,8 @@ def make_simple(
17611762pg_options = {},
17621763checksum = True ,
17631764bin_dir = None ):
1765+ assert type (pg_options )== dict # noqa: E721
1766+
17641767if checksum and '--data-checksums' not in initdb_params :
17651768initdb_params .append ('--data-checksums' )
17661769node = self .make_empty (base_dir ,port ,bin_dir = bin_dir )
@@ -1773,20 +1776,22 @@ def make_simple(
17731776node .major_version = float (node .major_version_str )
17741777
17751778# Set default parameters
1776- options = {'max_connections' :100 ,
1777- 'shared_buffers' :'10MB' ,
1778- 'fsync' :'off' ,
1779- 'wal_level' :'logical' ,
1780- 'hot_standby' :'off' ,
1781- 'log_line_prefix' :'%t [%p]: [%l-1] ' ,
1782- 'log_statement' :'none' ,
1783- 'log_duration' :'on' ,
1784- 'log_min_duration_statement' :0 ,
1785- 'log_connections' :'on' ,
1786- 'log_disconnections' :'on' ,
1787- 'restart_after_crash' :'off' ,
1788- 'autovacuum' :'off' ,
1789- 'unix_socket_directories' :'/tmp' }
1779+ options = {
1780+ 'max_connections' :100 ,
1781+ 'shared_buffers' :'10MB' ,
1782+ 'fsync' :'off' ,
1783+ 'wal_level' :'logical' ,
1784+ 'hot_standby' :'off' ,
1785+ 'log_line_prefix' :'%t [%p]: [%l-1] ' ,
1786+ 'log_statement' :'none' ,
1787+ 'log_duration' :'on' ,
1788+ 'log_min_duration_statement' :0 ,
1789+ 'log_connections' :'on' ,
1790+ 'log_disconnections' :'on' ,
1791+ 'restart_after_crash' :'off' ,
1792+ 'autovacuum' :'off' ,
1793+ # unix_socket_directories will be defined later
1794+ }
17901795
17911796# Allow replication in pg_hba.conf
17921797if set_replication :
@@ -1801,11 +1806,16 @@ def make_simple(
18011806else :
18021807options ['wal_keep_segments' ]= '12'
18031808
1804- # set default values
1805- node .set_auto_conf (options )
1806-
18071809# Apply given parameters
1808- node .set_auto_conf (pg_options )
1810+ for option_name ,option_value in iteritems (pg_options ):
1811+ options [option_name ]= option_value
1812+
1813+ # Define delayed propertyes
1814+ if not ("unix_socket_directories" in options .keys ()):
1815+ options ["unix_socket_directories" ]= __class__ ._gettempdir ()
1816+
1817+ # Set config values
1818+ node .set_auto_conf (options )
18091819
18101820# kludge for testgres
18111821# https://github.com/postgrespro/testgres/issues/54
@@ -1814,3 +1824,26 @@ def make_simple(
18141824node .set_auto_conf ({},'postgresql.conf' , ['wal_keep_segments' ])
18151825
18161826return node
1827+
1828+ def _gettempdir ():
1829+ v = tempfile .gettempdir ()
1830+
1831+ #
1832+ # Paranoid checks
1833+ #
1834+ if type (v )!= str :# noqa: E721
1835+ __class__ ._raise_bugcheck ("tempfile.gettempdir returned a value with type {0}." .format (type (v ).__name__ ))
1836+
1837+ if v == "" :
1838+ __class__ ._raise_bugcheck ("tempfile.gettempdir returned an empty string." )
1839+
1840+ if not os .path .exists (v ):
1841+ __class__ ._raise_bugcheck ("tempfile.gettempdir returned a not exist path [{0}]." .format (v ))
1842+
1843+ # OK
1844+ return v
1845+
1846+ def _raise_bugcheck (msg ):
1847+ assert type (msg )== str # noqa: E721
1848+ assert msg != ""
1849+ raise Exception ("[BUG CHECK] " + msg )