By NHI Mgmt Group Editorial TeamPublished 2025-06-25Domain: Workload IdentitySource: StrongDM

TL;DR: PostgreSQL query auditing can capture who did what and when through native logs, pgAudit, or a proxy layer, but each option shifts cost, detail, and operational burden, according to StrongDM. The governance problem is not just logging more, but preserving usable audit evidence without creating new performance or offboarding gaps.


At a glance

What this is: This is a practitioner guide to PostgreSQL access logging, comparing native logs, pgAudit, and proxy-based audit trails for human database activity.

Why it matters: It matters because auditability, evidence retention, and access lifecycle control sit at the centre of NHI and human privilege governance, especially where database access touches sensitive data or compliance scope.

By the numbers:

👉 Read StrongDM's PostgreSQL query logging and audit guide


Context

PostgreSQL audit logging is really a control problem: organisations need a usable record of database activity without slowing down the system that holds sensitive data. The article frames that tension around human access, where the need to know who queried what, and when, collides with performance and log-management overhead.

For IAM and security teams, the broader issue is not only database logging but access accountability across the full identity stack. When staff, consultants, vendors, and service-linked access all touch production data, PostgreSQL becomes a governance checkpoint for privilege review, evidence collection, and offboarding discipline.


Key questions

Q: How should security teams log PostgreSQL activity without hurting performance?

A: Use a tiered approach. Keep native logging lightweight by default, then increase detail only for sensitive systems or short investigation windows. If continuous audit coverage matters more than full native fidelity, place logging in a proxy or control plane so the database does less I/O while you still retain searchable evidence.

Q: Why do PostgreSQL audit logs matter for identity governance?

A: Because they connect a person or vendor account to a real action inside a production database. That evidence supports access reviews, incident response, and offboarding verification. Without it, teams can see that access existed, but not what the identity actually did with that access.

Q: What breaks when PostgreSQL logging is left local only?

A: Local-only logging breaks central visibility. If logs stay on individual nodes, teams may lose evidence during outages, fail to correlate activity across systems, or miss privileged actions that happened on another database instance. Governance also suffers because review and retention become inconsistent.

Q: Should organisations use proxy logging or native PostgreSQL audit features?

A: Choose based on the control objective. Native logging and PgAudit provide deeper database detail, while proxy logging reduces runtime load and is easier to keep always on. If the priority is forensic precision, stay closer to the database. If the priority is stable production performance, move the logging burden outward.


Technical breakdown

Native PostgreSQL logs and role-based statement capture

PostgreSQL can log statements directly by role using settings such as log_statement, with output routed to standard log files or CSV for downstream parsing. That gives strong locality and can preserve raw SQL detail, but the database itself absorbs the I/O cost. In practice, the logging surface is tightly coupled to the engine, which means the more detail you capture, the more you must plan for rotation, storage, and performance impact. This is useful when you need native evidence and can tolerate the overhead.

Practical implication: tune statement logging only where you can absorb the I/O cost and centralise the resulting logs quickly.

PgAudit adds session-level detail but expands overhead

PgAudit sits inside the database and breaks complex activity into more granular audit records, including function calls and individual DDL actions. That makes replaying administrative behaviour easier than with standard logs, especially for dynamic SQL. The tradeoff is that every extra line of evidence increases disk usage and I/O pressure, so the control improves forensic clarity while raising operational strain. The article’s example shows why audit depth and database performance are in direct tension.

Practical implication: reserve high-fidelity audit mode for periods or systems where deeper forensic detail outweighs extra resource consumption.

Proxy-based query logging shifts burden away from the database

A proxy can capture queries outside the PostgreSQL server, reducing database I/O while still recording activity across users and sessions. That changes the architecture of audit collection: the proxy becomes the logging choke point, but it cannot reproduce every native database event with the same fidelity as in-server audit tooling. This makes it a pragmatic option for always-on visibility when performance is the primary constraint, especially across multiple databases and servers.

Practical implication: use proxy logging when you need continuous audit coverage without placing extra load on the database engine.


  • DeepSeek breach — DeepSeek breach exposed 1M+ log lines and sensitive secret keys.
  • MongoBleed breach — MongoBleed exposed secrets across 87K MongoDB servers.

Read our 52 NHI Breaches Analysis report for a comprehensive view of breaches impacting Non-Human Identities including AI Agents.


NHI Mgmt Group analysis

Audit logging is an access accountability control, not a database convenience feature. The article makes clear that query logging exists because teams need to reconstruct who touched sensitive data and when. That places PostgreSQL logging inside the broader IAM and governance problem of proving authorised activity, especially where human, consultant, and vendor access all intersect. Practitioners should treat it as evidence infrastructure, not an optional operations tool.

Performance-aware audit design is the real control boundary. Native logging and pgAudit both improve traceability, but they do so by consuming disk and I/O, which can turn visibility into a self-inflicted service risk. The named concept here is audit fidelity versus runtime load: the more detail you retain, the more carefully you must engineer the collection path. Practitioners need to separate forensic ambition from production tolerance.

Offboarding without log-backed access review leaves a governance blind spot. The article notes that staff, consultants, and vendors all need audit trails, yet access may be created and removed through external identity systems. That means database logs have to support lifecycle governance, not just incident response. The implication is that access evidence must remain tied to identity changes, not float as disconnected query records.

Database audit trails only work when they are centralised and searchable. Raw logs sitting on one PostgreSQL node do not create governance value if the organisation cannot aggregate, query, and retain them consistently. This is where NIST CSF style logging and monitoring discipline meets operational IAM reality. Practitioners should assume distributed databases will fail local-only audit strategies unless log collection is designed upfront.

The real decision is where to pay the cost of observability. The article shows three places to absorb it: inside PostgreSQL, inside PgAudit, or in a proxy layer. Each choice changes the balance between detail, performance, and operational complexity. The governance lesson is that audit design is an architecture decision, not a plug-in decision, and teams should make it deliberately before they need evidence.

From our research:

  • 96% of organisations store secrets outside of secrets managers in vulnerable locations including code, config files, and CI/CD tools, according to Ultimate Guide to NHIs.
  • Only 5.7% of organisations have full visibility into their service accounts, which is why audit trails must be designed for discoverability as well as retention.
  • That visibility gap is one reason to pair PostgreSQL audit evidence with broader lifecycle governance, as discussed in NHI Lifecycle Management Guide.

What this signals

Audit logging is moving from a database admin concern to an identity governance requirement. As access paths multiply across humans, vendors, and machine identities, the value of a PostgreSQL audit trail depends on whether it can be joined to entitlement data and lifecycle events. Teams that treat logs as standalone artefacts will struggle to turn them into governance evidence.

Audit fidelity versus runtime load is the operational tradeoff that programme owners now have to manage explicitly. In environments with regulated data or active incident response needs, the question is no longer whether to log, but where to place the cost so visibility survives scale without degrading the service.

For programmes already working toward stronger non-human identity discipline, database auditing is a natural extension of the same control family. If you can prove who accessed a database and when, you can begin aligning that record with offboarding, recertification, and privileged access review across the wider estate.


For practitioners

  • Map audit depth to data sensitivity Apply the highest-fidelity logging only to databases that handle PII, PHI, or regulated workloads. Use lighter logging for lower-risk systems so you do not overburden production unnecessarily.
  • Centralise PostgreSQL logs immediately Send logs to a shared collector or SIEM as part of the baseline design, especially where more than one node exists. Local-only logging creates evidence gaps when teams need to reconstruct access across systems.
  • Tie database logs to joiner-mover-leaver events Review which human and third-party identities still have active database access after role changes, contract changes, or offboarding. Query records are only useful when they can be linked to current entitlement state.
  • Use proxy logging for continuous coverage Choose a proxy when the main requirement is persistent query visibility without extra database I/O. Keep in mind that proxy-based logging may reduce native detail for some database actions.
  • Enable higher-detail logging for short-lived investigations Turn on more detailed audit settings for patching windows, external auditor access, or other scoped investigations. Restore baseline settings once the review is complete to limit storage and performance impact.

Key takeaways

  • PostgreSQL audit logging is about proving accountable access, not just collecting server output.
  • The core tradeoff is between forensic detail and database performance, and that tradeoff must be engineered deliberately.
  • Centralised, identity-linked logs are the difference between usable evidence and disconnected query history.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

OWASP Non-Human Identity Top 10 address the attack and risk surface, while NIST CSF 2.0 and NIST Zero Trust (SP 800-207) set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
OWASP Non-Human Identity Top 10NHI-03Covers logging and auditability of NHI access paths.
NIST CSF 2.0PR.PT-1Logging architecture affects production protection and telemetry.
NIST Zero Trust (SP 800-207)Zero Trust requires continuous verification and evidence of access.

Design audit collection so logging does not degrade service while still preserving traceable activity records.


Key terms

  • Audit Trail: A record that shows who did what, when, and in what context. In database governance, an audit trail is only useful if it is complete enough to support incident response, access review, and compliance evidence without creating so much overhead that teams disable it.
  • PgAudit: A PostgreSQL auditing extension that records more detailed session and statement activity than standard logs. It improves forensic visibility for database operations, but it also increases storage and I/O demands, so it must be deployed with clear performance and retention boundaries.
  • Proxy Logging: A logging approach that captures queries and access events outside the database engine. It reduces load on PostgreSQL itself and is often easier to keep running at scale, but it may not preserve every native event detail that in-server auditing can capture.
  • Identity-Linked Evidence: Audit data that can be connected back to a specific human, vendor, or machine identity and its current entitlement state. Without that linkage, logs are only activity records; with it, they become governance evidence for access review, offboarding, and investigation.

Deepen your knowledge

PostgreSQL audit logging, privilege traceability, and identity-linked evidence are core topics in our NHI Foundation Level course, the industry's only accredited NHI security programme. If you are building governance around database access and offboarding, it is worth exploring.

This post draws on content published by StrongDM: PostgreSQL Log Queries and Audit. Read the original.

NHIMG Editorial Note
Published by the NHIMG editorial team on 2025-06-25.
NHI Mgmt Group — the independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org