Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postgres 13 support #810

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .agola/config.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ local task_build_push_images(name, pgversions, istag, push) =
task_integration_tests(store, pgversion, 'amd64'),
]
for store in ['etcdv3']
for pgversion in ['9.5', '9.6', '10', '11', '12']
for pgversion in ['9.5', '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.4 9.5 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.4 9.5 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.4 9.5 9.6 10 11 12 13', true, true)
+ {
when: {
tag: '#v.*#',
Expand Down
57 changes: 45 additions & 12 deletions cmd/keeper/cmd/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ var CmdKeeper = &cobra.Command{
}

const (
maxPostgresTimelinesHistory = 2
minWalKeepSegments = 8
maxPostgresTimelinesHistory = 2
minWalKeepSegments = 8
minWalKeepSize string = "128MB"
)

type KeeperLocalState struct {
Expand Down Expand Up @@ -154,6 +155,7 @@ func init() {
var managedPGParameters = []string{
"unix_socket_directories",
"wal_keep_segments",
"wal_keep_size",
"hot_standby",
"listen_addresses",
"port",
Expand Down Expand Up @@ -232,27 +234,58 @@ func (p *PostgresKeeper) walLevel(db *cluster.DB) string {
return walLevel
}

func (p *PostgresKeeper) walKeepSegments(db *cluster.DB) int {
walKeepSegments := minWalKeepSegments
if db.Spec.PGParameters != nil {
if v, ok := db.Spec.PGParameters["wal_keep_segments"]; ok {
// ignore wrong wal_keep_segments values
if configuredWalKeepSegments, err := strconv.Atoi(v); err == nil {
if configuredWalKeepSegments > walKeepSegments {
walKeepSegments = configuredWalKeepSegments
func (p *PostgresKeeper) walKeepSettingName() string {
maj, _, err := p.pgm.BinaryVersion()
if err != nil {
// in case we fail to parse the binary version then log it and just use "wal_keep_segments" that works for old versions
log.Warnf("failed to get postgres binary version: %v", err)
return "wal_keep_segments"
}
if maj >= 13 {
return "wal_keep_size"
} else {
return "wal_keep_segments"
}
}

func (p *PostgresKeeper) walKeepSetting(db *cluster.DB, setting string) string {
var value string
if setting == "wal_keep_segments" {
walKeepSegments := minWalKeepSegments
if db.Spec.PGParameters != nil {
if v, ok := db.Spec.PGParameters["wal_keep_segments"]; ok {
// ignore wrong wal_keep_segments values
if configuredWalKeepSegments, err := strconv.Atoi(v); err == nil {
if configuredWalKeepSegments > walKeepSegments {
walKeepSegments = configuredWalKeepSegments
}
}
}
}
value = fmt.Sprintf("%d", walKeepSegments)
} else {
walKeepSize := minWalKeepSize
if db.Spec.PGParameters != nil {
if v, ok := db.Spec.PGParameters["wal_keep_size"]; ok {
/* well, we can't check if wal_keep_size value is incorrect
without implementing conversion from PostgreSQL size string
to bytes, so just trust user-provided value for now */
walKeepSize = v
}
}
value = walKeepSize
}

return walKeepSegments
return value
}

func (p *PostgresKeeper) mandatoryPGParameters(db *cluster.DB) common.Parameters {
wks := p.walKeepSettingName()

return common.Parameters{
"unix_socket_directories": common.PgUnixSocketDirectories,
"wal_level": p.walLevel(db),
"wal_keep_segments": fmt.Sprintf("%d", p.walKeepSegments(db)),
wks: p.walKeepSetting(db, wks),
"hot_standby": "on",
}
}
Expand Down