start starts a postgres database instance. If port is 0, then it will choose a random unused port.
(port int, dataDir string, serverLog bool)
| 20 | // start starts a postgres database instance. |
| 21 | // If port is 0, then it will choose a random unused port. |
| 22 | func 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. |
| 54 | func stop(pgDataDir string) error { |
no test coverage detected