Skip to content

Commit

Permalink
Merge pull request #831 from sgotti/postgres13
Browse files Browse the repository at this point in the history
*: add support for PostgreSQL 13
  • Loading branch information
sgotti committed Mar 19, 2021
2 parents eb0e155 + 5dc6358 commit 057389f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
10 changes: 5 additions & 5 deletions .agola/config.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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.*#',
Expand Down
34 changes: 32 additions & 2 deletions cmd/keeper/cmd/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ func init() {
var managedPGParameters = []string{
"unix_socket_directories",
"wal_keep_segments",
"wal_keep_size",
"hot_standby",
"listen_addresses",
"port",
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions tests/integration/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 057389f

Please sign in to comment.