Support restore a replica from latest backup
Problem to solve
Restoring a replica using pg_basebackup put heavy load on the primary and is slow. Instead, if a replica was able to get the latest backup and use it to restore the data will avoid to impose such load on the primary and may be faster.
Proposal
The feature will be enabled by default as long as the backups are configured in the SGCluster. We will add a new section SGCluster.spec.replication.initialization
that will containes the following values:
-
mode
:-
BackupFromPrimary
: When this mode is used replicas will be always created from the primary usingpg_basebackup
. -
BackupFromReplica
: When this mode is used replicas will be created from another existing replica usingpg_basebackup
. Fallsback toBackupFromPrimary
if there's no replica or it fails. -
FromExistingBackup
: When this mode is used replicas will be created from an existing SGBackup. IfbackupNewerThan
is set the SGBackup must be newer than its value. When this mode fails to restore an SGBackup it will try with a previous one (if exists). Fallsback toBackupFromReplica
if there's no backup left or it fails. -
FromNewlyCreatedBackup
: When this mode is used replicas will be created from a newly created SGBackup. Fallsback toFromExistingBackup
ifbackupNewerThan
is set and exists a recent backup newer than its value or it fails.
-
-
backupNewerThan
: An ISO 8601 duration in the formatPnDTnHnMn.nS
, that specifies how old an SGBackup have to be in order to be seleceted to initialize a replica. WhenFromExistingBackup
mode is set this field restrict the selection of SGBackup to be used for recovery newer than the specified value. WhenFromNewlyCreatedBackup
mode is set this field skip the creation SGBackup to be used for recovery if one newer than the specified value exists. -
backupRestorePerformance
: Section to configure backup restore configuration similar to the one inSGCluster.spec.initialData.restore.fromBackup.performance
Testing
-
Test the 4 modes in an E2E test
Acceptance Criteria
- [] Implement the feature
- [] Test the feature
- [] Document the feature
Edited by Matteo Melli