Allow specifying primary slot for remote standby (#2065)

This commit is contained in:
machine424 2022-10-04 16:20:28 +02:00
parent 28cd2f188a
commit 3e4c42e264
10 changed files with 45 additions and 4 deletions

View File

@ -479,6 +479,8 @@ spec:
type: string
standby_port:
type: string
standby_primary_slot_name:
type: string
oneOf:
- required:
- s3_wal_path

View File

@ -1156,6 +1156,7 @@ the `STANDBY_` prefix for Spilo to find the backups and WAL files to stream.
Alternatively, standby clusters can also stream from a remote primary cluster.
You have to specify the host address. Port is optional and defaults to 5432.
Moreover, you can also specify a replication slot of the primary.
Note, that only one of the options (`s3_wal_path`, `gs_wal_path`,
`standby_host`) can be present under the `standby` top-level key.

View File

@ -430,6 +430,9 @@ if the `standby` key is present.
TCP port on which the primary is listening for connections. Patroni will
use `"5432"` if not set.
* **standby_primary_slot_name**
replication slot on the primary.
## Volume properties
Those parameters are grouped under the `volume` top-level key and define the

View File

@ -901,6 +901,15 @@ spec:
standby:
standby_host: "acid-minimal-cluster.default"
standby_port: "5433"
standby_primary_slot_name: "slot"
```
If needed, one can also specify the slot on the primary to use for replication.
```yaml
spec:
standby:
standby_primary_slot_name: "slot"
```
Note, that the pods and services use the same role labels like for normal clusters:

View File

@ -477,6 +477,8 @@ spec:
type: string
standby_port:
type: string
standby_primary_slot_name:
type: string
oneOf:
- required:
- s3_wal_path

View File

@ -14,3 +14,4 @@ spec:
# s3_wal_path: "s3://mybucket/spilo/acid-minimal-cluster/abcd1234-2a4b-4b2a-8c9c-c1234defg567/wal/14/"
standby_host: "acid-minimal-cluster.default"
# standby_port: "5432"
# standby_primary_slot_name: "slot"

View File

@ -746,6 +746,9 @@ var PostgresCRDResourceValidation = apiextv1.CustomResourceValidation{
"standby_port": {
Type: "string",
},
"standby_primary_slot_name": {
Type: "string",
},
},
OneOf: []apiextv1.JSONSchemaProps{
apiextv1.JSONSchemaProps{Required: []string{"s3_wal_path"}},

View File

@ -184,6 +184,7 @@ type StandbyDescription struct {
GSWalPath string `json:"gs_wal_path,omitempty"`
StandbyHost string `json:"standby_host,omitempty"`
StandbyPort string `json:"standby_port,omitempty"`
StandbyPrimarySlotName string `json:"standby_primary_slot_name,omitempty"`
}
// TLSDescription specs TLS properties

View File

@ -2058,6 +2058,12 @@ func (c *Cluster) generateStandbyEnvironment(description *acidv1.StandbyDescript
Value: description.StandbyPort,
})
}
if description.StandbyPrimarySlotName != "" {
result = append(result, v1.EnvVar{
Name: "STANDBY_PRIMARY_SLOT_NAME",
Value: description.StandbyPrimarySlotName,
})
}
} else {
c.logger.Info("standby cluster streaming from WAL location")
if description.S3WalPath != "" {

View File

@ -1292,6 +1292,19 @@ func TestStandbyEnv(t *testing.T) {
envPos: 1,
envLen: 2,
},
{
subTest: "from remote primary with slot",
standbyOpts: &acidv1.StandbyDescription{
StandbyHost: "remote-primary",
StandbyPrimarySlotName: "slot",
},
env: v1.EnvVar{
Name: "STANDBY_PRIMARY_SLOT_NAME",
Value: "slot",
},
envPos: 1,
envLen: 2,
},
{
subTest: "from remote primary - ignore WAL path",
standbyOpts: &acidv1.StandbyDescription{