MCPcopy
hub / github.com/sqlc-dev/sqlc / startPostgresService

Function startPostgresService

internal/sqltest/native/postgres.go:83–115  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

81}
82
83func startPostgresService() error {
84 // Try systemctl first
85 cmd := exec.Command("sudo", "systemctl", "start", "postgresql")
86 if err := cmd.Run(); err == nil {
87 return nil
88 }
89
90 // Try service command
91 cmd = exec.Command("sudo", "service", "postgresql", "start")
92 if err := cmd.Run(); err == nil {
93 return nil
94 }
95
96 // Try pg_ctlcluster (Debian/Ubuntu specific)
97 // Find the installed PostgreSQL version
98 output, err := exec.Command("ls", "/etc/postgresql/").CombinedOutput()
99 if err != nil {
100 return fmt.Errorf("could not find PostgreSQL version: %w", err)
101 }
102
103 versions := strings.Fields(string(output))
104 if len(versions) == 0 {
105 return fmt.Errorf("no PostgreSQL version found in /etc/postgresql/")
106 }
107
108 version := versions[0]
109 cmd = exec.Command("sudo", "pg_ctlcluster", version, "main", "start")
110 if output, err := cmd.CombinedOutput(); err != nil {
111 return fmt.Errorf("pg_ctlcluster start failed: %w\n%s", err, output)
112 }
113
114 return nil
115}
116
117func configurePostgres() error {
118 // Set password for postgres user using sudo -u postgres

Callers 1

startPostgreSQLServerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected