Skip to content

[Bug]: PG audit logs are dropped #10815

Closed

Description

@willmurnane

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

[email protected]

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:

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

  1. gbartolini commented on Jun 11, 2026

    @gbartolini
    Contributor

    Can you please share the cluster definition to reproduce it? However, if I recall correctly, pgaudit only logs successfully executed commands (you mispelled CREATE).

  2. willmurnane commented on Jun 11, 2026

    @willmurnane
    Author

    Here's test.yaml:

    apiVersion: postgresql.cnpg.io/v1
    kind: Cluster
    metadata:
      name: test-auditing
    spec:
      affinity:
        podAntiAffinityType: preferred
      bootstrap:
        initdb:
          database: app
          encoding: UTF8
          localeCType: C
          localeCollate: C
          owner: app
      instances: 1
      logLevel: info
      postgresGID: 26
      postgresUID: 26
      postgresql:
        parameters:
          archive_mode: "on"
          archive_timeout: 5min
          dynamic_shared_memory_type: posix
          full_page_writes: "on"
          log_destination: csvlog
          log_directory: /controller/log
          log_filename: postgres
          log_rotation_age: "0"
          log_rotation_size: "0"
          log_truncate_on_rotation: "false"
          logging_collector: "on"
          max_parallel_workers: "32"
          max_replication_slots: "32"
          max_worker_processes: "32"
          pgaudit.log: all,-misc,-function
          pgaudit.log_catalog: "on"
          pgaudit.log_level: log
          pgaudit.log_parameter: "on"
          pgaudit.log_statement_once: "off"
          shared_memory_type: mmap
          shared_preload_libraries: ""
          ssl_max_protocol_version: TLSv1.3
          ssl_min_protocol_version: TLSv1.3
          tcp_keepalives_count: "3"
          tcp_keepalives_idle: "60"
          tcp_keepalives_interval: "10"
          wal_keep_size: 512MB
          wal_level: logical
          wal_log_hints: "on"
          wal_receiver_timeout: 5s
          wal_sender_timeout: 5s
        pg_hba:
        - hostssl all all 0.0.0.0/0 scram-sha-256 clientcert=verify-ca
        - hostssl all all ::0/0 scram-sha-256 clientcert=verify-ca
        syncReplicaElectionConstraint:
          enabled: false
      storage:
        resizeInUseVolumes: true
        size: 1Gi

    (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=Ready

    Then, in one terminal:

    kubectl logs -f -l app.kubernetes.io/instance=test-auditing

    and in another, first demonstrate that this command produces an error message in the logs:

    kubectl exec -it test-auditing-1 -c postgres -- bash -c 'psql -c "CREAT TABLE test_table(id INT)"'
    ERROR:  syntax error at or near "CREAT"
    LINE 1: CREAT TABLE test_table(id INT)
            ^
    command terminated with exit code 1
    # logs in the first window:
    {"level":"info","ts":"2026-06-11T14:52:30.612446257Z","logger":"postgres","msg":"record","logging_pod":"test-auditing-1","record":{"log_time":"2026-06-11 14:52:30.612 UTC","user_name":"postgres","database_name":"postgres","process_id":"406","connection_from":"[local]","session_id":"6a2acbae.196","session_line_num":"1","command_tag":"idle","session_start_time":"2026-06-11 14:52:30 UTC","virtual_transaction_id":"13/7","transaction_id":"0","error_severity":"ERROR","sql_state_code":"42601","message":"syntax error at or near \"CREAT\"","query":"CREAT TABLE test_table(id INT)","query_pos":"1","application_name":"psql","backend_type":"client backend","query_id":"0"}}

    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:

    kubectl exec -it test-auditing-1 -c postgres -- bash -c 'psql -P pager --csv -c "\df+ *.*" >/dev/null ; psql -c "CREAT TABLE test_table(id INT)"'
    ERROR:  syntax error at or near "CREAT"
    LINE 1: CREAT TABLE test_table(id INT)
            ^
    command terminated with exit code 1

    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.

  3. added
    bug 🐛
    and removed on Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug 🐛triage

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions