# Connecting with psql

This guide explains how to connect to a **TimescaleDB** database using the **`psql`** command-line tool. It walks through the necessary setup, connection process, and execution of a simple SQL query.

### **Variables**

To connect to a TimescaleDB database, you only need <span class="s1">**one environment variable**</span> — the connection URI.

<table border="1" id="bkmrk-variable-description"><thead><tr><th>**Variable**

</th><th>**Description**

</th><th>**Purpose**

</th></tr></thead><tbody><tr><td>`TIMESCALE_URI`

</td><td>Full TimescaleDB connection string from Elestio

</td><td>Encodes all connection info in one URI

</td></tr></tbody></table>

A typical URI looks like this:

```bash
postgresql://<USER>:<PASSWORD>@<HOST>:<PORT>/<DATABASE>
```

You can find the details needed in the URI from the **Elestio service overview** details. Copy and replace the variables carefully in the URI example provided above.

[![Screenshot 2025-05-13 at 12.30.16 PM.jpg](https://docs.elest.io/uploads/images/gallery/2025-05/scaled-1680-/NKlscreenshot-2025-05-13-at-12-30-16-pm.jpg)](https://docs.elest.io/uploads/images/gallery/2025-05/NKlscreenshot-2025-05-13-at-12-30-16-pm.jpg)

### **Prerequisites**

While following this tutorial, you will need to have **`psql`** already installed; if not head over to [https://www.postgresql.org/download/](https://www.postgresql.org/download/) and download it first.

### **Connecting to TimescaleDB**

Open your terminal and run the following command to connect to your TimescaleDB database using the full connection URI:

```
psql TIMESCALE_URI
```

If the connection is successful, you’ll see output similar to this. Here it will show you the database you tried to connect to, which in this case is Elestio:

```bash
psql (17.4, server 14.13 (Debian 14.13-1.pgdg120+1))
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off, ALPN: none)
Type "help" for help.

elestio=# 
```

<div id="bkmrk--1"><div class="cm-editor ͼ1 ͼ2 ͼ4 ͼ1r"><button class="cm-copy-button" type="button"><svg height="16" viewbox="0 0 24 24" width="16" xmlns="http://www.w3.org/2000/svg"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"></path></svg></button></div></div>To ensure you're connected correctly, run this command inside the `psql` prompt:

```postgresql
SELECT version();
```

You should receive output like the following:

```postgresql
version
---------------------------------------------------------------------------------------------------------------------
PostgreSQL 16.8 (Debian 16.8-1.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
(1 row)
```

<div class="contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary" id="bkmrk--2"><div class="overflow-y-auto p-4" dir="ltr"><div class="contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute bottom-0 right-0 flex h-9 items-center pr-2"><div class="flex items-center rounded bg-token-sidebar-surface-primary px-2 font-sans text-xs text-token-text-secondary dark:bg-token-main-surface-secondary"></div></div></div></div></div></div>