MCPcopy Create free account
hub / github.com/CrunchyData/postgres-operator / PostgreSQLParameters

Function PostgreSQLParameters

internal/collector/postgres.go:23–75  ·  view source on GitHub ↗
(ctx context.Context,
	inCluster *v1beta1.PostgresCluster,
	outParameters *postgres.Parameters,
)

Source from the content-addressed store, hash-verified

21)
22
23func PostgreSQLParameters(ctx context.Context,
24 inCluster *v1beta1.PostgresCluster,
25 outParameters *postgres.Parameters,
26) {
27 version := inCluster.Spec.PostgresVersion
28
29 if OpenTelemetryLogsEnabled(ctx, inCluster) {
30 var spec *v1beta1.InstrumentationLogsSpec
31 if inCluster != nil && inCluster.Spec.Instrumentation != nil {
32 spec = inCluster.Spec.Instrumentation.Logs
33 }
34
35 // Retain logs for a short time unless specified.
36 retention := metav1.Duration{Duration: 24 * time.Hour}
37 if spec != nil && spec.RetentionPeriod != nil {
38 retention = spec.RetentionPeriod.AsDuration()
39 }
40
41 // Rotate log files according to retention and name them for the OpenTelemetry Collector.
42 //
43 // The ".log" suffix is replaced by ".csv" for CSV log files, and
44 // the ".log" suffix is replaced by ".json" for JSON log files.
45 //
46 // https://www.postgresql.org/docs/current/runtime-config-logging.html
47 for k, v := range postgres.LogRotation(retention, "postgresql-", ".log") {
48 outParameters.Mandatory.Add(k, v)
49 }
50
51 // Enable logging to file. Postgres uses a "logging collector" to safely write concurrent messages.
52 // NOTE: That collector is designed to not lose messages. When it is overloaded, other Postgres processes block.
53 //
54 // https://www.postgresql.org/docs/current/runtime-config-logging.html
55 outParameters.Mandatory.Add("logging_collector", "on")
56
57 // Enable structured logging. This setting is combined with any specified on the cluster.
58 //
59 // The JSON format of PostgreSQL v15 delimits messages with newline U+000A
60 // and escapes newlines in message content as "\n", U+005C + U+006E.
61 // JSON keys take up space on disk, but newline-delimited is easy to parse.
62 outParameters.Mandatory.Add("log_destination", "jsonlog")
63
64 // The only structured format prior to PostgreSQL v15 is the CSV format, added in PostgreSQL v8.3.
65 // This format does *not* escape newlines, so the Collector must search for the beginning of each message.
66 // Forcing the UTC timezone ensures a consistent beginning to each message.
67 if version < 15 {
68 outParameters.Mandatory.Add("log_destination", "csvlog")
69 outParameters.Mandatory.Add("log_timezone", "UTC")
70 }
71
72 // Log in a timezone the OpenTelemetry Collector understands.
73 outParameters.Mandatory.Add("log_timezone", "UTC")
74 }
75}
76
77func NewConfigForPostgresPod(ctx context.Context,
78 inCluster *v1beta1.PostgresCluster,

Callers 2

TestPostgresParametersFunction · 0.70

Calls 4

LogRotationFunction · 0.92
OpenTelemetryLogsEnabledFunction · 0.85
AsDurationMethod · 0.80
AddMethod · 0.45

Tested by 1

TestPostgresParametersFunction · 0.56