pgcli icon indicating copy to clipboard operation
pgcli copied to clipboard

Specifying SSH tunnel local port

Open Smylers opened this issue 2 years ago • 0 comments

Description

Thank you for the new SSH tunnel support; it's really useful. The only thing I'm missing is being able to specify which port to use on localhost to forward to the remote PostgreSQL port.

This is so I can also connect to PostgreSQL using other software, over the same tunnel. I'm using pgcli to help develop and debug software which accesses a database. Prior to pgcli's tunnel support, I would manually set up an SSH tunnel, and set both pgcli and the software I'm developing to connect to that localhost port. Now pgcli nicely automates the connection, but on a random port chosen by the sshtunnel library.

I can find out what this random port number is with \conninfo, and use that for other connections, but it'd be more convenient if I could specify which port number to use for the connection, then I can consistently use that everywhere and not have to adjust other software's config whenever I start pgcli.

Unfortunately, I can't see a neat place to specify this: the port specified with the DSN (or -p) is being used as the PostgreSQL port at the far end of the connection (default 5432) and that in the tunnel spec as the SSH port (default 22). OpenSSH uses syntax like 40000:localhost:5432 to specify a tunnel, but I presume that wouldn't work with urlparse() or would mess up specifying username and hostnames in the same string.

#1301 said “special config can just go in the ssh conf”, but that doesn't work in this case because it's sshtunnel config, not SSH config.

Your environment

Ubuntu 20.04 LTS, running pgcli version 3.4.1

Smylers avatar Jul 14 '22 16:07 Smylers