Skip to main content
The Upsun CLI includes upsun sql, a quick way to run queries against your database from the command line. But sometimes you want more than a basic prompt. You want autocomplete, syntax highlighting, a visual schema browser, and the ability to scroll through large result sets. That’s where Harlequin comes in. Harlequin is a terminal-based (TUI) SQL IDE that brings a rich, interactive experience to your shell. It includes a data catalog for browsing tables and columns, a query editor with autocompletion, and a results viewer that handles millions of rows. All without leaving your terminal. This tutorial covers two ways to use Harlequin with your Upsun PostgreSQL database:
  1. Run Harlequin locally and connect through an SSH tunnel
  2. Install Harlequin on your Upsun environment and access it via SSH
Both approaches give you the same powerful interface. Choose the one that fits your workflow. Harlequin's interface showing the data catalog, query editor, and results pane

Prerequisites

Before you start, make sure you have:
  • An Upsun account with a project deployed
  • A PostgreSQL service configured in your .upsun/config.yaml
  • The Upsun CLI installed and authenticated
  • For Option 1: Python 3.10+ and uv (or pip) installed locally
Your project should have a PostgreSQL service defined. If you don’t have one yet, add this to your .upsun/config.yaml:

Option 1: Run Harlequin locally with an SSH tunnel

This approach keeps Harlequin on your local machine and connects to Upsun through a secure SSH tunnel. It’s ideal for day-to-day development when you want quick access to your database without modifying your deployment.

Install Harlequin with the PostgreSQL adapter

Harlequin uses adapters to connect to different database types. Install both Harlequin and its PostgreSQL adapter:
Alternatively, you can use pip:
Or Homebrew on macOS:
Verify the installation:

Open an SSH tunnel to your Upsun services

The Upsun CLI can create SSH tunnels to all services in your environment. Run:
You’ll see output similar to:
Note the connection details. In this example:
  • Host: 127.0.0.1
  • Port: 30000
  • Username: main
  • Password: main
  • Database: main
Your values may differ depending on your configuration.

Connect Harlequin to the tunnel

With the tunnel open, launch Harlequin using the connection details:
You can also pass the connection parameters individually:
Harlequin opens in your terminal, ready to explore your database.

Explore your database

harlequin-tunnel Once connected, you can:
  • Browse the data catalog: The left sidebar shows all schemas, tables, and columns in your database
  • Write queries: The center pane is a full-featured editor with syntax highlighting and autocomplete (press Ctrl+Space to trigger suggestions)
  • View results: Execute queries with Ctrl+Enter and scroll through results in the bottom pane
  • Export data: Select results and export to CSV, JSON, or Parquet formats
Press F1 to see all keyboard shortcuts. When you’re done, close the tunnel:

Option 2: Install Harlequin on Upsun

If you prefer to keep your tools on the platform, or want consistent access for your team, you can install Harlequin directly in your Upsun environment. Since Harlequin is a terminal UI, you’ll access it by SSH-ing into your container.

Add Harlequin to your build hook

Modify your .upsun/config.yaml to install Harlequin during the build phase. Add the pip install command to your existing build hook:
If your application isn’t Python-based, you can still install Harlequin. Python is available in most Upsun containers. Add a build hook that installs it:

Deploy your changes

Commit and push your configuration changes:
Wait for the deployment to complete.

SSH into your environment

Connect to your running container:

Launch Harlequin

Upsun generate one environment variable for the database DSN automatically (see Service Environment variables):
The name can vary as it is using the relationships name in the myapp section of the .upsun/config.yaml file (e.g. database: in the example above) You can now launch Harlequin:
If you want to avoid specifying the whole path, update your PATH variable in the deploy hook of your application:

Tips and best practices

Create a shell alias for quick access

If you use Option 1 frequently, add an alias to your shell configuration:

Use read-only credentials for safety

When exploring production data, consider creating a read-only PostgreSQL user to prevent accidental modifications. You can configure additional database endpoints in your services configuration.

Keyboard shortcuts

Here are the most useful Harlequin shortcuts:

Query history

Harlequin automatically saves your query history. Press F8 to browse previous queries and re-run them.

Conclusion

You now have two ways to use Harlequin with your Upsun PostgreSQL database:
  1. Local installation with SSH tunnel: Best for individual developers who want quick, on-demand access
  2. Installed on Upsun: Best for team environments or when you want tools available directly on the platform
Both approaches give you a powerful, visual way to explore and query your data without leaving the terminal. For more Harlequin features and configuration options, check out the official documentation. Ready to try it out? Create a free Upsun account and deploy your first PostgreSQL-powered application.
Last modified on April 27, 2026