Set up a replicated store with server init --patroni, and watch it
init --patroni user@host ... installs PostgreSQL, Patroni and etcd on the given machines over ssh, with this one as the third etcd vote, makes the role and database, and moves the store in use into the cluster. Each step checks first, so it changes nothing on a cluster that is up. For a store of several hosts the control plane publishes each member's role, state and lag from Patroni, a stopped member as missing, prints it in ctl status, and alerts on it. Making an administrator on PostgreSQL sent a bool to an integer column; it sends an integer now. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
7a562ac1e7
commit
975c93994f
22 files changed
+1495
-43
No files matched your search
+6
-35
@@ -8,7 +8,6 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
@@ -190,42 +189,14 @@ func pgDump(ctx context.Context, dsn, out string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// pgEnv turns a store address into libpq's environment.
|
||||
//
|
||||
// Several hosts are allowed, as pgx allows them — "h1:5432,h2:5432", the
|
||||
// members of a replicated cluster — and become libpq's own lists in PGHOST and
|
||||
// PGPORT. url.Parse does not read such a host: it took everything before the
|
||||
// last colon as one name, which libpq could not resolve, and a backup worked
|
||||
// only because it fell through to the second host.
|
||||
// pgEnv turns a store address into libpq's environment. Several hosts — the
|
||||
// members of a replicated cluster — become libpq's own lists in PGHOST and
|
||||
// PGPORT; read as one URL host, the list was one name libpq could not
|
||||
// resolve, and a backup worked only by falling through to the second.
|
||||
func pgEnv(dsn string) ([]string, error) {
|
||||
scheme, rest, ok := strings.Cut(dsn, "://")
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("the store address is not a URL")
|
||||
}
|
||||
authority, tail := rest, ""
|
||||
if i := strings.IndexAny(rest, "/?"); i >= 0 {
|
||||
authority, tail = rest[:i], rest[i:]
|
||||
}
|
||||
userinfo, hostlist := "", authority
|
||||
if i := strings.LastIndexByte(authority, '@'); i >= 0 {
|
||||
userinfo, hostlist = authority[:i+1], authority[i+1:]
|
||||
}
|
||||
var hosts, ports []string
|
||||
for _, hp := range strings.Split(hostlist, ",") {
|
||||
u, err := url.Parse("x://" + hp)
|
||||
if err != nil || u.Hostname() == "" {
|
||||
return nil, fmt.Errorf("the store address has a host that is not one: %q", hp)
|
||||
}
|
||||
port := u.Port()
|
||||
if port == "" {
|
||||
port = "5432"
|
||||
}
|
||||
hosts, ports = append(hosts, u.Hostname()), append(ports, port)
|
||||
}
|
||||
// The rest of the address with one placeholder host, which url.Parse reads.
|
||||
u, err := url.Parse(scheme + "://" + userinfo + "host" + tail)
|
||||
hosts, ports, u, err := store.SplitPostgres(dsn)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("the store address is not a URL")
|
||||
return nil, err
|
||||
}
|
||||
var env []string
|
||||
set := func(k, v string) {
|
||||
|
||||
Reference in new issue
Block a user