1

I have an application that connects to a PostgreSQL database.

package main

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

    _ "github.com/lib/pq"
)

func main() {
    connectionString := "host=<my-host> port=<my-port> user=<my-user> password=<my-password> dbname=<my-dbname> sslmode=disable"

    db, err := sql.Open("postgres", connectionString)
    if err != nil {
        log.Fatal(err)
    }
    defer db.Close()

    err = db.Ping()
    if err != nil {
        log.Fatal(err)
    }

//...
}

I need to connect to Patroni. How do I need to specify the connection string? Do I need to specify all servers in the cluster, or is it possible to specify only one?

Violetta
  • 509
  • 4
  • 12
  • Do you want to connect to master node or to the standby(s) node? Did you tried to run your code at least one of the nodes? If so, what did you get? I assume the architecture is confusing you. It is better to check and understand the architecture. – Umut TEKİN Aug 20 '23 at 23:27

0 Answers0