Logging v1
EDB Postgres for Kubernetes outputs logs in JSON format directly to standard output, including PostgreSQL logs, without persisting them to storage for security reasons. This design facilitates seamless integration with most Kubernetes-compatible log management tools, including command line ones like stern.
Important
Long-term storage and management of logs are outside the scope of the operator and should be handled at the Kubernetes infrastructure level. For more information, see the Kubernetes Logging Architecture documentation.
Each log entry includes the following fields:
level
– The log level (e.g.,info
,notice
).ts
– The timestamp.logger
– The type of log (e.g.,postgres
,pg_controldata
).msg
– The log message, or the keywordrecord
if the message is in JSON format.record
– The actual record, with a structure that varies depending on thelogger
type.logging_pod
– The name of the pod where the log was generated.
Info
If your log ingestion system requires custom field names, you can rename
the level
and ts
fields using the log-field-level
and
log-field-timestamp
flags in the operator controller. This can be configured
by editing the Deployment
definition of the cloudnative-pg
operator.
Cluster Logs
You can configure the log level for the instance pods in the cluster
specification using the logLevel
option. Available log levels are: error
,
warning
, info
(default), debug
, and trace
.
Important
Currently, the log level can only be set at the time the instance starts. Changes to the log level in the cluster specification after the cluster has started will only apply to new pods, not existing ones.
Operator Logs
The logs produced by the operator pod can be configured with log
levels, same as instance pods: error
, warning
, info
(default), debug
,
and trace
.
The log level for the operator can be configured by editing the Deployment
definition of the operator and setting the --log-level
command line argument
to the desired value.
PostgreSQL Logs
Each PostgreSQL log entry is a JSON object with the logger
key set to
postgres
. The structure of the log entries is as follows:
Info
Internally, the operator uses PostgreSQL's CSV log format. For more details, refer to the PostgreSQL documentation on CSV log format.
PGAudit Logs
EDB Postgres for Kubernetes offers seamless and native support for PGAudit on PostgreSQL clusters.
To enable PGAudit, add the necessary pgaudit
parameters in the postgresql
section of the cluster configuration.
Important
The PGAudit library must be added to shared_preload_libraries
.
EDB Postgres for Kubernetes automatically manages this based on the presence of pgaudit.*
parameters in the PostgreSQL configuration. The operator handles both the
addition and removal of the library from shared_preload_libraries
.
Additionally, the operator manages the creation and removal of the PGAudit extension across all databases within the cluster.
Important
EDB Postgres for Kubernetes executes the CREATE EXTENSION
and DROP EXTENSION
commands
in all databases within the cluster that accept connections.
The following example demonstrates a PostgreSQL Cluster
deployment with
PGAudit enabled and configured:
The audit CSV log entries generated by PGAudit are parsed and routed to standard output in JSON format, similar to all other logs:
.logger
is set topgaudit
..msg
is set torecord
..record
contains the entire parsed record as a JSON object. This structure resembles that oflogging_collector
logs, with the exception of.record.audit
, which contains the PGAudit CSV message formatted as a JSON object.
This example shows sample log entries:
See the PGAudit documentation for more details about each field in a record.
EDB Audit logs
Clusters that are running on EDB Postgres Advanced Server (EPAS) can enable EDB Audit as follows:
Setting .spec.postgresql.epas.audit: true
enforces the following parameters:
Other parameters can be passed via .spec.postgresql.parameters
as usual.
The audit CSV logs are parsed and routed to stdout in JSON format, similarly to all the remaining logs:
.logger
set toedb_audit
.msg
set torecord
.record
containing the whole parsed record as a JSON object
See the example below:
See EDB Audit file for more details about the records' fields.
Other Logs
All logs generated by the operator and its instances are in JSON format, with
the logger
field indicating the process that produced them. The possible
logger
values are as follows:
barman-cloud-wal-archive
: logs frombarman-cloud-wal-archive
barman-cloud-wal-restore
: logs frombarman-cloud-wal-restore
edb_audit
: from the EDB Audit extensioninitdb
: logs from runninginitdb
pg_basebackup
: logs from runningpg_basebackup
pg_controldata
: logs from runningpg_controldata
pg_ctl
: logs from running anypg_ctl
subcommandpg_rewind
: logs from runningpg_rewind
pgaudit
: logs from the PGAudit extensionpostgres
: logs from thepostgres
instance (withmsg
distinct fromrecord
)wal-archive
: logs from thewal-archive
subcommand of the instance managerwal-restore
: logs from thewal-restore
subcommand of the instance managerinstance-manager
: from the PostgreSQL instance manager
With the exception of postgres
and edb_audit
, which follows a specific structure, all other
logger
values contain the msg
field with the escaped message that is
logged.