sorintlab / stolon

PostgreSQL cloud native High Availability and more.
https://talk.stolon.io
Apache License 2.0
4.62k stars 443 forks source link

To create a stolonctl demote sub-command #882

Open viggy28 opened 2 years ago

viggy28 commented 2 years ago

What would you like to be added:

stolon can promote a standby cluster to a primary cluster. However, it can't demote a primary cluster to become a standby cluster.

Why is this needed:

Currently, only way is to rebuild the cluster (correct me if I am wrong). It's not efficient. Imagine rebuilding a cluster of 10TB size. It can take multiple hours.

Rough idea on how to implement:

On the failed cluster,

  1. stop the keepers, sentinels, proxies
  2. update cluster.Spec.Role to standby and primary db's db.Spec.Role to standby
  3. create a recovery.conf file only on the primary. Not sure whether we need to populate the content in it. If needed we can do that using standbyConfig.standbySettings.primaryConninfo
  4. remove postgresql.auto.conf file on the primary
  5. run pg_rewind on the all Postgres severs (primary and replica too - in case they are ahead)

Let me know your thoughts @sgotti