Documentation
PostgreSQL databases

Create and connect to PostgreSQL

Managed PostgreSQL databases with backups, SSL, metrics, and access control, managed through Sliplane.

Create a database

  1. In the Sliplane dashboard, go to Databases.

  2. Click Create Database.

  3. Choose a name, region, compute size, and storage size. See Pricing for what each option costs.

  4. Click Create Database.

Your database is ready to use once it finishes provisioning which takes around 30 seconds. Open it to find its connection details.

Connect to your database

Connect with a PostgreSQL client using sslmode=verify-full to validate the TLS certificate and hostname.

For the psql and Python examples using sslrootcert=system, use libpq 16 or newer with a system CA store.

Configure the environment

The Connection URI contains your connection details:

postgres://jonas:pAsSworD123@xxxxxx.sliplane.app:1234/mydb?sslmode=verify-full&sslrootcert=system
           ^     ^           ^                   ^    ^
     user -|     |           |- host       port -|    |- database
                 |
                 |- password

Copy the Connection URI from the Sliplane dashboard where your database is located and set it as an environment variable DATABASE_URL.

export DATABASE_URL="postgres://USER:PASSWORD@HOST:PORT/DATABASE?sslmode=verify-full&sslrootcert=system"
set "DATABASE_URL=postgres://USER:PASSWORD@HOST:PORT/DATABASE?sslmode=verify-full&sslrootcert=system"
$Env:DATABASE_URL="postgres://USER:PASSWORD@HOST:PORT/DATABASE?sslmode=verify-full&sslrootcert=system"

Quick starts

Choose a client below:

# Connect to your database
psql "$DATABASE_URL"

# Or run a single query
psql "$DATABASE_URL" -c "SELECT version();"

In Windows Command Prompt, use psql "%DATABASE_URL%". In PowerShell, use psql $Env:DATABASE_URL.

For pg, remove only sslrootcert=system from DATABASE_URL and keep sslmode=verify-full. Otherwise it treats system as a certificate filename.

import { Client } from "pg"

const client = new Client({ connectionString: process.env.DATABASE_URL })
await client.connect()

const { rows } = await client.query("SELECT ssl FROM pg_stat_ssl WHERE pid = pg_backend_pid()")
console.log(rows[0]) // { ssl: true, ... }

await client.end()

This example requires postgres 3.4.9 or newer.

import postgres from "postgres"

const client = postgres(process.env.DATABASE_URL)

const [ ssl ] = await client`SELECT ssl FROM pg_stat_ssl WHERE pid = pg_backend_pid()`
console.log(ssl) // { ssl: true, ... }

await client.end()

This example requires postgres 3.4.9 or newer.

import { drizzle } from "drizzle-orm/postgres-js"
import { sql } from "drizzle-orm"
import postgres from "postgres"

const client = postgres(process.env.DATABASE_URL)
const db = drizzle(client)

const result = await db.execute(sql`SELECT ssl FROM pg_stat_ssl WHERE pid = pg_backend_pid()`)
console.log(result[0]) // { ssl: true, ... }

await client.end()
import os
import psycopg

with psycopg.connect(os.environ["DATABASE_URL"]) as conn:
    with conn.cursor() as cur:
        cur.execute("SELECT version()")
        print(cur.fetchone())
package main

import (
    "context"
    "fmt"
    "log"
    "os"

    "github.com/jackc/pgx/v5"
)

func main() {
    ctx := context.Background()

    conn, err := pgx.Connect(ctx, os.Getenv("DATABASE_URL"))
    if err != nil {
        log.Fatalf("Connect to PostgreSQL: %v", err)
    }
    defer conn.Close(ctx)

    var version string
    if err := conn.QueryRow(ctx, "SELECT version()").Scan(&version); err != nil {
        log.Fatalf("Read PostgreSQL version: %v", err)
    }
    fmt.Println(version)
}

JDBC URL is different from the common PostgreSQL URI format. To connect, you need to construct the connection string with the host, port, database, user, and password separately, and set sslmode to verify-full together with sslfactory set to org.postgresql.ssl.DefaultJavaSSLFactory so the driver validates our certificate against the JVM's trusted CAs.

export PGHOST="YOUR_DATABASE_HOST"
export PGPORT="YOUR_DATABASE_PORT"
export PGDATABASE="DATABASE_NAME"
export PGUSER="USERNAME"
export PGPASSWORD="PASSWORD"
set "PGHOST=YOUR_DATABASE_HOST"
set "PGPORT=YOUR_DATABASE_PORT"
set "PGDATABASE=DATABASE_NAME"
set "PGUSER=USERNAME"
set "PGPASSWORD=PASSWORD"
$Env:PGHOST="YOUR_DATABASE_HOST"
$Env:PGPORT="YOUR_DATABASE_PORT"
$Env:PGDATABASE="DATABASE_NAME"
$Env:PGUSER="USERNAME"
$Env:PGPASSWORD="PASSWORD"
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;

public class HelloPostgres {
    public static void main(String[] args) throws Exception {
        String url = String.format(
            "jdbc:postgresql://%s:%s/%s",
            System.getenv("PGHOST"),
            System.getenv("PGPORT"),
            System.getenv("PGDATABASE"));

        Properties props = new Properties();
        props.setProperty("user", System.getenv("PGUSER"));
        props.setProperty("password", System.getenv("PGPASSWORD"));
        props.setProperty("sslmode", "verify-full");
        props.setProperty("sslfactory", "org.postgresql.ssl.DefaultJavaSSLFactory");

        try (Connection conn = DriverManager.getConnection(url, props);
            Statement stmt = conn.createStatement();
            ResultSet rs = stmt.executeQuery("SELECT ssl FROM pg_stat_ssl WHERE pid = pg_backend_pid();")) {
            if (rs.next()) {
                System.out.println(rs.getString("ssl")); // "t"
            }
        }
    }
}

Detailed guides

The following table lists the official documentation for popular PostgreSQL drivers and ORMs.

Language or frameworkLibrary
JavaScript / TypeScriptnode-postgres (pg)
JavaScript / TypeScriptpostgres.js
JavaScript / TypeScriptDrizzle ORM
JavaScript / TypeScriptPrisma ORM
Pythonpsycopg
Gopgx
JavaPostgreSQL JDBC Driver
.NETNpgsql
Rubypg gem
PHPPDO_PGSQL
Rustsqlx / tokio-postgres
LaravelEloquent PostgreSQL driver
Djangodjango.db.backends.postgresql

Connect with a GUI

Prefer a graphical client? Follow one of these quickstarts to connect with your database's connection details.

How is this guide?

On this page