@@ -76,11 +76,14 @@ def is_port_open(host, port):
7676except socket .error :
7777return False
7878
79- def establish_ssh_tunnel (self ,local_port ,remote_port ):
79+ def establish_ssh_tunnel (self ,local_port ,remote_port , host ):
8080"""
8181 Establish an SSH tunnel from a local port to a remote PostgreSQL port.
8282 """
83- ssh_cmd = ['-N' ,'-L' ,f"{ local_port } :localhost:{ remote_port } " ]
83+ if host != 'localhost' :
84+ ssh_cmd = ['-N' ,'-L' ,f"localhost:{ local_port } :{ host } :{ remote_port } " ]
85+ else :
86+ ssh_cmd = ['-N' ,'-L' ,f"{ local_port } :{ host } :{ remote_port } " ]
8487self .tunnel_process = self .exec_command (ssh_cmd ,get_process = True ,timeout = 300 )
8588timeout = 10
8689start_time = time .time ()
@@ -412,10 +415,10 @@ def db_connect(self, dbname, user, password=None, host="localhost", port=5432):
412415 """
413416local_port = reserve_port ()
414417self .tunnel_port = local_port
415- self .establish_ssh_tunnel (local_port = local_port ,remote_port = port )
418+ self .establish_ssh_tunnel (local_port = local_port ,remote_port = port , host = host )
416419try :
417420conn = pglib .connect (
418- host = host ,
421+ host = 'localhost' ,
419422port = local_port ,
420423database = dbname ,
421424user = user ,