Logging v1
The operator is designed to log in JSON format directly to standard output, including PostgreSQL logs.
Each log entry has the following fields:
level
: log level (info
,notice
, ...)ts
: the timestamp (epoch with microseconds)logger
: the type of the record (e.g.postgres
orpg_controldata
)msg
: the actual message or the keywordrecord
in case the message is parsed in JSON formatrecord
: the actual record (with structure that varies depending on thelogger
type)logging_pod
: the name of the pod where the log was created
Warning
Long-term storage and management of logs is outside the operator's purview, and needs to be provided at the level of the Kubernetes installation. Please refer to the Kubernetes Logging Architecture documentation.
Info
The level
and ts
field names can be renamed via the log-field-level
and
log-field-timestamp
flags of the operator controller, should your log ingestion
system require it. All you have to do is edit the Deployment
definition of the
cloudnative-pg
operator.
Operator log
A log level can be specified in the cluster spec with the option logLevel
and
can be set to any of error
, warning
, info
(default), debug
or trace
.
At the moment, the log level can only be set when an instance starts and can not be changed at runtime. If the value is changed in the cluster spec after the cluster was started, this will take effect only in the new pods and not the old ones.
PostgreSQL log
Each entry in the PostgreSQL log is a JSON object having the logger
key set
to postgres
and the structure described in the following example:
Internally, the operator relies on the PostgreSQL CSV log format. Please refer to the PostgreSQL documentation for more information about the CSV log format.
PGAudit logs
EDB Postgres for Kubernetes has transparent and native support for PGAudit on PostgreSQL clusters.
All you need to do is add the required pgaudit
parameters to the postgresql
section in the configuration of the cluster.
Important
It is unnecessary to add the PGAudit library to shared_preload_libraries
.
The library will be added automatically by EDB Postgres for Kubernetes based on the
presence of pgaudit.*
parameters in the postgresql configuration.
The operator will detect and manage the addition and removal of the
library from shared_preload_libraries
.
The operator also takes care of creating and removing the extension from all the available databases in the cluster.
Important
EDB Postgres for Kubernetes runs the CREATE EXTENSION
and
DROP EXTENSION
command in all databases in the cluster that accept
connections.
Here is an example of a PostgreSQL 13 Cluster
deployment which will result in
pgaudit
being enabled with the requested configuration:
The audit CSV logs entries returned by PGAudit are then parsed and routed to stdout in JSON format, similarly to all the remaining logs:
.logger
is set topgaudit
.msg
is set torecord
.record
contains the whole parsed record as a JSON object, similar tologging_collector
logs - except for.record.audit
, which contains the PGAudit CSV message formatted as a JSON object
See the example below:
Please refer to 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 that are produced by the operator and its instances are in JSON
format, with logger
set accordingly to the process that produced them.
Therefore, all the possible logger
values are the following ones:
barman-cloud-wal-archive
: frombarman-cloud-wal-archive
directlybarman-cloud-wal-restore
: frombarman-cloud-wal-restore
directlyedb_audit
: from the EDB Audit extensioninitdb
: from runninginitdb
pg_basebackup
: from runningpg_basebackup
pg_controldata
: from runningpg_controldata
pg_ctl
: from running anypg_ctl
subcommandpg_rewind
: from runningpg_rewind
pgaudit
: from PGAudit extensionpostgres
: from thepostgres
instance (havingmsg
different thanrecord
)wal-archive
: from thewal-archive
subcommand of the instance managerwal-restore
: from thewal-restore
subcommand of the instance manager
Except for postgres
and edb_audit
that have the aforementioned structures,
all other possible values just have msg
set to the escaped message that is
logged.