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

Method Run

pkg/management/postgres/instance.go:741–785  ·  view source on GitHub ↗

Run this instance returning an OS process needed to control the instance execution

()

Source from the content-addressed store, hash-verified

739// Run this instance returning an OS process needed
740// to control the instance execution
741func (instance *Instance) Run() (*execlog.StreamingCmd, error) {
742 process, err := instance.CheckForExistingPostmaster(GetPostgresExecutableName())
743 if err != nil {
744 return nil, err
745 }
746
747 // We have already a postmaster running, let's use this
748 //
749 // NOTE: following this path the instance manager has no way
750 // to reattach the process stdout/stderr. This should not do
751 // any harm because PostgreSQL stops writing on stdout/stderr
752 // when the logging collector starts.
753 if process != nil {
754 return execlog.StreamingCmdFromProcess(process), nil
755 }
756
757 // We don't have a postmaster running and we need to create
758 // one.
759
760 socketDir := GetSocketDir()
761 if err := fileutils.EnsureDirectoryExists(socketDir); err != nil {
762 return nil, fmt.Errorf("while creating socket directory: %w", err)
763 }
764
765 options := []string{
766 "-D", instance.PgData,
767 }
768
769 // We need to make sure that the permissions are the right ones
770 // in some systems they may be messed up even if we fix them before
771 if err := fileutils.EnsurePgDataPerms(instance.PgData); err != nil {
772 return nil, err
773 }
774
775 postgresCmd := exec.Command(GetPostgresExecutableName(), options...) // #nosec
776 postgresCmd.Env = instance.buildPostgresEnv()
777 compatibility.AddInstanceRunCommands(postgresCmd)
778
779 streamingCmd, err := execlog.RunStreamingNoWait(postgresCmd, GetPostgresExecutableName())
780 if err != nil {
781 return nil, err
782 }
783
784 return streamingCmd, nil
785}
786
787// buildPostgresEnv builds the environment variables that should be used by PostgreSQL
788// to run the main process, taking care of adding any path that is needed for extensions.

Callers 2

PgIsReadyFunction · 0.45

Calls 4

buildPostgresEnvMethod · 0.95
GetSocketDirFunction · 0.85

Tested by

no test coverage detected