updateResultForDecrease updates the given postgres.PostgresqlStatus in case of pending restart, by checking whether the restart is due to hot standby sensible parameters being decreased
( instance *Instance, superUserDB *sql.DB, result *postgres.PostgresqlStatus, )
| 131 | // in case of pending restart, by checking whether the restart is due to hot standby |
| 132 | // sensible parameters being decreased |
| 133 | func updateResultForDecrease( |
| 134 | instance *Instance, |
| 135 | superUserDB *sql.DB, |
| 136 | result *postgres.PostgresqlStatus, |
| 137 | ) error { |
| 138 | // get all the hot standby sensible parameters being decreased |
| 139 | decreasedValues, err := instance.GetDecreasedSensibleSettings(superUserDB) |
| 140 | if err != nil { |
| 141 | return err |
| 142 | } |
| 143 | |
| 144 | if len(decreasedValues) == 0 { |
| 145 | return nil |
| 146 | } |
| 147 | |
| 148 | // if there is at least one hot standby sensible parameter decreased |
| 149 | // mark the pending restart as due to a decrease |
| 150 | result.PendingRestartForDecrease = true |
| 151 | if !result.IsPrimary { |
| 152 | // In a replica cluster, pg_controldata values are received from the external |
| 153 | // source primary through the WAL stream, not from this cluster's designated |
| 154 | // primary. Comparing decreased parameter values against pg_controldata is |
| 155 | // incorrect for replica clusters because those values reflect the source |
| 156 | // primary's configuration, not the local cluster's. We skip this check and |
| 157 | // keep PendingRestart as-is, allowing the restart to proceed. |
| 158 | cluster := instance.GetClusterOrDefault() |
| 159 | if cluster.IsReplica() { |
| 160 | return nil |
| 161 | } |
| 162 | |
| 163 | // In non-replica clusters, followers need to wait for the new value to be |
| 164 | // present in the PGDATA before being restarted. |
| 165 | pgControldataParams, err := LoadEnforcedParametersFromPgControldata(instance.PgData) |
| 166 | if err != nil { |
| 167 | return err |
| 168 | } |
| 169 | // So, we set PendingRestart according to whether all decreased |
| 170 | // hot standby sensible parameters have been updated in the PGDATA |
| 171 | result.PendingRestart = areAllParamsUpdated(decreasedValues, pgControldataParams) |
| 172 | } |
| 173 | return nil |
| 174 | } |
| 175 | |
| 176 | func areAllParamsUpdated(decreasedValues map[string]int, pgControldataParams map[string]int) bool { |
| 177 | var readyParams int |
no test coverage detected