MCPcopy Index your code
hub / github.com/bytebase/bytebase / start

Function start

backend/resources/postgres/postgres.go:22–51  ·  view source on GitHub ↗

start starts a postgres database instance. If port is 0, then it will choose a random unused port.

(port int, dataDir string, serverLog bool)

Source from the content-addressed store, hash-verified

20// start starts a postgres database instance.
21// If port is 0, then it will choose a random unused port.
22func start(port int, dataDir string, serverLog bool) (err error) {
23 // See -p -k -h option definitions in the link below.
24 // https://www.postgresql.org/docs/current/app-postgres.html
25 // We also set max_connections to 500 for tests.
26 p := exec.Command("pg_ctl", "start", "-w",
27 "-D", dataDir,
28 "-o", fmt.Sprintf(`-p %d -k %s -N 500 -h "" -c log_checkpoints=off`, port, common.GetPostgresSocketDir()))
29
30 uid, _, sameUser, err := shouldSwitchUser()
31 if err != nil {
32 return err
33 }
34 if !sameUser {
35 p.SysProcAttr = &syscall.SysProcAttr{
36 Setpgid: true,
37 Credential: &syscall.Credential{Uid: uid},
38 }
39 }
40
41 // It's useful to log the SQL statement errors from Postgres in developer environment.
42 if serverLog {
43 p.Stdout = os.Stdout
44 }
45 p.Stderr = os.Stderr
46 if err := p.Run(); err != nil {
47 return errors.Wrapf(err, "failed to start postgres %q", p.String())
48 }
49
50 return nil
51}
52
53// stop stops a postgres instance, outputs to stdout and stderr.
54func stop(pgDataDir string) error {

Callers 2

StartMetadataInstanceFunction · 0.70
StartAllSampleInstancesFunction · 0.70

Calls 4

GetPostgresSocketDirFunction · 0.92
shouldSwitchUserFunction · 0.85
StringMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected