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

Method IsPrimary

pkg/management/postgres/instance.go:985–1003  ·  view source on GitHub ↗

IsPrimary check if the data directory belongs to a primary server or to a secondary one by looking for a "standby.signal" file inside the data directory. IMPORTANT: this method also works when the instance is not started up

()

Source from the content-addressed store, hash-verified

983// directory. IMPORTANT: this method also works when the instance is not
984// started up
985func (instance *Instance) IsPrimary() (bool, error) {
986 result, err := fileutils.FileExists(filepath.Join(instance.PgData, "standby.signal"))
987 if err != nil {
988 return false, err
989 }
990 if result {
991 return false, nil
992 }
993
994 result, err = fileutils.FileExists(filepath.Join(instance.PgData, "recovery.conf"))
995 if err != nil {
996 return false, err
997 }
998 if result {
999 return false, nil
1000 }
1001
1002 return true, nil
1003}
1004
1005// Demote demotes an existing PostgreSQL instance
1006func (instance *Instance) Demote(ctx context.Context, cluster *apiv1.Cluster) error {

Callers 4

GetStatusMethod · 0.95
PromoteAndWaitMethod · 0.95

Calls 1

JoinMethod · 0.80

Tested by

no test coverage detected