5
5
import signal
6
6
import subprocess
7
7
import threading
8
+ import tempfile
8
9
from queue import Queue
9
10
10
11
import time
@@ -1781,6 +1782,8 @@ def make_simple(
1781
1782
pg_options = {},
1782
1783
checksum = True ,
1783
1784
bin_dir = None ):
1785
+ assert type (pg_options ) == dict # noqa: E721
1786
+
1784
1787
if checksum and '--data-checksums' not in initdb_params :
1785
1788
initdb_params .append ('--data-checksums' )
1786
1789
node = self .make_empty (base_dir , port , bin_dir = bin_dir )
@@ -1793,20 +1796,22 @@ def make_simple(
1793
1796
node .major_version = float (node .major_version_str )
1794
1797
1795
1798
# Set default parameters
1796
- options = {'max_connections' : 100 ,
1797
- 'shared_buffers' : '10MB' ,
1798
- 'fsync' : 'off' ,
1799
- 'wal_level' : 'logical' ,
1800
- 'hot_standby' : 'off' ,
1801
- 'log_line_prefix' : '%t [%p]: [%l-1] ' ,
1802
- 'log_statement' : 'none' ,
1803
- 'log_duration' : 'on' ,
1804
- 'log_min_duration_statement' : 0 ,
1805
- 'log_connections' : 'on' ,
1806
- 'log_disconnections' : 'on' ,
1807
- 'restart_after_crash' : 'off' ,
1808
- 'autovacuum' : 'off' ,
1809
- 'unix_socket_directories' : '/tmp' }
1799
+ options = {
1800
+ 'max_connections' : 100 ,
1801
+ 'shared_buffers' : '10MB' ,
1802
+ 'fsync' : 'off' ,
1803
+ 'wal_level' : 'logical' ,
1804
+ 'hot_standby' : 'off' ,
1805
+ 'log_line_prefix' : '%t [%p]: [%l-1] ' ,
1806
+ 'log_statement' : 'none' ,
1807
+ 'log_duration' : 'on' ,
1808
+ 'log_min_duration_statement' : 0 ,
1809
+ 'log_connections' : 'on' ,
1810
+ 'log_disconnections' : 'on' ,
1811
+ 'restart_after_crash' : 'off' ,
1812
+ 'autovacuum' : 'off' ,
1813
+ # unix_socket_directories will be defined later
1814
+ }
1810
1815
1811
1816
# Allow replication in pg_hba.conf
1812
1817
if set_replication :
@@ -1821,11 +1826,16 @@ def make_simple(
1821
1826
else :
1822
1827
options ['wal_keep_segments' ] = '12'
1823
1828
1824
- # set default values
1825
- node .set_auto_conf (options )
1826
-
1827
1829
# Apply given parameters
1828
- node .set_auto_conf (pg_options )
1830
+ for option_name , option_value in iteritems (pg_options ):
1831
+ options [option_name ] = option_value
1832
+
1833
+ # Define delayed propertyes
1834
+ if not ("unix_socket_directories" in options .keys ()):
1835
+ options ["unix_socket_directories" ] = __class__ ._gettempdir ()
1836
+
1837
+ # Set config values
1838
+ node .set_auto_conf (options )
1829
1839
1830
1840
# kludge for testgres
1831
1841
# https://github.com/postgrespro/testgres/issues/54
@@ -1834,3 +1844,26 @@ def make_simple(
1834
1844
node .set_auto_conf ({}, 'postgresql.conf' , ['wal_keep_segments' ])
1835
1845
1836
1846
return node
1847
+
1848
+ def _gettempdir ():
1849
+ v = tempfile .gettempdir ()
1850
+
1851
+ #
1852
+ # Paranoid checks
1853
+ #
1854
+ if type (v ) != str : # noqa: E721
1855
+ __class__ ._raise_bugcheck ("tempfile.gettempdir returned a value with type {0}." .format (type (v ).__name__ ))
1856
+
1857
+ if v == "" :
1858
+ __class__ ._raise_bugcheck ("tempfile.gettempdir returned an empty string." )
1859
+
1860
+ if not os .path .exists (v ):
1861
+ __class__ ._raise_bugcheck ("tempfile.gettempdir returned a not exist path [{0}]." .format (v ))
1862
+
1863
+ # OK
1864
+ return v
1865
+
1866
+ def _raise_bugcheck (msg ):
1867
+ assert type (msg ) == str # noqa: E721
1868
+ assert msg != ""
1869
+ raise Exception ("[BUG CHECK] " + msg )
0 commit comments