MCPcopy Create free account
hub / github.com/CrunchyData/postgres-operator / ReplicaCreateCommand

Function ReplicaCreateCommand

internal/pgbackrest/reconcile.go:452–491  ·  view source on GitHub ↗

ReplicaCreateCommand returns the command that can initialize the PostgreSQL data directory on an instance from one of cluster's repositories. It returns nil when no repository is available.

(
	cluster *v1beta1.PostgresCluster, instance *v1beta1.PostgresInstanceSetSpec,
)

Source from the content-addressed store, hash-verified

450// data directory on an instance from one of cluster's repositories. It returns
451// nil when no repository is available.
452func ReplicaCreateCommand(
453 cluster *v1beta1.PostgresCluster, instance *v1beta1.PostgresInstanceSetSpec,
454) []string {
455 command := func(repoName string) []string {
456 return []string{
457 "pgbackrest", "restore", "--delta",
458 "--stanza=" + DefaultStanzaName,
459 "--repo=" + strings.TrimPrefix(repoName, "repo"),
460 "--link-map=pg_wal=" + postgres.WALDirectory(cluster, instance),
461
462 // Do not create a recovery signal file on PostgreSQL v12 or later;
463 // Patroni creates a standby signal file which takes precedence.
464 // Patroni manages recovery.conf prior to PostgreSQL v12.
465 // - https://github.com/pgbackrest/pgbackrest/blob/release/2.38/src/command/restore/restore.c#L1824
466 // - https://www.postgresql.org/docs/12/runtime-config-wal.html
467 "--type=standby",
468 }
469 }
470
471 if cluster.Spec.Standby != nil && cluster.Spec.Standby.Enabled && cluster.Spec.Standby.RepoName != "" {
472 // Patroni initializes standby clusters using the same command it uses
473 // for any replica. Assume the repository in the spec has a stanza
474 // and can be used to restore. The repository name is validated by the
475 // Kubernetes API and begins with "repo".
476 //
477 // NOTE(cbandy): A standby cluster cannot use "online" stanza-create
478 // nor create backups because every instance is always in recovery.
479 return command(cluster.Spec.Standby.RepoName)
480 }
481
482 if cluster.Status.PGBackRest != nil {
483 for _, repo := range cluster.Status.PGBackRest.Repos {
484 if repo.ReplicaCreateBackupComplete {
485 return command(repo.Name)
486 }
487 }
488 }
489
490 return nil
491}
492
493// RepoVolumeMount returns the name and mount path of the pgBackRest repo volume.
494func RepoVolumeMount() corev1.VolumeMount {

Callers 2

InstanceConfigMapFunction · 0.92
TestReplicaCreateCommandFunction · 0.85

Calls 1

WALDirectoryFunction · 0.92

Tested by 1

TestReplicaCreateCommandFunction · 0.68