@@ -119,8 +119,17 @@ def get_pg_major_version():
119
119
return int (major_version_string .group (0 ))
120
120
121
121
122
+ def get_bin_dir ():
123
+ pg_config_bin = (
124
+ os .environ ["PG_CONFIG" ] if "PG_CONFIG" in os .environ else "pg_config"
125
+ )
126
+ return capture ([pg_config_bin , "--bindir" ], silent = True ).strip ()
127
+
128
+
122
129
PG_MAJOR_VERSION = get_pg_major_version ()
123
130
131
+ PG_BIN_DIR = get_bin_dir ()
132
+
124
133
# this is out of ephemeral port range for many systems hence
125
134
# it is a lower change that it will conflict with "in-use" ports
126
135
PORT_LOWER_BOUND = 10200
@@ -131,6 +140,10 @@ def get_pg_major_version():
131
140
next_port = PORT_LOWER_BOUND
132
141
133
142
143
+ def pg_bin (b ):
144
+ return os .path .join (PG_BIN_DIR , b )
145
+
146
+
134
147
class NoResultClass :
135
148
def __eq__ (self , other ):
136
149
return self is other
@@ -393,7 +406,15 @@ def psql(self, query, **kwargs):
393
406
self .set_default_connection_options (kwargs )
394
407
connect_options = " " .join ([f"{ k } ={ v } " for k , v in kwargs .items ()])
395
408
396
- run (["psql" , f"port={ self .port } { connect_options } " , "-c" , query ], shell = False )
409
+ run (
410
+ [
411
+ pg_bin ("psql" ),
412
+ f"port={ self .port } { connect_options } " ,
413
+ "-c" ,
414
+ query ,
415
+ ],
416
+ shell = False ,
417
+ )
397
418
398
419
@contextmanager
399
420
def transaction (self , ** kwargs ):
@@ -541,13 +562,14 @@ def debug(self):
541
562
def psql_debug (self , ** kwargs ):
542
563
conninfo = self .make_conninfo (** kwargs )
543
564
run (
544
- ["psql" , conninfo ],
565
+ [pg_bin ( "psql" ) , conninfo ],
545
566
silent = True ,
546
567
)
547
568
548
569
def initdb (self ):
570
+ initdb = pg_bin ("initdb" )
549
571
run (
550
- f"initdb -A trust --nosync --username postgres --pgdata { self .pgdata } " ,
572
+ f"' { initdb } ' -A trust --nosync --username postgres --pgdata { self .pgdata } " ,
551
573
stdout = subprocess .DEVNULL ,
552
574
)
553
575
@@ -595,11 +617,17 @@ def initdb(self):
595
617
pgconf .write ("duckdb.force_execution = 'true'\n " )
596
618
597
619
def pgctl (self , command , ** kwargs ):
598
- run (f"pg_ctl -w --pgdata { self .pgdata } { command } " , ** kwargs )
620
+ pg_ctl = pg_bin ("pg_ctl" )
621
+ run (
622
+ f"'{ pg_ctl } ' -w --pgdata { self .pgdata } { command } " ,
623
+ ** kwargs ,
624
+ )
599
625
600
626
def apgctl (self , command , ** kwargs ):
627
+ pg_ctl = pg_bin ("pg_ctl" )
601
628
return asyncio .create_subprocess_shell (
602
- f"pg_ctl -w --pgdata { self .pgdata } { command } " , ** kwargs
629
+ f"'{ pg_ctl } ' -w --pgdata { self .pgdata } { command } " ,
630
+ ** kwargs ,
603
631
)
604
632
605
633
def start (self ):
0 commit comments