Startup starts up a PostgreSQL instance and wait for the instance to be started
()
| 514 | // Startup starts up a PostgreSQL instance and wait for the instance to be |
| 515 | // started |
| 516 | func (instance *Instance) Startup() error { |
| 517 | socketDir := GetSocketDir() |
| 518 | if err := fileutils.EnsureDirectoryExists(socketDir); err != nil { |
| 519 | return fmt.Errorf("while creating socket directory: %w", err) |
| 520 | } |
| 521 | |
| 522 | options := []string{ |
| 523 | "start", |
| 524 | "-w", |
| 525 | "-D", instance.PgData, |
| 526 | "-o", fmt.Sprintf("-c port=%v -c unix_socket_directories=%v", GetServerPort(), socketDir), |
| 527 | "-t " + pgCtlTimeout, |
| 528 | } |
| 529 | |
| 530 | // Add postgres server command line options |
| 531 | for _, opt := range instance.StartupOptions { |
| 532 | options = append(options, "-o", "-c "+opt) |
| 533 | } |
| 534 | |
| 535 | log.Info("Starting up instance", "pgdata", instance.PgData, "options", options) |
| 536 | |
| 537 | // We need to make sure that the permissions are the right ones |
| 538 | // in some systems they may be messed up even if we fix them before |
| 539 | if err := fileutils.EnsurePgDataPerms(instance.PgData); err != nil { |
| 540 | return err |
| 541 | } |
| 542 | |
| 543 | pgCtlCmd := exec.Command(pgCtlName, options...) // #nosec |
| 544 | pgCtlCmd.Env = instance.buildPostgresEnv() |
| 545 | err := execlog.RunStreaming(pgCtlCmd, pgCtlName) |
| 546 | if err != nil { |
| 547 | return fmt.Errorf("error starting PostgreSQL instance: %w", err) |
| 548 | } |
| 549 | |
| 550 | return nil |
| 551 | } |
| 552 | |
| 553 | // ShutdownConnections tears down database connections |
| 554 | func (instance *Instance) ShutdownConnections() { |
no test coverage detected