From 5dc6358f69eb73e03f7ab55c07295bd65be7c800 Mon Sep 17 00:00:00 2001 From: Simone Gotti Date: Tue, 16 Mar 2021 11:40:46 +0100 Subject: [PATCH] *: add support for PostgreSQL 13 * Handle wal_keep_segments removed and replaced by wal_keep_size * CI: Remove build/tests/images for upstream unsupported versions (9.4 and 9.5) --- .agola/config.jsonnet | 10 +++++----- cmd/keeper/cmd/keeper.go | 34 ++++++++++++++++++++++++++++++-- tests/integration/config_test.go | 8 ++++++++ 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/.agola/config.jsonnet b/.agola/config.jsonnet index 8b5d413fa..5ea6cf037 100644 --- a/.agola/config.jsonnet +++ b/.agola/config.jsonnet @@ -172,15 +172,15 @@ local task_build_push_images(name, pgversions, istag, push) = task_integration_tests(store, pgversion, 'amd64'), ] for store in ['etcdv2', 'consul'] - for pgversion in ['12'] + for pgversion in ['13'] ]) + std.flattenArrays([ [ task_integration_tests(store, pgversion, 'amd64'), ] for store in ['etcdv3'] - for pgversion in ['9.5', '9.6', '10', '11', '12'] + for pgversion in [ '9.6', '10', '11', '12', '13'] ]) + [ - task_build_push_images('test build docker "stolon" images', '9.4 9.5 9.6 10 11 12', false, false) + task_build_push_images('test build docker "stolon" images', '9.6 10 11 12 13', false, false) + { when: { branch: { @@ -190,13 +190,13 @@ local task_build_push_images(name, pgversions, istag, push) = ref: '#refs/pull/\\d+/head#', }, }, - task_build_push_images('build and push docker "stolon" master branch images', '9.4 9.5 9.6 10 11 12', false, true) + task_build_push_images('build and push docker "stolon" master branch images', '9.6 10 11 12 13', false, true) + { when: { branch: 'master', }, }, - task_build_push_images('build and push docker "stolon" tag images', '9.4 9.5 9.6 10 11 12', true, true) + task_build_push_images('build and push docker "stolon" tag images', '9.6 10 11 12 13', true, true) + { when: { tag: '#v.*#', diff --git a/cmd/keeper/cmd/keeper.go b/cmd/keeper/cmd/keeper.go index f676c50da..dd9b2aafa 100644 --- a/cmd/keeper/cmd/keeper.go +++ b/cmd/keeper/cmd/keeper.go @@ -156,6 +156,7 @@ func init() { var managedPGParameters = []string{ "unix_socket_directories", "wal_keep_segments", + "wal_keep_size", "hot_standby", "listen_addresses", "port", @@ -250,13 +251,42 @@ func (p *PostgresKeeper) walKeepSegments(db *cluster.DB) int { return walKeepSegments } +func (p *PostgresKeeper) walKeepSize(db *cluster.DB) string { + // assume default 16Mib wal segment size + walKeepSize := strconv.Itoa(minWalKeepSegments * 16) + + // TODO(sgotti) currently we ignore if wal_keep_size value is less than our + // min value or wrong and just return it as is + if db.Spec.PGParameters != nil { + if v, ok := db.Spec.PGParameters["wal_keep_size"]; ok { + return v + } + } + + return walKeepSize +} + func (p *PostgresKeeper) mandatoryPGParameters(db *cluster.DB) common.Parameters { - return common.Parameters{ + params := common.Parameters{ "unix_socket_directories": common.PgUnixSocketDirectories, "wal_level": p.walLevel(db), - "wal_keep_segments": fmt.Sprintf("%d", p.walKeepSegments(db)), "hot_standby": "on", } + + maj, _, err := p.pgm.BinaryVersion() + if err != nil { + // in case we fail to parse the binary version don't return any wal_keep_segments or wal_keep_size + log.Warnf("failed to get postgres binary version: %v", err) + return params + } + + if maj >= 13 { + params["wal_keep_size"] = p.walKeepSize(db) + } else { + params["wal_keep_segments"] = fmt.Sprintf("%d", p.walKeepSegments(db)) + } + + return params } func (p *PostgresKeeper) getSUConnParams(db, followedDB *cluster.DB) pg.ConnParams { diff --git a/tests/integration/config_test.go b/tests/integration/config_test.go index ddfe6d515..a6631c838 100644 --- a/tests/integration/config_test.go +++ b/tests/integration/config_test.go @@ -302,6 +302,14 @@ func TestWalKeepSegments(t *testing.T) { t.Fatalf("unexpected err: %v", err) } + maj, _, err := tk.PGDataVersion() + if err != nil { + t.Fatalf("unexpected err: %v", err) + } + if maj >= 13 { + t.Skipf("skipping since postgres version %d >= 13", maj) + } + // "archive" isn't an accepted wal_level err = StolonCtl(t, clusterName, tstore.storeBackend, storeEndpoints, "update", "--patch", `{ "pgParameters" : { "wal_level": "archive" } }`) if err != nil {