@@ -20,6 +20,10 @@ const (
20
20
AutovacuumNaptimeKey = "autovacuum_naptime"
21
21
EffectiveIOKey = "effective_io_concurrency" // linux only
22
22
23
+ // nonnumeric
24
+ DefaultToastCompression = "default_toast_compression"
25
+ Jit = "jit"
26
+
23
27
checkpointDefault = "0.9"
24
28
statsTargetDefault = "100"
25
29
randomPageCostDefault = "1.1"
@@ -31,6 +35,8 @@ const (
31
35
// https://www.postgresql.org/message-id/20210422195232.GA25061%40momjian.us
32
36
effectiveIODefaultOldVersions = "200"
33
37
effectiveIODefault = "256"
38
+ lz4Compression = "lz4"
39
+ off = "off"
34
40
35
41
// If you want to lower this value, consider that Patroni will not accept anything less than 25 as
36
42
// a valid max_connections and will replace it with 100, per
@@ -59,12 +65,18 @@ func getMaxConns(totalMemory uint64) uint64 {
59
65
}
60
66
}
61
67
68
+ func getValueForVersion (currentVersion string , oldVersions []string , oldVersionValue , newVersionValue string ) string {
69
+ for _ , ov := range oldVersions {
70
+ if ov == currentVersion {
71
+ return oldVersionValue
72
+ }
73
+ }
74
+ return newVersionValue
75
+ }
76
+
62
77
func getEffectiveIOConcurrency (pgMajorVersion string ) string {
63
78
switch pgMajorVersion {
64
- case pgutils .MajorVersion96 ,
65
- pgutils .MajorVersion10 ,
66
- pgutils .MajorVersion11 ,
67
- pgutils .MajorVersion12 :
79
+ case pgutils .MajorVersion96 , pgutils .MajorVersion10 , pgutils .MajorVersion11 , pgutils .MajorVersion12 :
68
80
return effectiveIODefaultOldVersions
69
81
}
70
82
return effectiveIODefault
@@ -90,7 +102,10 @@ var MiscKeys = []string{
90
102
MaxLocksPerTxKey ,
91
103
AutovacuumMaxWorkersKey ,
92
104
AutovacuumNaptimeKey ,
93
- EffectiveIOKey ,
105
+ DefaultToastCompression ,
106
+ Jit ,
107
+
108
+ EffectiveIOKey , //linux only
94
109
}
95
110
96
111
// MiscRecommender gives recommendations for MiscKeys based on system resources.
@@ -113,37 +128,49 @@ func (r *MiscRecommender) IsAvailable() bool {
113
128
// Recommend returns the recommended PostgreSQL formatted value for the conf
114
129
// file for a given key.
115
130
func (r * MiscRecommender ) Recommend (key string ) string {
116
- var val string
117
- if key == CheckpointKey {
118
- val = checkpointDefault
119
- } else if key == StatsTargetKey {
120
- val = statsTargetDefault
121
- } else if key == MaxConnectionsKey {
122
- conns := getMaxConns (r .totalMemory )
131
+ switch key {
132
+ case CheckpointKey :
133
+ return checkpointDefault
134
+ case StatsTargetKey :
135
+ return statsTargetDefault
136
+ case AutovacuumMaxWorkersKey :
137
+ return autovacuumMaxWorkersDefault
138
+ case AutovacuumNaptimeKey :
139
+ return autovacuumNaptimeDefault
140
+ case RandomPageCostKey :
141
+ return randomPageCostDefault
142
+ case EffectiveIOKey :
143
+ return getValueForVersion (r .pgMajorVersion , []string {
144
+ pgutils .MajorVersion96 , pgutils .MajorVersion10 , pgutils .MajorVersion11 , pgutils .MajorVersion12 },
145
+ effectiveIODefaultOldVersions , effectiveIODefault ,
146
+ )
147
+ case DefaultToastCompression :
148
+ return getValueForVersion (r .pgMajorVersion , []string {
149
+ pgutils .MajorVersion96 , pgutils .MajorVersion10 , pgutils .MajorVersion11 , pgutils .MajorVersion12 , pgutils .MajorVersion13 },
150
+ NoRecommendation , lz4Compression ,
151
+ )
152
+ case Jit :
153
+ return getValueForVersion (r .pgMajorVersion , []string {
154
+ pgutils .MajorVersion96 , pgutils .MajorVersion10 , pgutils .MajorVersion11 },
155
+ NoRecommendation , off ,
156
+ )
157
+ case MaxConnectionsKey :
123
158
if r .maxConns != 0 {
124
- conns = r .maxConns
159
+ return fmt . Sprintf ( "%d" , r .maxConns )
125
160
}
126
- val = fmt .Sprintf ("%d" , conns )
127
- } else if key == RandomPageCostKey {
128
- val = randomPageCostDefault
129
- } else if key == MaxLocksPerTxKey {
161
+ return fmt .Sprintf ("%d" , getMaxConns (r .totalMemory ))
162
+ case MaxLocksPerTxKey :
130
163
for i := len (maxLocksValues ) - 1 ; i >= 1 ; i -- {
131
164
limit := uint64 (math .Pow (2.0 , float64 (2 + i )))
132
165
if r .totalMemory >= limit * parse .Gigabyte {
133
166
return maxLocksValues [i ]
134
167
}
135
168
}
136
169
return maxLocksValues [0 ]
137
- } else if key == AutovacuumMaxWorkersKey {
138
- val = autovacuumMaxWorkersDefault
139
- } else if key == AutovacuumNaptimeKey {
140
- val = autovacuumNaptimeDefault
141
- } else if key == EffectiveIOKey {
142
- val = getEffectiveIOConcurrency (r .pgMajorVersion )
143
- } else {
144
- val = NoRecommendation
145
170
}
146
- return val
171
+
172
+ //unknown key no recommendation
173
+ return NoRecommendation
147
174
}
148
175
149
176
// MiscSettingsGroup is the SettingsGroup to represent settings that do not fit in other SettingsGroups.
0 commit comments