zalando / postgres-operator

Postgres operator creates and manages PostgreSQL clusters running in Kubernetes
https://postgres-operator.readthedocs.io/
MIT License
4.22k stars 968 forks source link

Editing postgres yml though operator #741

Open Jabbl opened 4 years ago

Jabbl commented 4 years ago

Half my patroni-cluster recently had a power outage which the active master was affected by.

The master-role was successfully transferred to one of the slaves, but when the power came back the previous master refused to act as a slave, since the timelines had diverged by a couple seconds (the few values the master never got to send to it's slaves).

To fix this, I found the parameters remove_data_directory_on_rewind_failure and remove_data_directory_on_diverged_timelines in the patroni documentation, and would like to enable these two.\ However, I have found no way of adding any of these parameters to the postgres.yaml.\ I've tried adding them under both the posgresql and patroni top-level parameters in the cluster manifest, but none of them seems to have worked:

  postgresql:
    version: "11"
  patroni:
    use_pg_rewind: true
    remove_data_directory_on_rewind_failure: true
    remove_data_directory_on_diverged_timelines: true

Is there something I'm missing, or is there really no way of adding more posgres.yml-parameters through the operator?\ If there isn't, is this something that could be added?

FxKu commented 4 years ago

The Patroni struct only allows you to specify the documented fields. Try to use the generic parameters field under postgresql key which is also passed to Patroni:

  postgresql:
    version: "11"
    parameters:
      use_pg_rewind: true
      remove_data_directory_on_rewind_failure: true
      remove_data_directory_on_diverged_timelines: true

By looking at the Patroni docs, I'm not sure if it will work for the two remove_... parameters

Jabbl commented 4 years ago

It seems parameters: is the wrong place to add these. The operator complains about the bools it seems:

level=debug msg="skipping \"UPDATE\" event for the invalid cluster: json: cannot unmarshal bool into Go struct field PostgresqlParam.parameters of type string" cluster-name=patroni/patroni-cluster pkg=controller

Manifest at this point:

  postgresql:
    version: "11"
    parameters:
      use_pg_rewind: true
      remove_data_directory_on_rewind_failure: true
      remove_data_directory_on_diverged_timelines: true
FxKu commented 4 years ago

parameters is of type map[string]string, so please quote the flags -> "true"

Jabbl commented 4 years ago

I now tried quoting them too, but you're probably right in that the remove_ parameters cannot be set via parameters...

use_pg_rewind seems to be defaulted to true, so I'm unsure if that line helps anything.

Is there some other way to set values for the postgres-deployment? \ It would be nice to configure Patroni in such a way that it self-adjusts after loss and restore of the master.