# How to Connect

# Connecting with Node.js

This guide explains how to establish a connection between a Node.js application and a PostgreSQL database using the `pg` package. It walks through the necessary setup, configuration, and execution of a simple SQL query.

## **Variables**

Certain parameters must be provided to establish a successful connection to a PostgreSQL database. Below is a breakdown of each required variable, its purpose, and where to find it. Here’s what each variable represents:

<table border="1" id="bkmrk-variable-description" style="border-collapse: collapse; width: 100%; height: 178.781px;"><colgroup><col style="width: 16.329%;"></col><col style="width: 41.8355%;"></col><col style="width: 41.8355%;"></col></colgroup><thead><tr style="height: 29.7969px;"><td style="height: 29.7969px;">**Variable**  
</td><td style="height: 29.7969px;">**Description**  
</td><td>**Purpose**</td></tr></thead><tbody><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`USER`</td><td style="height: 29.7969px;">PostgreSQL username, from the Elestio service overview page</td><td>Identifies the database user who has permission to access the PostgreSQL database.</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`PASSWORD`</td><td style="height: 29.7969px;">PostgreSQL password, from the Elestio service overview page</td><td>The authentication key required for the specified `USER` to access the database</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`HOST`</td><td style="height: 29.7969px;">Hostname for PostgreSQL connection, from the Elestio service overview page</td><td>The address of the server hosting the PostgreSQL database.</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`PORT`</td><td style="height: 29.7969px;">Port for PostgreSQL connection, from the Elestio service overview page</td><td>The network port is used to connect to PostgreSQL. The default port is `5432`.</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`DATABASE`</td><td style="height: 29.7969px;">Database Name for PostgreSQL connection, from the Elestio service overview page</td><td>The name of the database being accessed. A PostgreSQL instance can contain multiple databases.</td></tr></tbody></table>

These values can usually be found in the Elestio service overview details as shown in the image below, make sure to take a copy of these details and add it to the code moving ahead.

[![Screenshot 2025-03-20 at 12.34.30 PM.jpg](https://docs.elest.io/uploads/images/gallery/2025-03/scaled-1680-/screenshot-2025-03-20-at-12-34-30-pm.jpg)](https://docs.elest.io/uploads/images/gallery/2025-03/screenshot-2025-03-20-at-12-34-30-pm.jpg)

## **Prerequisites**

- **Install Node.js and NPM**
    
    
    - Check if Node.js is installed by running: <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><div class="overflow-y-auto p-4" dir="ltr">`node -v`</div></div>
    - If not installed, download it from [nodejs.org](https://nodejs.org/) and install.
    - Verify npm installation: <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><div class="overflow-y-auto p-4" dir="ltr">`npm -v`</div></div>
- **Install the `pg` Package**  
    The `pg` package enables Node.js applications to interact with PostgreSQL. Install it using:
    
    <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><div class="overflow-y-auto p-4" dir="ltr">`npm install pg --save`</div></div>

## **Code**

Once all prerequisites are set up, create a new file named `pg.js` and add the following code:

```javascript
const pg = require("pg"); 

// Database connection configuration
const config = {
  user: "USER", 
  password: "PASSWORD",
  host: "HOST",
  port: "PORT",
  database: "DATABASE",
};

// Create a new PostgreSQL client
const client = new pg.Client(config);

// Connect to the database
client.connect((err) => {
  if (err) {
    console.error("Connection failed:", err);
    return;
  }
  console.log("Connected to PostgreSQL");

  // Run a test query to check the PostgreSQL version
  client.query("SELECT VERSION()", [], (err, result) => {
    if (err) {
      console.error("Query execution failed:", err);
      client.end();
      return;
    }

    console.log("PostgreSQL Version:", result.rows[0]);

    // Close the database connection
    client.end((err) => {
      if (err) console.error("Error closing connection:", err);
    });
  });
});

```

To execute the script, open the terminal or command prompt and navigate to the directory where `pg.js`. Once in the correct directory, run the script with the command

```bash
node pg.js
```

If the connection is successful, the terminal will display output similar to:

```bash
Connected to PostgreSQL
PostgreSQL Version: {
  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'
}
```

# Connecting with Python

This guide explains how to establish a connection between a **Python** application and a **PostgreSQL** database using the **`psycopg2-binary`** package. It walks through the necessary setup, configuration, and execution of a simple SQL query.

### **Variables**

To connect to a PostgreSQL database, you only need one environment variable — the **connection URI**. This URI contains all the necessary information like username, password, host, port, and database name.

<div class="overflow-x-auto contain-inline-size" id="bkmrk-variable-description"><table border="1" data-end="1005" data-start="750" style="border-collapse: collapse; border-color: rgb(0, 0, 0);"><thead data-end="786" data-start="750"><tr data-end="786" data-start="750"><th data-end="761" data-start="750" style="border-color: rgb(0, 0, 0);">Variable</th><th data-end="775" data-start="761" style="border-color: rgb(0, 0, 0);">Description</th><th data-end="786" data-start="775" style="border-color: rgb(0, 0, 0);">Purpose</th></tr></thead><tbody data-end="1005" data-start="824"><tr data-end="1005" data-start="824"><td style="border-color: rgb(0, 0, 0);">**POSTGRESQL\_URI**</td><td style="border-color: rgb(0, 0, 0);">Full PostgreSQL connection string (from the Elestio service overview page)</td><td style="border-color: rgb(0, 0, 0);">Provides all necessary credentials and endpoint details in a single URI format.</td></tr></tbody></table>

</div>The URI will look 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.

![image.png](https://docs.elest.io/uploads/images/gallery/2025-03/scaled-1680-/ZvEimage.png)

### **Prerequisites**

##### **Install Python**

Check if Python is installed by running:

```bash
python --version
```

If not installed, download it from [python.org](https://www.python.org/) and install it.

##### **Install `psycopg2-binary` Package**

The `psycopg2-binary` package enables Python applications to interact with PostgreSQL. Install it using:

```bash
pip install psycopg2-binary
```

### **Code**

Once all prerequisites are set up, create a new file named `pg.py` and add the following code and replace the `POSTGRESQL_URI` with actual link or in environment setup as you wish:

```python
import psycopg2

def get_db_version():
    try:
        db_connection = psycopg2.connect('POSTGRESQL_URI')
        db_cursor = db_connection.cursor()
        db_cursor.execute('SELECT VERSION()')
        db_version = db_cursor.fetchone()[0]
        return db_version
        
    except Exception as e:
        print(f"Database connection error: {e}")
        return None
        
    finally:
        if 'db_cursor' in locals():
            db_cursor.close()
        if 'db_connection' in locals():
            db_connection.close()

def display_version():
    version = get_db_version()
    if version:
        print(f"Connected to PostgreSQL: {version}")

if __name__ == "__main__":
    display_version()
```

To execute the script, open the terminal or command prompt and navigate to the directory where `pg.py`. Once in the correct directory, run the script with the command

```bash
python pg.py
```

If the connection is successful, the terminal will display output similar to:

```
Connected to PostgreSQL: 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
```

<div id="bkmrk--1"><div class="cm-editor ͼ1 ͼ2 ͼ4 ͼ1q"><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>

# Connecting with PHP

This guide explains how to establish a connection between a **PHP** application and a **PostgreSQL** database using the built-in `PDO` extension. It walks through the necessary setup, configuration, and execution of a simple SQL query.

### **Variables**

To connect to a PostgreSQL database, you only need one environment variable — the **connection URI**. This URI contains all the necessary information like username, password, host, port, and database name.

<div class="overflow-x-auto contain-inline-size" id="bkmrk-variable-description"><table border="1" data-end="1005" data-start="750" style="border-collapse: collapse; border-color: rgb(0, 0, 0);"><thead data-end="786" data-start="750"><tr data-end="786" data-start="750"><th data-end="761" data-start="750" style="border-color: rgb(0, 0, 0);">Variable</th><th data-end="775" data-start="761" style="border-color: rgb(0, 0, 0);">Description</th><th data-end="786" data-start="775" style="border-color: rgb(0, 0, 0);">Purpose</th></tr></thead><tbody data-end="1005" data-start="824"><tr data-end="1005" data-start="824"><td style="border-color: rgb(0, 0, 0);">**POSTGRESQL\_URI**</td><td style="border-color: rgb(0, 0, 0);">Full PostgreSQL connection string (from the Elestio service overview page)</td><td style="border-color: rgb(0, 0, 0);">Provides all necessary credentials and endpoint details in a single URI format.</td></tr></tbody></table>

</div>The URI will look 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.

![image.png](https://docs.elest.io/uploads/images/gallery/2025-03/scaled-1680-/ZvEimage.png)

### **Prerequisites**

##### **Install PHP**

Check if PHP is installed by running:

```bash
php -v
```

If not installed, download and install it from [https://www.php.net/downloads.php](https://www.php.net/downloads.php).

### **Code**

Once all prerequisites are set up, create a new file named `pg.php` and add the following code and replace the `POSTGRESQL_URI` with actual link or in environment setup as you wish:

```php
<?php

$db_url = "POSTGRESQL_URI";//Replace with actual URI
$db_parts = parse_url($db_url);

$dsn = "pgsql:host={$db_parts['host']};port={$db_parts['port']};dbname=Elestio";//Replace with your DB name
$pdo = new PDO($dsn, $db_parts['user'], $db_parts['pass']);

$version = $pdo->query("SELECT VERSION()")->fetchColumn();
echo $version;
```

To execute the script, open the terminal or command prompt and navigate to the directory where `pg.php`. Once in the correct directory, run the script with the command

```kotlin
php pg.php
```

If the connection is successful, the terminal will display output similar to:

```bash
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
```

# Connecting with Go

This guide explains how to establish a connection between a **Go (Golang)** application and a **PostgreSQL** database using the `github.com/lib/pq` driver. It walks through the necessary setup, configuration, and execution of a simple SQL query.

### **Variables**

To connect to a PostgreSQL database, you only need one environment variable — the **connection URI**. This URI contains all the necessary information like username, password, host, port, and database name.

<div class="overflow-x-auto contain-inline-size" id="bkmrk-variable-description"><table border="1" data-end="1005" data-start="750" style="border-collapse: collapse; border-color: rgb(0, 0, 0);"><thead data-end="786" data-start="750"><tr data-end="786" data-start="750"><th data-end="761" data-start="750" style="border-color: rgb(0, 0, 0);">Variable</th><th data-end="775" data-start="761" style="border-color: rgb(0, 0, 0);">Description</th><th data-end="786" data-start="775" style="border-color: rgb(0, 0, 0);">Purpose</th></tr></thead><tbody data-end="1005" data-start="824"><tr data-end="1005" data-start="824"><td style="border-color: rgb(0, 0, 0);">**POSTGRESQL\_URI**</td><td style="border-color: rgb(0, 0, 0);">Full PostgreSQL connection string (from the Elestio service overview page)</td><td style="border-color: rgb(0, 0, 0);">Provides all necessary credentials and endpoint details in a single URI format.</td></tr></tbody></table>

</div>The URI will look 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.

![image.png](https://docs.elest.io/uploads/images/gallery/2025-03/scaled-1680-/ZvEimage.png)

### **Prerequisites**

##### **Install Go**

Check if Go is installed by running:

```bash
go version
```

If not installed, download and install it from [https://go.dev/dl/](https://go.dev/dl/).

##### **Install `pq` Package**

Install the `pq` driver using:

```bash
go get github.com/lib/pq
```

### **Code**

Once all prerequisites are set up, create a new file named `main.go` and add the following code, and replace the `POSTGRESQL_URI` with actual link or in environment setup as you wish:

```go
package main

import (
	"database/sql"
	"fmt"
	"log"
	"net/url"

	_ "github.com/lib/pq"
)

func getDBConnection(connectionString string) (*sql.DB, error) {
	parsedURL, err := url.Parse(connectionString)
	if err != nil {
		return nil, fmt.Errorf("Failed to parse connection string: %v", err)
	}

	db, err := sql.Open("postgres", parsedURL.String())
	if err != nil {
		return nil, fmt.Errorf("Failed to open database connection: %v", err)
	}

	return db, nil
}

func main() {
	connectionString := "POSTGRESQL_URI"

	db, err := getDBConnection(connectionString)
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()

	query := "SELECT current_database(), current_user, version()"
	rows, err := db.Query(query)
	if err != nil {
		log.Fatal("Failed to execute query:", err)
	}
	defer rows.Close()

	for rows.Next() {
		var dbName, user, version string
		if err := rows.Scan(&dbName, &user, &version); err != nil {
			log.Fatal("Failed to scan row:", err)
		}
		fmt.Printf("Database: %s\nUser: %s\nVersion: %s\n", dbName, user, version)
	}
}

```

To execute the script, open the terminal or command prompt and navigate to the directory where `main.go`. Once in the correct directory, run the script with the command

```bash
go run main.go
```

If the connection is successful, the terminal will display output similar to:

```
Database: Elestio
User: postgres
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
```

<div id="bkmrk--1"><div class="cm-editor ͼ1 ͼ2 ͼ4 ͼ1q"><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>

# Connecting with Java

This guide explains how to establish a connection between a **Java** application and a **PostgreSQL** database using the **JDBC driver**. It walks through the necessary setup, configuration, and execution of a simple SQL query.

## **Variables**

Certain parameters must be provided to establish a successful connection to a PostgreSQL database. Below is a breakdown of each required variable, its purpose, and where to find it. Here’s what each variable represents:

<table border="1" id="bkmrk-variable-description" style="width: 100%;"><colgroup><col style="width: 10.7229%;"></col><col style="width: 39.0983%;"></col><col style="width: 50.1788%;"></col></colgroup><thead><tr><td>**Variable**  
</td><td>**Description**  
</td><td>**Purpose**</td></tr></thead><tbody><tr><td>`USER`</td><td>PostgreSQL username, from the Elestio service overview page</td><td>Identifies the database user who has permission to access the PostgreSQL database.</td></tr><tr><td>`PASSWORD`</td><td>PostgreSQL password, from the Elestio service overview page</td><td>The authentication key required for the specified `USER` to access the database</td></tr><tr><td>`HOST`</td><td>Hostname for PostgreSQL connection, from the Elestio service overview page</td><td>The address of the server hosting the PostgreSQL database.</td></tr><tr><td>`PORT`</td><td>Port for PostgreSQL connection, from the Elestio service overview page</td><td>The network port is used to connect to PostgreSQL. The default port is `5432`.</td></tr><tr><td>`DATABASE`</td><td>Database Name for PostgreSQL connection, from the Elestio service overview page</td><td>The name of the database being accessed. A PostgreSQL instance can contain multiple databases.</td></tr></tbody></table>

These values can usually be found in the Elestio service overview details, as shown in the image below. Make sure to take a copy of these details and add them to the code moving ahead.

![Screenshot 2025-03-20 at 12.34.30 PM.jpg](https://docs.elest.io/uploads/images/gallery/2025-03/scaled-1680-/screenshot-2025-03-20-at-12-34-30-pm.jpg)

### **Prerequisites**

##### **Install Java &amp; JDBC driver**

Check if Java is installed by running:

```bash
java -version
```

If not installed, install it first and then download and install **JDBC** driver from [https://jdbc.postgresql.org/download/](https://jdbc.postgresql.org/download/) or if you have Maven installed, run the following command with updated version of the driver:

```bash
mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:get -Dartifact=org.postgresql:postgresql:42.7.5:jar -Ddest=postgresql-42.7.5.jar
```

## **Code**

Once all prerequisites are set up, create a new file named `Pg.java` and add the following code:

```java
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;

public class Pg {
    private static class ConnectionConfig {
        private final String host;
        private final String port;
        private final String database;
        private final String username;
        private final String password;

        public ConnectionConfig(String host, String port, String database, String username, String password) {
            this.host = host;
            this.port = port;
            this.database = database;
            this.username = username;
            this.password = password;
        }

        public String getConnectionUrl() {
            return String.format("jdbc:postgresql://%s:%s/%s?sslmode=require", host, port, database);
        }

        public boolean isValid() {
            return host != null && !host.isEmpty() && 
                   port != null && !port.isEmpty() && 
                   database != null && !database.isEmpty();
        }
    }

    private static Map<String, String> parseArguments(String[] args) {
        Map<String, String> config = new HashMap<>();
        for (int i = 0; i < args.length - 1; i++) {
            String key = args[i].toLowerCase();
            String value = args[++i];
            config.put(key, value);
        }
        return config;
    }

    private static ConnectionConfig createConfig(Map<String, String> args) {
        return new ConnectionConfig(
            args.get("-host"),
            args.get("-port"),
            args.get("-database"),
            args.get("-username"),
            args.get("-password")
        );
    }

    private static void validateConnection(Connection connection) throws SQLException {
        try (Statement stmt = connection.createStatement();
             ResultSet rs = stmt.executeQuery("SELECT version()")) {
            if (rs.next()) {
                System.out.println("Database Version: " + rs.getString("version"));
            }
        }
    }

    public static void main(String[] args) {
        try {
            // Load PostgreSQL driver
            Class.forName("org.postgresql.Driver");

            // Parse and validate configuration
            Map<String, String> parsedArgs = parseArguments(args);
            ConnectionConfig config = createConfig(parsedArgs);

            if (!config.isValid()) {
                System.err.println("Error: Missing required connection parameters (host, port, database)");
                return;
            }

            // Establish connection and validate
            try (Connection conn = DriverManager.getConnection(
                    config.getConnectionUrl(),
                    config.username,
                    config.password)) {
                
                System.out.println("Successfully connected to the database!");
                validateConnection(conn);
            }

        } catch (ClassNotFoundException e) {
            System.err.println("Error: PostgreSQL JDBC Driver not found");
            e.printStackTrace();
        } catch (SQLException e) {
            System.err.println("Database connection error:");
            e.printStackTrace();
        }
    }
}
```

To execute the script, open the terminal or command prompt and navigate to the directory where `Pg.java`. Once in the correct directory, run the script with the command (Update the variables with actual values acquired from previous steps.)

```bash
javac Pg.java && java -cp postgresql-42.7.5.jar:. Pg -host HOST -port PORT -database DATABASE -username avnadmin -password PASSWORD
```

If the connection is successful, the terminal will display output similar to:

```bash
Successfully connected to the database!
Database 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
```

# Connecting with psql

This guide explains how to connect to a **PostgreSQL** 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 PostgreSQL database, you only need one environment variable — the **connection URI**. This URI contains all the necessary information like username, password, host, port, and database name.

<div class="overflow-x-auto contain-inline-size" id="bkmrk-variable-description"><table border="1" data-end="1005" data-start="750" style="width: 100%;"><thead data-end="786" data-start="750"><tr data-end="786" data-start="750"><th data-end="761" data-start="750" style="width: 15.4918%;">Variable</th><th data-end="775" data-start="761" style="width: 40.4081%;">Description</th><th data-end="786" data-start="775" style="width: 44.1001%;">Purpose</th></tr></thead><tbody data-end="1005" data-start="824"><tr data-end="1005" data-start="824"><td style="width: 15.4918%;">**POSTGRESQL\_URI**</td><td style="width: 40.4081%;">Full PostgreSQL connection string (from the Elestio service overview page)</td><td style="width: 44.1001%;">Provides all necessary credentials and endpoint details in a single URI format.</td></tr></tbody></table>

</div>The URI will look 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.

![image.png](https://docs.elest.io/uploads/images/gallery/2025-03/scaled-1680-/ZvEimage.png)

### **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 PostgreSQL**

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

```bash
psql POSTGRESQL_URI
```

<div class="contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary" id="bkmrk--1"><div class="sticky top-9"><div class="absolute bottom-0 right-0 flex h-9 items-center pr-2"></div></div></div>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:

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

Elestio=#
```

To ensure you're connected correctly, run this command inside the `psql` prompt:

```bash
SELECT version();
```

You should receive output like the following:

```
                                                       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>

# Connecting with pgAdmin

**pgAdmin** is a widely used graphical interface for PostgreSQL that allows you to manage, connect to, and run queries on your databases with ease.

### **Variables**

To connect using `pgAdmin`, you'll need the following connection parameters. When you deploy a PostgreSQL service on Elestio, you also get a pgAdmin dashboard configured for you to use with these variables. These details are available in the **Elestio service overview page**:

<div class="overflow-x-auto contain-inline-size" id="bkmrk-variable-description"><table border="1" data-end="1422" data-start="642" style="border-collapse: collapse; border-color: rgb(0, 0, 0);"><thead data-end="723" data-start="642"><tr data-end="723" data-start="642"><th data-end="657" data-start="642" style="border-color: rgb(0, 0, 0);">Variable</th><th data-end="712" data-start="657" style="border-color: rgb(0, 0, 0);">Description</th><th data-end="723" data-start="712" style="border-color: rgb(0, 0, 0);">Purpose</th></tr></thead><tbody data-end="1422" data-start="806"><tr data-end="932" data-start="806"><td style="border-color: rgb(0, 0, 0);">**USER**</td><td style="border-color: rgb(0, 0, 0);">pgAdmin username</td><td style="border-color: rgb(0, 0, 0);">Identifies the pgAdmin user with access permission.</td></tr><tr data-end="1041" data-start="933"><td style="border-color: rgb(0, 0, 0);">**PASSWORD**</td><td style="border-color: rgb(0, 0, 0);">pgAdmin password</td><td style="border-color: rgb(0, 0, 0);">Authentication key for the `USER`.</td></tr></tbody></table>

</div>You can find these values in your Elestio project dashboard under **Admin** section.

[![Screenshot 2025-04-01 at 3.49.57 PM.jpg](https://docs.elest.io/uploads/images/gallery/2025-04/scaled-1680-/screenshot-2025-04-01-at-3-49-57-pm.jpg)](https://docs.elest.io/uploads/images/gallery/2025-04/screenshot-2025-04-01-at-3-49-57-pm.jpg)

### **Prerequisites**

Make sure the **PostgreSQL** service is correctly deployed on Elestio and you are able to access the Admin section like the one in the image above.

### **Setting Up the Connection**

1. Launch **pgAdmin** from the Admin UI URL and log in with the credentials acquired in the steps before. ![Screenshot 2025-04-01 at 3.51.28 PM.jpg](https://docs.elest.io/uploads/images/gallery/2025-04/scaled-1680-/screenshot-2025-04-01-at-3-51-28-pm.jpg)
2. Click on **"Create"** and select **"Server…"** from the dropdown, or find **Add New Server** from the quick links![Screenshot 2025-04-01 at 3.55.59 PM.jpg](https://docs.elest.io/uploads/images/gallery/2025-04/scaled-1680-/screenshot-2025-04-01-at-3-55-59-pm.jpg)
3. In the **General** tab:
    
    
    - Enter a name for your connection (e.g., `Trial pgAdmin Connection`).![image.png](https://docs.elest.io/uploads/images/gallery/2025-04/scaled-1680-/image.png)
4. Go to the **Connection** tab and enter the following details:
    
    
    - **Host name/address**: `HOSTNAME`
    - **Port**: `PORT`
    - **Maintenance database**: `DATABASE`
    - **Username**: `USERNAME`
    - **Password**: `PASSWORD`

![image.png](https://docs.elest.io/uploads/images/gallery/2025-04/scaled-1680-/6v6image.png)