Skip to content

Commit cf7e7d3

Browse files
fcanovaileonardocearmru
committed
feat: drop support for pg12 (cloudnative-pg#7396)
Drop conditional logic specific to PostgreSQL 12 and previous versions which have reached end-of-life and are already out of support. Closes cloudnative-pg#7395 Signed-off-by: Francesco Canovai <francesco.canovai@enterprisedb.com> Signed-off-by: Leonardo Cecchi <leonardo.cecchi@enterprisedb.com> Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com> Co-authored-by: Leonardo Cecchi <leonardo.cecchi@enterprisedb.com> Co-authored-by: Armando Ruocco <armando.ruocco@enterprisedb.com> (cherry picked from commit 467849c)
1 parent ce9163d commit cf7e7d3

File tree

13 files changed

+82
-166
lines changed

13 files changed

+82
-166
lines changed

docs/src/database_import.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ As a result, the instructions in this section are suitable for both:
1818
- importing one or more databases from an existing PostgreSQL instance, even
1919
outside Kubernetes
2020
- importing the database from any PostgreSQL version to one that is either the
21-
same or newer, enabling *major upgrades* of PostgreSQL (e.g. from version 11.x
22-
to version 15.x)
21+
same or newer, enabling *major upgrades* of PostgreSQL (e.g. from version 13.x
22+
to version 17.x)
2323

2424
!!! Warning
2525
When performing major upgrades of PostgreSQL you are responsible for making
@@ -316,4 +316,3 @@ upgrades.
316316

317317
For more details, including limitations and best practices, refer to the
318318
[Logical Replication](logical_replication.md) section in the documentation.
319-

docs/src/postgresql_conf.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ operator by applying the following sections in this order:
6565
The **global default parameters** are:
6666

6767
```text
68-
archive_mode = 'on'
68+
archive_timeout = '5min'
6969
dynamic_shared_memory_type = 'posix'
7070
full_page_writes = 'on'
7171
logging_collector = 'on'
@@ -78,9 +78,11 @@ log_truncate_on_rotation = 'false'
7878
max_parallel_workers = '32'
7979
max_replication_slots = '32'
8080
max_worker_processes = '32'
81-
shared_memory_type = 'mmap' # for PostgreSQL >= 12 only
82-
wal_keep_size = '512MB' # for PostgreSQL >= 13 only
83-
wal_keep_segments = '32' # for PostgreSQL <= 12 only
81+
shared_memory_type = 'mmap'
82+
shared_preload_libraries = ''
83+
ssl_max_protocol_version = 'TLSv1.3'
84+
ssl_min_protocol_version = 'TLSv1.3'
85+
wal_keep_size = '512MB'
8486
wal_level = 'logical'
8587
wal_log_hints = 'on'
8688
wal_sender_timeout = '5s'

internal/cmd/manager/instance/pgbasebackup/cmd.go

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@ func NewCmd() *cobra.Command {
105105

106106
// bootstrapUsingPgbasebackup creates a new data dir from the configuration
107107
func (env *CloneInfo) bootstrapUsingPgbasebackup(ctx context.Context) error {
108-
contextLogger := log.FromContext(ctx)
109-
110108
var cluster apiv1.Cluster
111109
err := env.client.Get(ctx, ctrl.ObjectKey{Namespace: env.info.Namespace, Name: env.info.ClusterName}, &cluster)
112110
if err != nil {
@@ -134,22 +132,13 @@ func (env *CloneInfo) bootstrapUsingPgbasebackup(ctx context.Context) error {
134132
return err
135133
}
136134

137-
pgVersion, err := cluster.GetPostgresqlVersion()
138-
if err != nil {
139-
contextLogger.Warning(
140-
"Error while parsing PostgreSQL server version to define connection options, defaulting to PostgreSQL 11",
141-
"imageName", cluster.GetImageName(),
142-
"err", err)
143-
} else if pgVersion.Major() >= 12 {
144-
// We explicitly disable wal_sender_timeout for join-related pg_basebackup executions.
145-
// A short timeout could not be enough in case the instance is slow to send data,
146-
// like when the I/O is overloaded.
147-
connectionString += " options='-c wal_sender_timeout=0s'"
148-
}
135+
// We explicitly disable wal_sender_timeout for join-related pg_basebackup executions.
136+
// A short timeout could not be enough in case the instance is slow to send data,
137+
// like when the I/O is overloaded.
138+
connectionString += " options='-c wal_sender_timeout=0s'"
149139

150-
err = postgres.ClonePgData(ctx, connectionString, env.info.PgData, env.info.PgWal)
151-
if err != nil {
152-
return err
140+
if err := postgres.ClonePgData(ctx, connectionString, env.info.PgData, env.info.PgWal); err != nil {
141+
return fmt.Errorf("while cloning pgdata: %w", err)
153142
}
154143

155144
if cluster.IsReplica() {

internal/cmd/manager/instance/run/lifecycle/run.go

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,15 @@ package lifecycle
2222
import (
2323
"context"
2424
"database/sql"
25+
"errors"
2526
"fmt"
2627
"sync"
2728

28-
"github.com/blang/semver"
2929
"github.com/cloudnative-pg/machinery/pkg/log"
3030
"github.com/jackc/pgx/v5"
3131

3232
apiv1 "github.com/cloudnative-pg/cloudnative-pg/api/v1"
3333
"github.com/cloudnative-pg/cloudnative-pg/pkg/management/postgres"
34-
postgresutils "github.com/cloudnative-pg/cloudnative-pg/pkg/management/postgres/utils"
3534
)
3635

3736
var identifierStreamingReplicationUser = pgx.Identifier{apiv1.StreamingReplicationUser}.Sanitize()
@@ -153,11 +152,6 @@ func configureInstancePermissions(ctx context.Context, instance *postgres.Instan
153152
return nil
154153
}
155154

156-
pgVersion, err := postgresutils.GetPgdataVersion(instance.PgData)
157-
if err != nil {
158-
return fmt.Errorf("while getting major version: %w", err)
159-
}
160-
161155
db, err := instance.GetSuperUserDB()
162156
if err != nil {
163157
return fmt.Errorf("while getting a connection to the instance: %w", err)
@@ -177,14 +171,12 @@ func configureInstancePermissions(ctx context.Context, instance *postgres.Instan
177171
return fmt.Errorf("creating a new transaction to setup the instance: %w", err)
178172
}
179173

180-
hasSuperuser, err := configureStreamingReplicaUser(tx)
181-
if err != nil {
174+
if err := configureStreamingReplicaUser(tx); err != nil {
182175
_ = tx.Rollback()
183176
return err
184177
}
185178

186-
err = configurePgRewindPrivileges(pgVersion, hasSuperuser, tx)
187-
if err != nil {
179+
if err = configurePgRewindPrivileges(tx); err != nil {
188180
_ = tx.Rollback()
189181
return err
190182
}
@@ -194,28 +186,28 @@ func configureInstancePermissions(ctx context.Context, instance *postgres.Instan
194186

195187
// configureStreamingReplicaUser makes sure the streaming replication user exists
196188
// and has the required rights
197-
func configureStreamingReplicaUser(tx *sql.Tx) (bool, error) {
198-
var hasLoginRight, hasReplicationRight, hasSuperuser bool
199-
row := tx.QueryRow("SELECT rolcanlogin, rolreplication, rolsuper FROM pg_catalog.pg_roles WHERE rolname = $1",
189+
func configureStreamingReplicaUser(tx *sql.Tx) error {
190+
var hasLoginRight, hasReplicationRight bool
191+
row := tx.QueryRow("SELECT rolcanlogin, rolreplication FROM pg_catalog.pg_roles WHERE rolname = $1",
200192
apiv1.StreamingReplicationUser)
201-
err := row.Scan(&hasLoginRight, &hasReplicationRight, &hasSuperuser)
193+
err := row.Scan(&hasLoginRight, &hasReplicationRight)
202194
if err != nil {
203-
if err != sql.ErrNoRows {
204-
return false, fmt.Errorf("while creating streaming replication user: %w", err)
195+
if !errors.Is(err, sql.ErrNoRows) {
196+
return fmt.Errorf("while getting streaming replication user privileges: %w", err)
205197
}
206198

207199
_, err = tx.Exec(fmt.Sprintf(
208200
"CREATE USER %v REPLICATION",
209201
identifierStreamingReplicationUser))
210202
if err != nil {
211-
return false, fmt.Errorf("CREATE USER %v error: %w", apiv1.StreamingReplicationUser, err)
203+
return fmt.Errorf("CREATE USER %v error: %w", apiv1.StreamingReplicationUser, err)
212204
}
213205

214206
_, err = tx.Exec(fmt.Sprintf(
215207
"COMMENT ON ROLE %v IS 'Special user for streaming replication created by CloudNativePG'",
216208
identifierStreamingReplicationUser))
217209
if err != nil {
218-
return false, fmt.Errorf("COMMENT ON ROLE %v error: %w", apiv1.StreamingReplicationUser, err)
210+
return fmt.Errorf("COMMENT ON ROLE %v error: %w", apiv1.StreamingReplicationUser, err)
219211
}
220212
}
221213

@@ -224,28 +216,14 @@ func configureStreamingReplicaUser(tx *sql.Tx) (bool, error) {
224216
"ALTER USER %v LOGIN REPLICATION",
225217
identifierStreamingReplicationUser))
226218
if err != nil {
227-
return false, fmt.Errorf("ALTER USER %v error: %w", apiv1.StreamingReplicationUser, err)
219+
return fmt.Errorf("ALTER USER %v error: %w", apiv1.StreamingReplicationUser, err)
228220
}
229221
}
230-
return hasSuperuser, nil
222+
return nil
231223
}
232224

233225
// configurePgRewindPrivileges ensures that the StreamingReplicationUser has enough rights to execute pg_rewind
234-
func configurePgRewindPrivileges(pgVersion semver.Version, hasSuperuser bool, tx *sql.Tx) error {
235-
// We need the superuser bit for the streaming-replication user since pg_rewind in PostgreSQL <= 10
236-
// will require it.
237-
if pgVersion.Major <= 10 {
238-
if !hasSuperuser {
239-
_, err := tx.Exec(fmt.Sprintf(
240-
"ALTER USER %v SUPERUSER",
241-
identifierStreamingReplicationUser))
242-
if err != nil {
243-
return fmt.Errorf("ALTER USER %v error: %w", apiv1.StreamingReplicationUser, err)
244-
}
245-
}
246-
return nil
247-
}
248-
226+
func configurePgRewindPrivileges(tx *sql.Tx) error {
249227
// Ensure the user has rights to execute the functions needed for pg_rewind
250228
var hasPgRewindPrivileges bool
251229
row := tx.QueryRow(

internal/webhook/v1/cluster_webhook.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ func (v *ClusterCustomValidator) ValidateCreate(_ context.Context, obj runtime.O
105105
if !ok {
106106
return nil, fmt.Errorf("expected a Cluster object but got %T", obj)
107107
}
108-
clusterLog.Info("Validation for Cluster upon creation", "name", cluster.GetName(), "namespace", cluster.GetNamespace())
108+
clusterLog.Info("Validation for Cluster upon creation", "name", cluster.GetName(), "namespace",
109+
cluster.GetNamespace())
109110

110111
allErrs := v.validate(cluster)
111112
allWarnings := v.getAdmissionWarnings(cluster)
@@ -134,7 +135,8 @@ func (v *ClusterCustomValidator) ValidateUpdate(
134135
return nil, fmt.Errorf("expected a Cluster object for the oldObj but got %T", oldObj)
135136
}
136137

137-
clusterLog.Info("Validation for Cluster upon update", "name", cluster.GetName(), "namespace", cluster.GetNamespace())
138+
clusterLog.Info("Validation for Cluster upon update", "name", cluster.GetName(), "namespace",
139+
cluster.GetNamespace())
138140

139141
// applying defaults before validating updates to set any new default
140142
oldCluster.SetDefaults()
@@ -160,7 +162,8 @@ func (v *ClusterCustomValidator) ValidateDelete(_ context.Context, obj runtime.O
160162
if !ok {
161163
return nil, fmt.Errorf("expected a Cluster object but got %T", obj)
162164
}
163-
clusterLog.Info("Validation for Cluster upon deletion", "name", cluster.GetName(), "namespace", cluster.GetNamespace())
165+
clusterLog.Info("Validation for Cluster upon deletion", "name", cluster.GetName(), "namespace",
166+
cluster.GetNamespace())
164167

165168
// TODO(user): fill in your validation logic upon object deletion.
166169

@@ -948,12 +951,12 @@ func (v *ClusterCustomValidator) validateConfiguration(r *apiv1.Cluster) field.E
948951
// validateImageName function
949952
return result
950953
}
951-
if pgVersion.Major() < 12 {
954+
if pgVersion.Major() < 13 {
952955
result = append(result,
953956
field.Invalid(
954957
field.NewPath("spec", "imageName"),
955958
r.Spec.ImageName,
956-
"Unsupported PostgreSQL version. Versions 12 or newer are supported"))
959+
"Unsupported PostgreSQL version. Versions 13 or newer are supported"))
957960
}
958961
info := postgres.ConfigurationInfo{
959962
Settings: postgres.CnpgConfigurationSettings,

internal/webhook/v1/cluster_webhook_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,23 @@ var _ = Describe("configuration change validation", func() {
10301030
Expect(v.validateConfiguration(cluster)).To(HaveLen(1))
10311031
})
10321032

1033+
It("rejects PostgreSQL version lower than 13", func() {
1034+
v := &ClusterCustomValidator{}
1035+
1036+
cluster := &apiv1.Cluster{
1037+
Spec: apiv1.ClusterSpec{
1038+
ImageName: "postgres:12",
1039+
},
1040+
}
1041+
1042+
result := v.validateConfiguration(cluster)
1043+
1044+
Expect(result).To(HaveLen(1))
1045+
Expect(result[0].Field).To(Equal("spec.imageName"))
1046+
Expect(result[0].Detail).To(ContainSubstring("Unsupported PostgreSQL version"))
1047+
Expect(result[0].Detail).To(ContainSubstring("Versions 13 or newer are supported"))
1048+
})
1049+
10331050
It("should disallow changing wal_level to minimal for existing clusters", func() {
10341051
oldCluster := &apiv1.Cluster{
10351052
ObjectMeta: metav1.ObjectMeta{

pkg/management/postgres/join.go

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,29 +77,21 @@ func ClonePgData(ctx context.Context, connectionString, targetPgData, walDir str
7777
func (info InitInfo) Join(ctx context.Context, cluster *apiv1.Cluster) error {
7878
primaryConnInfo := buildPrimaryConnInfo(info.ParentNode, info.PodName) + " dbname=postgres connect_timeout=5"
7979

80-
pgVersion, err := cluster.GetPostgresqlVersion()
81-
if err != nil {
82-
log.Warning(
83-
"Error while parsing PostgreSQL server version to define connection options, defaulting to PostgreSQL 11",
84-
"imageName", cluster.GetImageName(),
85-
"err", err)
86-
} else if pgVersion.Major() >= 12 {
87-
// We explicitly disable wal_sender_timeout for join-related pg_basebackup executions.
88-
// A short timeout could not be enough in case the instance is slow to send data,
89-
// like when the I/O is overloaded.
90-
primaryConnInfo += " options='-c wal_sender_timeout=0s'"
91-
}
80+
// We explicitly disable wal_sender_timeout for join-related pg_basebackup executions.
81+
// A short timeout could not be enough in case the instance is slow to send data,
82+
// like when the I/O is overloaded.
83+
primaryConnInfo += " options='-c wal_sender_timeout=0s'"
9284

9385
coredumpFilter := cluster.GetCoredumpFilter()
9486
if err := system.SetCoredumpFilter(coredumpFilter); err != nil {
9587
return err
9688
}
9789

98-
if err = ClonePgData(ctx, primaryConnInfo, info.PgData, info.PgWal); err != nil {
90+
if err := ClonePgData(ctx, primaryConnInfo, info.PgData, info.PgWal); err != nil {
9991
return err
10092
}
10193

10294
slotName := cluster.GetSlotNameFromInstanceName(info.PodName)
103-
_, err = UpdateReplicaConfiguration(info.PgData, info.GetPrimaryConnInfo(), slotName)
95+
_, err := UpdateReplicaConfiguration(info.PgData, info.GetPrimaryConnInfo(), slotName)
10496
return err
10597
}

pkg/management/postgres/logpipe/logpipe_test.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,6 @@ var _ = Describe("CSV file reader", func() {
5757
Expect(spy.records).To(HaveLen(2))
5858
})
5959

60-
It("can read multiple CSV lines on PostgreSQL version <= 12", func(ctx SpecContext) {
61-
f, err := os.Open("testdata/two_lines_12.csv")
62-
defer func() {
63-
_ = f.Close()
64-
}()
65-
Expect(err).ToNot(HaveOccurred())
66-
67-
spy := SpyRecordWriter{}
68-
p := LogPipe{
69-
record: &LoggingRecord{},
70-
fieldsValidator: LogFieldValidator,
71-
}
72-
Expect(p.streamLogFromCSVFile(ctx, f, &spy)).To(Succeed())
73-
Expect(spy.records).To(HaveLen(2))
74-
})
75-
7660
It("can read multiple CSV lines on PostgreSQL version == 14", func(ctx SpecContext) {
7761
f, err := os.Open("testdata/two_lines_14.csv")
7862
defer func() {

pkg/management/postgres/logpipe/testdata/two_lines_12.csv

Lines changed: 0 additions & 2 deletions
This file was deleted.

pkg/management/postgres/probes_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,6 @@ var _ = Describe("probes", func() {
9393
})
9494

9595
Context("Fill basebackup stats", func() {
96-
It("does nothing in case of that major version is less than 13 ", func() {
97-
instance := &Instance{
98-
pgVersion: &semver.Version{Major: 12},
99-
}
100-
Expect(instance.fillBasebackupStats(nil, nil)).To(Succeed())
101-
})
102-
10396
It("set the information", func() {
10497
instance := (&Instance{
10598
pgVersion: &semver.Version{Major: 13},

0 commit comments

Comments
 (0)