From 5c199262c57d2a51b1037f80e942f2dae2d51db5 Mon Sep 17 00:00:00 2001 From: Stefan Majewsky Date: Thu, 4 Jan 2024 13:19:54 +0100 Subject: [PATCH] use explicit database name with psql --- internal/backup/backup.go | 3 +-- internal/core/config.go | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/backup/backup.go b/internal/backup/backup.go index 8bca89c4..27832d40 100644 --- a/internal/backup/backup.go +++ b/internal/backup/backup.go @@ -97,8 +97,7 @@ func Create(cfg *core.Configuration, reason string) (nowTime time.Time, returned // determine postgresql server version cmd := exec.CommandContext(ctx, "psql", //nolint:gosec // input is user supplied and self executed - "-h", cfg.PgHostname, "-U", cfg.PgUsername, //NOTE: PGPASSWORD comes via inherited env variable - "--csv", "--tuples-only", "-c", "SHOW SERVER_VERSION") // output not decoration or padding + cfg.ArgsForPsql("--csv", "--tuples-only", "-c", "SHOW SERVER_VERSION")...) // output not decoration or padding output, err := cmd.Output() if err != nil { return nowTime, fmt.Errorf("could not determine postgresql server version: %w", err) diff --git a/internal/core/config.go b/internal/core/config.go index 7847a96c..510b09fa 100644 --- a/internal/core/config.go +++ b/internal/core/config.go @@ -100,6 +100,7 @@ func NewConfiguration() (*Configuration, error) { func (cfg Configuration) ArgsForPsql(args ...string) []string { common := []string{ "-qA", "-h", cfg.PgHostname, "-U", cfg.PgUsername, //NOTE: PGPASSWORD comes via inherited env variable + "-d", "postgres", //ensure that -d does not default to the app username } return append(common, args...) }