Skip to content

Commit fc1817c

Browse files
committed
Merge branch '230-dle-configuration' into 'master'
fix: DLE restore configuration (#230) # Description - add recovery_target_timeline (PG < 12) to handle a failover properly in Postgres 11 and older(see the related issue) - skip an error due to absent `postgresql.conf` while init DLE configs. The absence of the `postgresql.conf` file is normal at the first start because it will be initialized a little later - correct the path of the recovery file Closes #230 See merge request postgres-ai/database-lab!247
2 parents 5fb36f0 + 4dda095 commit fc1817c

File tree

5 files changed

+18
-6
lines changed

5 files changed

+18
-6
lines changed

pkg/retrieval/engine/postgres/physical/custom.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func (c *custom) GetRecoveryConfig(pgVersion float64) map[string]string {
4141

4242
if pgVersion < defaults.PGVersion12 {
4343
recoveryCfg["standby_mode"] = "on"
44+
recoveryCfg["recovery_target_timeline"] = "latest"
4445
}
4546
}
4647

pkg/retrieval/engine/postgres/physical/custom_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ func TestCustomRecoveryConfig(t *testing.T) {
1313

1414
recoveryConfig := customTool.GetRecoveryConfig(11.7)
1515
expectedResponse11 := map[string]string{
16-
"restore_command": "pg_basebackup -X stream -D dataDirectory",
17-
"standby_mode": "on",
16+
"restore_command": "pg_basebackup -X stream -D dataDirectory",
17+
"standby_mode": "on",
18+
"recovery_target_timeline": "latest",
1819
}
1920
assert.Equal(t, expectedResponse11, recoveryConfig)
2021

pkg/retrieval/engine/postgres/physical/wal_g.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func (w *walg) GetRecoveryConfig(pgVersion float64) map[string]string {
4444

4545
if pgVersion < defaults.PGVersion12 {
4646
recoveryCfg["standby_mode"] = "on"
47+
recoveryCfg["recovery_target_timeline"] = "latest"
4748
}
4849

4950
return recoveryCfg

pkg/retrieval/engine/postgres/physical/wal_g_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ func TestWALGRecoveryConfig(t *testing.T) {
1111

1212
recoveryConfig := walg.GetRecoveryConfig(11.7)
1313
expectedResponse11 := map[string]string{
14-
"restore_command": "wal-g wal-fetch %f %p",
15-
"standby_mode": "on",
14+
"restore_command": "wal-g wal-fetch %f %p",
15+
"standby_mode": "on",
16+
"recovery_target_timeline": "latest",
1617
}
1718
assert.Equal(t, expectedResponse11, recoveryConfig)
1819

pkg/services/provision/databases/postgres/pgconfig/configuration.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ func (m *Manager) isInitialized() (bool, error) {
146146

147147
postgresFile, err := os.Open(pgConfDst)
148148
if err != nil {
149+
if _, ok := err.(*os.PathError); ok {
150+
return false, nil
151+
}
152+
149153
return false, err
150154
}
151155

@@ -303,6 +307,10 @@ func (m *Manager) AdjustRecoveryFiles() error {
303307

304308
// ApplyRecovery applies recovery configuration parameters.
305309
func (m *Manager) ApplyRecovery(cfg map[string]string) error {
310+
if err := tools.TouchFile(path.Join(m.dataDir, m.recoveryFilename())); err != nil {
311+
return err
312+
}
313+
306314
if err := appendExtraConf(path.Join(m.dataDir, m.recoveryFilename()), cfg); err != nil {
307315
return err
308316
}
@@ -373,11 +381,11 @@ func (m *Manager) getConfigPath(configName string) string {
373381

374382
// recoveryFilename returns the name of a recovery configuration file.
375383
func (m Manager) recoveryFilename() string {
376-
if m.pgVersion > defaults.PGVersion12 {
384+
if m.pgVersion >= defaults.PGVersion12 {
377385
return configPrefix + pgConfName
378386
}
379387

380-
return configPrefix + recoveryConfName
388+
return recoveryConfName
381389
}
382390

383391
// rewriteConfig completely rewrite a configuration file with provided parameters.

0 commit comments

Comments
 (0)