Recreate cluster from last PV
Problem to solve
Whenever a cluster gets recreated (e.g. CI/CD gets trigger happy), the cluster starts on fresh persistent volumes. This can be a big pain because it means that you have to restore from backup and can end up losing data.
But there's old PVs right there, just asking to get bound!
Further details
I'm aware of these docs, but I found it a bit difficult to do right and was only able to get it to work 1 out of 3 times (and the time it worked, my cluster wasn't named correctly because I was trying to pg_dump | psql at the time). The two other times I had issues with the credentials or wal timeline divergence and none of the 3 times I was able to do a full restore.
Proposal
cleanUpPVCs: false
Option 1: Add an option to retain PVCs after cluster deletion e.g. This feels the most natural, just don't delete the PVCs and the pods can come back to where they left it (like if a pod was only deleted) - and seems quite easy to implement?
The only thing to make sure is that the credentials are resynced from the new secret.
initialData.restore.fromPersistentVolume
Option 2: In the case where the cluster is already gone, this could be a nice-to-have - especially on the dashboard. You could just filter for PVs with a certain stackgres-assigned label (to avoid the case of mounting some unrelated pod).
Testing
I think the additional testing cases would be restoring from a PV from a previous replica and restoring from sudden failure cases.
Perhaps there's some overlap here with Volume Snapshots but I'm not sure?