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
@@ -1761,6 +1762,8 @@ def make_simple(
1761
1762
pg_options = {},
1762
1763
checksum = True ,
1763
1764
bin_dir = None ):
1765
+ assert type (pg_options ) == dict # noqa: E721
1766
+
1764
1767
if checksum and '--data-checksums' not in initdb_params :
1765
1768
initdb_params .append ('--data-checksums' )
1766
1769
node = self .make_empty (base_dir , port , bin_dir = bin_dir )
@@ -1773,20 +1776,22 @@ def make_simple(
1773
1776
node .major_version = float (node .major_version_str )
1774
1777
1775
1778
# 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
+ }
1790
1795
1791
1796
# Allow replication in pg_hba.conf
1792
1797
if set_replication :
@@ -1801,11 +1806,16 @@ def make_simple(
1801
1806
else :
1802
1807
options ['wal_keep_segments' ] = '12'
1803
1808
1804
- # set default values
1805
- node .set_auto_conf (options )
1806
-
1807
1809
# 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 )
1809
1819
1810
1820
# kludge for testgres
1811
1821
# https://github.com/postgrespro/testgres/issues/54
@@ -1814,3 +1824,26 @@ def make_simple(
1814
1824
node .set_auto_conf ({}, 'postgresql.conf' , ['wal_keep_segments' ])
1815
1825
1816
1826
return 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 )
0 commit comments