Repository navigation
Description
Is there an existing issue already for this feature request/idea?
- I have searched for an existing issue, and could not find anything. I believe this is a new feature request to be evaluated.
What problem is this feature going to solve? Why should it be added?
Right now, if you try and put an existing cluster previously bootstrapped with initdb in replica mode, you are immediately blocked.
The Cluster "pg1" is invalid:
* spec.replicaCluster: Invalid value: v1.ReplicaClusterConfiguration{Source:"pg2", Enabled:true}: replica mode is compatible only with bootstrap using pg_basebackup or recovery
* spec.replicaCluster: Invalid value: v1.ReplicaClusterConfiguration{Source:"pg2", Enabled:true}: Can not enable replication on existing clusters
This behaviour prevents a cluster from being properly shut down and for example become a follower of another cluster sharing the same transactional continuum.
Describe the solution you'd like
We should enable managing the replica stanza on any cluster, no matter how they were initially bootstrapped.
For example, consider the following pg1.yaml file:
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: pg1
spec:
imageName: ghcr.io/cloudnative-pg/postgresql:16
instances: 1
storage:
size: 1Gi
postgresql:
pg_hba:
- hostssl replication streaming-replica 0.0.0.0/0 cert
externalClusters:
- name: pg2
connectionParameters:
host: pg2-rw.default.svc
user: streaming_replica
sslmode: verify-full
dbname: postgres
sslKey:
name: pg2-replication
key: tls.key
sslCert:
name: pg2-replication
key: tls.crt
sslRootCert:
name: pg2-ca
key: ca.crtRun kubectl apply -f pg1.yaml.
Then, look at the pg2.yaml one:
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: pg2
spec:
imageName: ghcr.io/cloudnative-pg/postgresql:16
instances: 1
storage:
size: 1Gi
bootstrap:
pg_basebackup:
source: pg1
postgresql:
pg_hba:
- hostssl replication streaming-replica 0.0.0.0/0 cert
replica:
enabled: true
source: pg1
externalClusters:
- name: pg1
connectionParameters:
host: pg1-rw.default.svc
user: streaming_replica
dbname: postgres
sslmode: verify-full
sslKey:
name: pg1-replication
key: tls.key
sslCert:
name: pg1-replication
key: tls.crt
sslRootCert:
name: pg1-ca
key: ca.crtRun kubectl apply -f pg2.yaml and ensure that the two clusters are up.
Now run kubect edit cluster pg1 and add:
replica:
enabled: true
source: pg2Instead of blocking the operation, we should:
- detect the change and acknowledge the request to become a replica cluster
- properly fence the instance
- reconfigure replication (using the
pg2external cluster definition) - restart the instance
In case this instance has standbys, the instance should work as a standard designated primary.
Describe alternatives you've considered
N/A
Additional context
This is an intermediate step to enhance switchover operations involving replica clusters.
Backport?
No
Are you willing to actively contribute to this feature?
Yes
Code of Conduct
- I agree to follow this project's Code of Conduct
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
gbartolini commentedon Feb 26, 2024
Let's make sure we check that
recovery_target_actionis set topause(see https://www.postgresql.org/docs/16/runtime-config-wal.html#GUC-RECOVERY-TARGET-ACTION).wip: enable replica on an existing cluster
wip: enable replica on an existing cluster
feat: enable replica mode on an existing cluster (#4261)