MCPcopy Create free account
hub / github.com/cloudnative-pg/cloudnative-pg / Startup

Method Startup

pkg/management/postgres/instance.go:516–551  ·  view source on GitHub ↗

Startup starts up a PostgreSQL instance and wait for the instance to be started

()

Source from the content-addressed store, hash-verified

514// Startup starts up a PostgreSQL instance and wait for the instance to be
515// started
516func (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
554func (instance *Instance) ShutdownConnections() {

Callers 1

WithActiveInstanceMethod · 0.95

Calls 4

buildPostgresEnvMethod · 0.95
GetSocketDirFunction · 0.85
GetServerPortFunction · 0.85
InfoMethod · 0.80

Tested by

no test coverage detected