Repository navigation
Description
Is there an existing issue already for this bug?
- I have searched for an existing issue, and could not find anything. I believe this is a new bug.
I have read the troubleshooting guide
- I have read the troubleshooting guide and I think this is a new bug.
I am running a supported version of CloudNativePG
- I have read the troubleshooting guide and I think this is a new bug.
Contact Details
Version
1.29 (latest patch)
What version of Kubernetes are you using?
1.35
What is your Kubernetes environment?
Cloud: Amazon EKS
How did you install the operator?
Helm
What happened?
I configured a Cluster with postgreSQL auditing enabled with pgaudit. Then I ran a pair of queries: one that produces a lot of auditing output quickly, and one that's got a nice distinctive error message.
kubectl exec -it mycluster-0 -- bash -c 'psql "\df *.*"; psql "CREAT TABLE foo(id int)"'Meanwhile, I watched the logs from the cluster in another terminal:
kubectl logs -f mycluster-0 | grep 'CREAT 'and the log message never came through.
I believe this is due to a few factors:
- CNPG logs
"msg": "record"on every record it outputs via this function. - controller-runtime defaults to adding a sampler to its logger
- A sampler discards messages which contain the same message if they occur too often within a specified timeframe
- CNPG uses the controller-runtime logger for all of its output.
This is not an ideal outcome, audit logs should not be dropped. However, I'm not sure of the right way to fix it; it might be best for the controller to determine "this cluster's logs should not be sampled" or maybe the instance manager should do so, maybe it should be communicated from the controller to the instance manager with a flag or an environment variable, maybe audit logs should always be sent through an un-sampled logger or maybe all Postgres logs should or maybe it should always be up to an administrator, and so on.
I'm happy to implement the code to make the changes if desired, I came up with a dirty hack that makes the audit logs work properly for my particular circumstances and could adapt it if that would be helpful, but the questions above (and probably many more) made me think twice about just starting a pull request that makes a bunch of decisions up front.
Cluster resource
Relevant log output
Code of Conduct
- I agree to follow this project's Code of Conduct
Activity
gbartolini commentedon Jun 11, 2026
Can you please share the cluster definition to reproduce it? However, if I recall correctly, pgaudit only logs successfully executed commands (you mispelled
CREATE).willmurnane commentedon Jun 11, 2026
Here's
test.yaml:(The parameters could probably be cut down to just the 'pgaudit' stuff, and I think there's some other config noise in there, but this is what I tested verbatim.)
Steps to reproduce:
kubectl apply -f test.yaml kubectl wait clusters.postgresql.cnpg.io test-auditing --for=condition=ReadyThen, in one terminal:
and in another, first demonstrate that this command produces an error message in the logs:
Now run this command, which spews a bunch of stuff to the audit logs and then produces the error message we expect to see afterwards:
Meanwhile in the logs, no "CREAT " shows up this time. 95%+ failure rate in my environment.
I was able to fix the dropped logs by manually building a logger with no sampler attached, and calling
{log, ctrl, log}.SetLogger(loggerWithNoSampler)but that's a big hammer that CNPG might not want to use all the time.feat(log): allow disabling the zap duplicate-message sampler (#292)
fix(logging): stop sampling logs of the pods' processes
fix(logging): stop sampling logs of the pods' processes (cloudnative-…
fix(logging): stop sampling logs of the pods' processes (#11131)
fix(logging): stop sampling logs of the pods' processes (#11131)
fix(logging): stop sampling logs of the pods' processes (#11131)
fix(logging): stop sampling logs of the pods' processes (cloudnative-…