tpsql
is a command-line tool that simplifies connecting to PostgreSQL databases through various types of tunnels. It provides an easy interface to call psql over secure and flexible tunneling mechanisms without have to run the tunnel separately. Currently, tpsql supports SSH and Kubernetes tunnels, with the possibility to extend support to other tunneling methods in the future.
- Connect to PostgreSQL databases via various tunnels mechanism. Currently supports SSH tunnel and kubernetes port-forward.
- Simple and familiar interface to use alongside the psql command-line tool.
psql
(PostgreSQL client)ssh
(SSH client) if you are willing to use SSH tunnel
- Download latest version of
tpsql
from github release.
wget https://github.com/orhan89/tpsql/releases/download/v0.1.0/tpsql_Linux_x86_64.tar.gz
- Extract the downloaded archive
tar -xzf tpsql_Linux_x86_64.tar.gz
- Move
tpsql
binary into PATH directory
mv tpsql /usr/local/bin/
To use tpsql
you need to select the tunnel type using --tunnel-type
parameter (default to ssh
) along with the selected tunnel type specific arguments, followed by arguments for the psql separated by --
tpsql --tunnel-type <tunnel-type> [tunnel specific arguments] -- [normal psql arguments]
Establishes an SSH tunnel to the remote host for PostgreSQL.
Example:
tpsql --tunnel-type ssh --sshHost remote.example.com --sshUser myUser -- --host postgres.internal --port 5432 --dbname mydb --user myuser
This will establish an SSH tunnel to the remote host remote.example.com
and connect to the PostgreSQL instance at postgres.internal
running on port 5432
.
Uses kubernetes port-forward
to create a tunnel to a PostgreSQL pod within a Kubernetes cluster.
Example:
tpsql --tunnel-type k8s --k8sNamespace myNamespace --k8sResourceType pods --k8sResourceName postgresql-pod-1 -- --dbname mydb --user myuser
- Support for additional tunneling methods such as IAP
- Improved error handling and logging.
- Automatic tunnel management and reconnection.
Contributions are welcome! Please open an issue or submit a pull request on GitHub if you'd like to contribute or report a bug.
This project is licensed under the MIT License - see the LICENSE file for details.