Skip to main content

Postgres tunnel

info

Available only with a subscription.

Overview​

Postgres tunnel allows you to provide access to a PostgreSQL database and track executed SQL queries in the inspector.

note

Postgres tunnels are designed for debugging and working locally or in test environments, they do not support SSL connections, so you need to use sslmode=disable. We do not recommend using this type of tunnels in production environments.

If the user or password is wrong, the client gets the database error as is, with the SQLSTATE code — for example, FATAL: password authentication failed for user "app" — instead of a dropped connection.

Starting with version 0.36.0, tuna shows a full-screen interface in the terminal with sessions and SQL queries.

Examples​

note

You can view all current flags, hints, and examples by calling help:

tuna postgres --help

Almost all flags have corresponding environment variables.

Basic example​

tuna postgres 5432

With IP address​

tuna postgres 10.0.0.1:5432

Specifying an API key​

You can specify a different API key using the --api-key flag or the TUNA_API_KEY environment variable; the key needs the tunnels:connect scope. Overriding follows the configuration ordering policy.

tuna postgres 5432 --api-key=tak_***

Specifying a connection region​

You can specify a particular region using the --location/-l flag or the TUNA_LOCATION environment variable. Overriding follows the configuration ordering policy.

tuna postgres 5432 --location=nl

Static port​

The value of the --port/-p flag can be an alias or an assigned port. You can reserve ports in the dashboard, and after restarting the tunnel the address will remain the same. For more details about ports, see the dedicated guide.

tuna postgres 5432 --port=postgres
tuna postgres 5432 --port=35000

IP subnet access restriction​

You can define a whitelist of subnets in CIDR format:

tuna postgres 5432 --cidr-allow="10.0.0.1/32"

Or prohibit access from specific subnets:

tuna postgres 5432 --cidr-deny="10.0.0.1/32"

You can combine them, for example specify a wide network and subtract private IPs:

tuna postgres 5432 --cidr-allow="10.0.0.1/24" --cidr-deny="10.0.0.33/32"

You can also pass lists separated by commas:

tuna postgres 5432 --cidr-allow="10.0.0.1/24,192.168.0.1/24" --cidr-deny="10.0.0.33/32,192.168.0.33/32"

Query inspector​

The inspector is always on and available at http://127.0.0.1:4040: sessions on the left, queries of the selected session on the right with duration, result and errors. The next tunnel takes port 4041; set a fixed port with --inspect-port or TUNA_INSPECT_PORT. If you don't need the inspector, use a TCP tunnel.

The CLI logs the inspector address and shows it in the header of the terminal UI. More on the inspector page.

Postgres session: a transaction with durations and command tags