Support PostgreSQL with ProxySQL and deployment optimization by ronaldbradford · Pull Request #129 · ProxySQL/dbdeployer · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 69 additions & 7 deletions cmd/replication.go
21 changes: 19 additions & 2 deletions cmd/single.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,9 +491,26 @@ func deploySingleNonMySQL(cmd *cobra.Command, args []string, providerName string
}

sandboxHome := defaults.Defaults().SandboxHome
sandboxDir := path.Join(sandboxHome, fmt.Sprintf("%s_sandbox_%d", providerName, port))
sandboxDirName, _ := flags.GetString(globals.SandboxDirectoryLabel)
force, _ := flags.GetBool(globals.ForceLabel)

var sandboxDir string
if sandboxDirName != "" {
sandboxDir = path.Join(sandboxHome, sandboxDirName)
} else {
sandboxDir = path.Join(sandboxHome, fmt.Sprintf("%s_sandbox_%d", providerName, port))
}

if common.DirExists(sandboxDir) {
common.Exitf(1, "sandbox directory %s already exists", sandboxDir)
if !force {
common.Exitf(1, "sandbox directory %s already exists", sandboxDir)
}
Comment thread
ronaldbradford marked this conversation as resolved.
common.CondPrintf("Overwriting directory %s\n", sandboxDir)
stopScript := path.Join(sandboxDir, "stop")
if common.ExecExists(stopScript) {
_, _ = common.RunCmd(stopScript)
}
common.RmdirAll(sandboxDir)
}

skipStart, _ := flags.GetBool(globals.SkipStartLabel)
Expand Down
10 changes: 5 additions & 5 deletions cmd/unpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ func unpackTarball(cmd *cobra.Command, args []string) {
Version, _ := flags.GetString(globals.UnpackVersionLabel)
providerName, _ := flags.GetString(globals.ProviderLabel)
if providerName == "postgresql" {
if len(args) < 2 {
common.Exitf(1, "PostgreSQL unpack requires both server and client .deb files\n"+
"Usage: dbdeployer unpack --provider=postgresql postgresql-16_*.deb postgresql-client-16_*.deb")
if len(args) < 3 {
common.Exitf(1, "PostgreSQL unpack requires server and client .deb files, plus libpq5\n"+
"Usage: dbdeployer unpack --provider=postgresql postgresql-18_*.deb postgresql-client-18_*.deb libpq5_*.deb")
}
server, client, err := postgresql.ClassifyDebs(args)
server, _, err := postgresql.ClassifyDebs(args)
if err != nil {
common.Exitf(1, "error classifying deb files: %s", err)
}
Expand All @@ -59,7 +59,7 @@ func unpackTarball(cmd *cobra.Command, args []string) {
}
home, _ := os.UserHomeDir()
targetDir := filepath.Join(home, "opt", "postgresql", version)
if err := postgresql.UnpackDebs(server, client, targetDir); err != nil {
if err := postgresql.UnpackDebs(args, targetDir); err != nil {
common.Exitf(1, "error unpacking PostgreSQL debs: %s", err)
}
fmt.Printf("PostgreSQL %s unpacked to %s\n", version, targetDir)
Expand Down
20 changes: 16 additions & 4 deletions common/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"sort"
"strconv"
"strings"
"time"

"github.com/araddon/dateparse"
"github.com/pkg/errors"
Expand All @@ -46,6 +47,17 @@ type VersionInfo struct {

var portDebug bool = IsEnvSet("PORT_DEBUG")

func portDebugf(format string, args ...interface{}) {
if !portDebug {
return
}
if IsEnvSet("DEPLOY_DEBUG") {
CondPrintf("[%s] "+format, append([]interface{}{time.Now().Format("15:04:05")}, args...)...)
return
}
CondPrintf(format, args...)
}

type PortMap map[int]bool

type SandboxInfoList []SandboxInfo
Expand Down Expand Up @@ -721,7 +733,7 @@ func findFreePortSingle(requestedPort int, usedPorts PortMap) (int, error) {
_, exists := usedPorts[candidatePort]
if exists {
if portDebug {
CondPrintf("- port %d not free\n", candidatePort)
portDebugf("- port %d not free\n", candidatePort)
}
} else {
foundPort = candidatePort
Expand Down Expand Up @@ -752,15 +764,15 @@ func findFreePortRange(basePort int, usedPorts PortMap, howMany int) (int, error
_, exists := usedPorts[candidatePort+counter]
if exists {
if portDebug {
CondPrintf("- port %d is not free\n", candidatePort+counter)
portDebugf("- port %d is not free\n", candidatePort+counter)
}
candidatePort += 1
counter = 0
numPorts = 0
continue
} else {
if portDebug {
CondPrintf("+ port %d is free\n", candidatePort+counter)
portDebugf("+ port %d is free\n", candidatePort+counter)
}
numPorts += 1
}
Expand Down Expand Up @@ -789,7 +801,7 @@ func findFreePortRange(basePort int, usedPorts PortMap, howMany int) (int, error
// Returns the first port of the requested range
func FindFreePort(basePort int, installedPorts []int, howMany int) (int, error) {
if portDebug {
CondPrintf("FindFreePort: requested: %d - used: %v - howMany: %d\n", basePort, installedPorts, howMany)
portDebugf("FindFreePort: requested: %d - used: %v - howMany: %d\n", basePort, installedPorts, howMany)
}
usedPorts := make(PortMap)

Expand Down
14 changes: 14 additions & 0 deletions common/strutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"sort"
"strconv"
"strings"
"time"

"github.com/ProxySQL/dbdeployer/globals"
)
Expand All @@ -41,6 +42,19 @@ func CondPrintf(format string, args ...interface{}) {
}
}

// DeployDebugf prints timestamped deploy tracing when DEPLOY_DEBUG is set.
func DeployDebugf(format string, args ...interface{}) {
if !IsEnvSet("DEPLOY_DEBUG") || !globals.UsingDbDeployer {
return
}
fmt.Printf("[%s] %s", time.Now().Format("15:04:05"), fmt.Sprintf(format, args...))
}

// DeployDebugSince prints elapsed seconds since start when DEPLOY_DEBUG is set.
func DeployDebugSince(label string, start time.Time) {
DeployDebugf("%s (%.1fs)\n", label, time.Since(start).Seconds())
}

func CondPrintln(args ...interface{}) {
if globals.UsingDbDeployer {
fmt.Println(args...)
Expand Down
98 changes: 98 additions & 0 deletions providers/postgresql/paths.go
Loading
Loading