MCPcopy Index your code
hub / github.com/cloudnative-pg/cloudnative-pg / ClonePgData

Function ClonePgData

pkg/management/postgres/join.go:40–74  ·  view source on GitHub ↗

ClonePgData clones an existing server, given its connection string, to a certain data directory

(ctx context.Context, connectionString, targetPgData, walDir string)

Source from the content-addressed store, hash-verified

38// ClonePgData clones an existing server, given its connection string,
39// to a certain data directory
40func ClonePgData(ctx context.Context, connectionString, targetPgData, walDir string) error {
41 log.Info("Waiting for server to be available", "connectionString", connectionString)
42
43 db, err := pool.NewDBConnection(connectionString, pool.ConnectionProfilePostgresqlPhysicalReplication)
44 if err != nil {
45 return err
46 }
47 defer func() {
48 _ = db.Close()
49 }()
50
51 err = waitForStreamingConnectionAvailable(ctx, db)
52 if err != nil {
53 return fmt.Errorf("source server not available: %v", connectionString)
54 }
55
56 options := []string{
57 "-D", targetPgData,
58 "-v",
59 "-w",
60 "-d", connectionString,
61 }
62
63 if walDir != "" {
64 options = append(options, "--waldir", walDir)
65 }
66
67 pgBaseBackupCmd := exec.Command(pgBaseBackupName, options...) // #nosec
68 err = execlog.RunStreaming(pgBaseBackupCmd, pgBaseBackupName)
69 if err != nil {
70 return fmt.Errorf("error in pg_basebackup, %w", err)
71 }
72
73 return nil
74}
75
76// Join creates a new instance joined to an existing PostgreSQL cluster
77func (info InitInfo) Join(ctx context.Context, cluster *apiv1.Cluster) error {

Callers 2

JoinMethod · 0.85

Calls 4

NewDBConnectionFunction · 0.92
InfoMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected