pgAudit audit logging for PostgreSQL

pgAudit records which statements and objects your PostgreSQL users touch, in a form your security and compliance teams can review. This page covers the configuration decisions, the rollout, and what drives effort and log volume.

On this page

Why teams add pgAudit to self-hosted PostgreSQL audit logging

A security, compliance or platform lead who must show who accessed or changed regulated data in a self-hosted PostgreSQL database needs more than the server log. Standard PostgreSQL logging can record connections, errors and, when configured, individual statements, but it does not give a consistent, classified record of the reads and writes against specific tables that an assessor will ask about. The pgAudit extension adds that structured audit trail. It is typically added when a team must answer questions such as who read a customer table, who changed a privilege, or which role ran a DDL statement, and must answer them from logs that were not written by the application itself.

pgAudit adds two mechanisms on top of standard logging. Session audit logging records statements by class, such as READ, WRITE, DDL, ROLE and MISC, for every session that matches the configuration. Object audit logging records statements against specific tables or objects through the audit role, so that access to sensitive data can be traced separately from general traffic. Teams usually adopt it when their control framework expects audit records with actor, object and statement type, when a SIEM needs fields it can alert on, or when application-level logging has been found to be incomplete or bypassable through direct database access.

Before you design the configuration, confirm the pgAudit documentation for the exact build you will deploy, including which PostgreSQL major versions that build supports and how it is installed through your package source or container image. Plan for the controls and the evidence, not the verdict: DeployOpen configures pgAudit, sets up log routing and retention, and documents how the settings map to your requirements, but auditors decide whether that evidence is sufficient for your assessment. Ask your assessor early which events they expect to see and how long they expect records to be kept.

What pgAudit logs inside a PostgreSQL session

pgAudit adds structured audit records to the PostgreSQL log, and most of the design work is choosing which activity earns a record. The cards below separate the parallel capabilities you configure, from statement classes to object rules, and note where the exact settings must be checked against the documentation for your version.

Session auditing by statement class

Session auditing records statements by class, such as reads, writes, DDL, role changes and misc commands, for every session that matches the configuration. Start from the classes your control framework names, not from the full list, because each added class multiplies log volume. Confirm the class names and the setting that enables them in the pgAudit documentation for the extension version you run, since names have changed between releases.

PostgreSQL logging context

Object auditing through roles

Object auditing logs statements that touch specific tables, views or columns, and it is driven by a role that pgAudit grants the right to be audited. Because the audit trail depends on which role holds the privilege, role design becomes an audit design decision. Test the rule with a sample table before relying on it, and confirm how the role is assigned and granted in your pgAudit version.

Bind parameters and catalog access

Logging bind parameters records the values passed to prepared statements, which can help reconstruct an event but can also write personal or secret data into the log. Catalog access logging records queries against system tables, which is useful for spotting reconnaissance. Decide both settings with your privacy and security teams, and confirm the exact keys and their defaults in the documentation for your release.

Entries written through normal logging

pgAudit does not keep its own store. It writes audit entries through PostgreSQL's standard logging system, so log destination, format, rotation and permissions come from the server's logging settings. Check that the logging collector, log file ownership and log line prefix let your SIEM parse the audit tag reliably. Confirm these requirements against your PostgreSQL and pgAudit versions before the first shipping test.

PostgreSQL authentication docs

Version pairing with the PostgreSQL major

Each pgAudit release targets specific PostgreSQL major versions, so the extension must be built and loaded against the server major you run. Mismatches usually fail at load time, but a planned major upgrade can also leave audit settings silently inactive if the new build is not installed. Check the compatibility matrix for your major, and plan the extension in the same change window as the server upgrade.

Next EOL year for 14
2026
PostgreSQL versioning policy

How an audit event travels from the database to the SIEM

The flow starts when a client session connects and passes through PostgreSQL's client authentication, so each audited statement is tied to an identified role. The statement then runs on the database host, where pgAudit checks whether its statement class is in scope for logging. Matching entries go to the PostgreSQL log, which should be readable only by the database host and the log shipper. The shipper forwards entries across the trust boundary to the SIEM, which stores them and drives alerts. Check three hand-offs: that authentication identifies each user, that the class filter matches your policy, and that the shipper and SIEM keep every entry.

Audit events cross from the database host to the SIEM at one trust boundary.

Which pgAudit statement classes to log and when each fits

This table compares the main pgAudit logging decisions: session versus object auditing, individual statement classes, bind parameters and catalog access. Read each row for what it records, how much volume it tends to add, and the regulated or operational case that usually justifies turning it on.

Decision or classWhat it capturesVolume it addsWhen it usually fits
Session auditing (pgaudit.log)Every statement of the chosen classes run by any session, including those from application service accountsHighest of the two modes because all matching activity is loggedBroad compliance scopes where assessors expect a complete record of privileged or sensitive activity
Object auditing (pgaudit.role)Only statements that touch objects granted to the audit role, such as specific regulated tablesUsually lower, since it follows the audited objects rather than every sessionTargeted reviews of cardholder, health or personnel tables where you must show who read or changed specific data
READ classSELECT and COPY from tables, views and sequences that match the configured scopeOften the largest contributor on read-heavy applicationsDemonstrating who viewed sensitive records; pair with object auditing to limit volume
WRITE classINSERT, UPDATE, DELETE, TRUNCATE and COPY to tablesModerate, driven by batch jobs and application write ratesEvidence of data changes for integrity investigations and change tracking
DDL classSchema changes such as CREATE, ALTER and DROP for database objectsLow on stable systems, spikes during deployments and migrationsChange control evidence; useful even when a team does not audit reads
ROLE classRole and privilege changes: CREATE ROLE, GRANT, REVOKE and similar statementsLow, but high in value for access reviewsAccess management evidence and detecting unexpected privilege escalation
FUNCTION classCalls to functions and DO blocksCan be high if applications call functions heavilyAuditing stored procedures that read or change regulated data inside the database
MISC classMiscellaneous statements such as DISCARD, FETCH, CHECKPOINT and SETCan be noisy for connection pooled or ORM-driven workloadsNarrow cases only; confirm the exact statement list for your pgAudit version before enabling
Bind parameters (pgaudit.log_parameter)Values passed to parameterized statements, which may include personal or account dataAdds size per statement and may increase exposure of sensitive values in logsForensic investigations that need the values used; check with privacy and security owners before enabling
Catalog access (pgaudit.log_catalog)Queries against system catalogs such as pg_class or pg_roles, often run by tools and driversCan be very high because clients and monitoring agents query catalogs constantlyRarely needed; enable only when an assessor or investigation specifically asks for schema discovery activity

Choosing session or object auditing by data sensitivity

Tables that hold personal health, financial or payment card data usually need the strongest audit coverage, because reviewers often ask who read or changed specific records, not only who connected. Object auditing fits best here: pgAudit logs statements that touch named tables or columns when the audit role is granted privileges on them, so the log stays focused on sensitive objects. Session auditing can add broad coverage for read and write classes if the team needs a full record for a regulated environment.

  • Audit mode: Start with object auditing on the tables that hold regulated fields, and add session classes only where the control requires broader capture.
  • Audited roles: Decide whether the audit role is a database role that applications and staff inherit, or whether it applies to every login, and document who can grant or revoke it.
  • Statement classes: Typically include READ and WRITE for sensitive objects, plus DDL and ROLE to record schema and privilege changes.
  • Coverage gaps: Test that queries through views, functions and bulk loads still generate entries, since privileges on base tables are what pgAudit checks.
  • Retention and access: Confirm with your compliance team how long entries must be kept and who may read them.

Before enabling this in production, run representative queries from each application and confirm the expected entries appear in the PostgreSQL log with the right object names.

How to roll out pgAudit without breaking production

The sequence moves pgAudit from an inventory of regulated databases to a logged, alerted and rollback-ready production setting. Each step produces an artifact the security, database and operations teams can review before the next one starts.

  1. Inventory regulated databases and roles

    The security or compliance lead lists every PostgreSQL cluster that holds regulated data, along with the application, administrator, batch and support roles that connect to it. The output is an inventory sheet that names each database, its owner, the roles with write or privileged access, and the audit questions the business must answer. Done means the database team and the compliance owner have both signed the inventory, so later logging choices trace back to a named requirement.

  2. Confirm the build matches the PostgreSQL major

    The database engineer checks the installed PostgreSQL major version against the pgAudit release built for that major, and confirms the package comes from a source your team trusts. Since the extension is compiled against PostgreSQL internals, a mismatch can stop the server from loading it, so the check is made on every server, including standbys and the copy used for testing. The output is a version record per host that shows the PostgreSQL build, the pgAudit build and the package source. Confirm the supported pairing with the pgAudit project documentation before you install.

  3. Set audit classes in a non-production copy

    The database engineer loads pgAudit in a restored, non-production copy of the regulated cluster and sets the audit classes that match the requirements from the inventory, such as read, write, DDL, role and function activity. Object-level auditing is configured only for specific sensitive tables, and the role-based settings are kept separate from session-wide settings so the scope is explicit. The output is a versioned configuration file, for example a postgresql.conf fragment and the CREATE EXTENSION and role grants, stored in version control with a short note explaining each class.

  4. Measure log volume and performance impact

    The team replays a representative workload against the test copy, once with auditing off and once with the agreed settings, and records log growth per hour, server CPU, I/O and the latency of the slowest application queries. The comparison shows which classes drive most of the volume and whether any hot path slows down beyond what the application owners accept. The output is a test report with both runs side by side and a list of classes or roles to narrow before production. Repeat the test whenever a class or role scope changes.

  5. Define log retention and file access

    The security team and database team agree how long raw PostgreSQL log files stay on the database host, where they are copied, who can read them, and how they are protected from modification. Access is limited to named service accounts and a small set of reviewers, and the rotation settings are tuned so log files are not lost before the forwarder reads them. The output is a logging runbook that records retention periods, file permissions, rotation settings and the people approved to read or change them. Confirm the retention period with your compliance owner, since it comes from your own obligations rather than from pgAudit.

  6. Wire the SIEM forwarder and parse rules

    The operations engineer configures the log forwarder to ship PostgreSQL and pgAudit entries to the SIEM over an encrypted, authenticated channel, then writes parse rules that split the audit records into fields such as user, database, statement class and object. Sample entries from the test copy are used to confirm every field is extracted and that multi-line statements are kept together. The output is the forwarder configuration, the parser definitions and a field mapping document, and the step is done when a test search returns each expected field for each class.

  7. Test alerts with planned events

    The security team runs a scripted set of planned events in the test environment, such as a new administrator role, a bulk read of a sensitive table, a schema change and a failed login, then confirms that each event appears in the SIEM and triggers the intended alert. Each alert is checked for false positives caused by normal batch jobs or application service accounts, and thresholds are adjusted where needed. The output is a test report listing every planned event, the expected alert, the observed result and the tuning changes, signed by the security owner.

  8. Enable in production with a rollback plan

    The change owner enables the approved configuration in production during a planned change window, starting with the least critical cluster and standbys handled according to the runbook. Before the change, the team records the current settings and writes a rollback procedure that restores the previous configuration and reloads or restarts the server as the change requires. Post-change checks compare log volume, forwarder lag and application latency against the test report. The output is the change record, the rollback runbook and a post-change review, and the step is complete when the owners accept the production baseline.

What drives pgAudit effort and log volume

This table lists the factors that change how much work a pgAudit rollout takes and how much log data it produces. Read each row as a lever: the driver on the left is what grows cost or volume, and the right column shows how to hold it down. The main takeaway is that scoping and a standard configuration template usually matter more than the extension itself.

DriverWhy it changes effort or volumeHow to keep it down
Number of databases and clustersEach cluster needs the extension installed, its settings reviewed, and its logs routed. Every major upgrade repeats this work for each cluster.Build one configuration template and apply it to every cluster through the same automation. Count clusters in the quote so the work is priced per cluster.
Number of roles and applications connectingService accounts that run high volumes of identical queries produce many log lines that carry little investigative value.Audit by role where possible, and exclude or minimize application service roles after confirming they do not touch regulated data.
Volume of regulated data flowing through statementsLogging read statements against tables holding cardholder, health or personal data creates the largest volume and the most sensitive log content.Scope object-level auditing to the tables and columns that hold regulated data, and keep session-wide logging to classes that answer specific questions.
Statement classes enabledLogging broad classes such as read and write for every database multiplies lines per transaction and increases storage and parsing load.Start from the classes your control requirements name, then add others only when a specific investigation or assessor question needs them.
SIEM parsing and field mappingAudit lines are free text unless the pipeline parses them. Each new field or format change needs a parser update and a test.Agree on the log format and field names once, keep the parser under version control, and test it against samples from each cluster.
Retention and storage requirementsRetention periods set how much data is kept hot in the SIEM and how much is archived. Longer periods raise storage and query cost.Confirm retention periods with the compliance owner and split hot search from low-cost archive, so only recent data sits in expensive storage.
Change control on configurationEach change to logging settings, role lists or filters needs review, testing and a record. Frequent ad hoc edits multiply that overhead.Keep settings in version-controlled templates, require review for each change, and limit who can alter audit configuration on the server.
Evidence artifacts for the compliance teamAssessors often ask for configuration exports, sample logs, change records and proof of review. Each artifact is extra collection and explanation work.Agree the evidence list before build starts, and automate exports of configuration and sample logs so they are produced on a schedule.

Matching the pgAudit build to your PostgreSQL major version

pgAudit is built against specific PostgreSQL major versions, so the extension package you install must match the major version of the server it loads into. A build for one major does not become valid on another because the minor number changed or the package installed without error. Before you install anything, record the exact major your cluster runs, confirm which pgAudit release the project lists for that major, and make the package version part of your deployment record alongside the server version. Because pgAudit loads as a shared library, a mismatch usually shows up at server start or when CREATE EXTENSION runs, so check both during the change window rather than assuming the package manager resolved correctly.

The PostgreSQL support window sets how long you can stay on a given pairing. According to the PostgreSQL versioning policy, supported majors today are 18, 17, 16, 15 and 14, and the end of life for PostgreSQL 14 falls on November 12, 2026. Once a major leaves support, the server stops receiving fixes, and an audit control that depends on it inherits that exposure. Plan the pgAudit move as part of the server move, not as a separate task you finish later. Minor releases keep the storage format unchanged, so routine patching usually means replacing executables and restarting, but a major upgrade means a new pgAudit build, a reinstall into the new server, and a test of the logging configuration against the new version.

Treat each major upgrade as a re-verification of your audit trail. After the upgrade, confirm that pgaudit.log still produces the statement classes you expect, that pgaudit.log_parameter and related settings behave as before, and that the entries reach your SIEM in the format your parsers and detection rules expect. Run the same test statements you used at go-live, and compare the output line by line. Before you schedule the upgrade, confirm with the pgAudit project which release supports your target major, whether any setting names or defaults changed, and any known issues for the version pair. Also confirm with your upgrade method, whether pg_upgrade or logical replication, how the extension is handled on the new cluster, since a restored or replicated database does not necessarily carry the same extension installation.

How pgAudit connects to the rest of your platform

pgAudit writes audit records inside PostgreSQL, but its value depends on the systems around it: the log pipeline, the upgrade and backup process, identity, file permissions, monitoring and evidence retention. Each card names the decision you need to settle with the team that owns that system before logging goes live.

SIEM and log shipper

pgAudit records appear in the PostgreSQL server log, so something must read, parse and forward them. Agree with the SIEM team on the shipper (for example, a forwarder your team already runs), the log format it expects, and the fields that must survive parsing, such as user, database, client address and statement class. Test with a sample session before the rule set is final, and confirm how the SIEM handles multi-line statements.

Upgrade and backup process

The pgAudit version must match the PostgreSQL major version, so every major upgrade needs a pgAudit package for the target release before the cutover. Hand the database team a written pin for the extension version, the shared_preload_libraries entry and the upgrade checklist. Restores from backup also need the same extension version, so confirm the backup tooling restores CREATE EXTENSION state and the library setting together.

Upgrade docs

Authentication and user identity

Audit entries are only useful if each session maps to a person. Shared application accounts hide who ran a statement, so agree with the identity team which PostgreSQL authentication method ties logins to directory identities, such as GSSAPI, LDAP, certificate or OAuth, and whether application users carry a name that identifies the caller. Confirm the mapping in pg_hba.conf before you rely on the audit trail.

Authentication methods

Access control for audit log files

Audit logs record SQL text, which can include personal data or secrets pasted into queries. Decide with the infrastructure team who can read, rotate and delete the log files on the database host, and set file ownership and mode so application accounts and the database service user cannot alter past entries. Confirm that forwarding copies are protected in transit and at rest with the same rules.

Monitoring for logging failures

A silent logging failure looks the same as a quiet database, so an audit gap can go unnoticed for weeks. Ask the monitoring team to alert when the shipper stops, when log files stop growing during business hours, or when the pgAudit setting is changed or the library fails to load after a restart. Test the alert by disabling the forwarder on a non-production host and confirming the page fires.

Retention and evidence processes

Your compliance owner decides how long audit records are kept, where they are stored and how an auditor will be given a sample. Agree the retention period, the archive location and a documented procedure for exporting a session's records with their timestamps and user mapping. DeployOpen prepares these controls and evidence for compliance assessments, but independent auditors and certification bodies issue any report.

What do buyers ask before hiring help with pgAudit?

What does pgAudit implementation cost and why does the price vary?

The cost follows the written scope, so no single figure applies to every environment. Most of the fee pays for analysis of which statement classes your compliance team needs, configuration across your PostgreSQL servers, the SIEM pipeline, and testing that logs arrive and stay readable. The main drivers are the number of clusters and databases, how many log sources the SIEM already ingests, whether you need object-level auditing on sensitive tables, and how much evidence your assessors will request. Ask for the quote to list each deliverable separately, state whether it is one-time or recurring, and name who runs log review and extension upgrades after handover. DeployOpen does not publish a price list.

How long does a pgAudit engagement take?

Duration depends on the number of PostgreSQL clusters, how settled your logging pipeline is, and how quickly your team can approve the audit policy. Work usually moves through four stages: agreeing the statement classes to capture, installing the extension at the correct version for each PostgreSQL major, connecting logs to the SIEM, and testing retention and alerting. Delays most often come from waiting on SIEM parser changes, change-approval windows, or a decision on whether logs include bound parameter values. Ask the provider to put dated milestones in the written scope and to name the dependencies your team owns.

What does our internal team need to provide?

Plan for your team to supply access and decisions rather than hands-on configuration alone. You will need administrative access to the database servers or the container images, a named owner for the audit policy, the SIEM administrator who can create parsers and retention rules, and a compliance contact who can confirm which events must be retained and for how long. You also need a change window for restarts, because loading the extension requires a server restart. Confirm these responsibilities in the scope so that the timeline does not wait on unassigned tasks.

Can a capable in-house team set up pgAudit alone?

Yes, a team with PostgreSQL and SIEM experience can install and configure pgAudit using the project documentation. The harder parts are not the settings themselves but matching the extension build to each PostgreSQL major version, deciding what to log without overwhelming the SIEM, and producing evidence that an assessor will accept. Teams that have not handled audit evidence before often find that the policy review and the test plan take longer than the installation. Outside help makes most sense when you need a second review of the policy, a documented test run, or a fixed deliverable before an assessment date.

How do you control log volume when auditing is enabled?

Log volume is controlled mainly through the choice of statement classes. The pgaudit.log setting determines which classes are recorded, such as DDL, ROLE, READ, WRITE, and MISC, and logging everything on a busy OLTP database produces the most data. Object auditing through pgaudit.role is more targeted but still needs a careful role design. Other levers include excluding low-risk service accounts where your policy allows, setting the SIEM to index only selected fields, and applying retention tiers so that older events move to cheaper storage. Ask the provider to measure log volume in a test environment before the production rollout and to document the settings chosen.

What happens to pgAudit during a PostgreSQL major upgrade?

The extension must be rebuilt or installed for the new PostgreSQL major version before the upgraded cluster starts, because the compiled module is tied to one major. Your upgrade plan should cover whether you use pg_upgrade or logical replication, then confirm that the pgAudit package and settings carry over and that audit events still reach the SIEM after cutover. Check the PostgreSQL versioning policy to see which majors are still supported, since an extension build for an unsupported release adds risk. Test the upgrade on a copy first and compare sample audit records before and after.

What should we ask for in a written pgAudit quote?

Ask for a scope that lists every cluster, database and SIEM in the work, the statement classes and object rules to be configured, and the exact log destinations and retention settings. The quote should name the deliverables, such as the configuration files, the SIEM parser or dashboard, the test record, and the runbook. It should also state what is outside scope, including ongoing log review, extension upgrades and changes to audit policy after handover. Confirm the acceptance criteria in writing so that both sides know when the work is complete. DeployOpen plans most engagements as fixed-scope work, with scope, deliverables and timelines agreed before work starts.

How DeployOpen scopes and delivers pgAudit audit logging

DeployOpen plans, builds and documents pgAudit audit logging on PostgreSQL inside infrastructure you control. The work starts with a written scope that names the statement classes, the PostgreSQL major version and the SIEM the logs will feed, so your security and compliance teams can review the design before anything is changed.

How we scope

  • Agree in writing which statement classes and object audit targets pgAudit will log, and why each one matters.
  • Confirm the PostgreSQL major version and the matching pgAudit build before any package or extension work begins.
  • Map where audit records will be stored, retained and forwarded to your SIEM, including who owns each step.

How we build

  • Install and configure pgAudit on a non-production cluster, then set session and object logging to the agreed rules.
  • Test log volume and content with representative workloads, and adjust filters so noisy statements do not bury useful events.
  • Ship the logs to your SIEM through the agreed pipeline and verify that events arrive with the fields your analysts need.

How we hand over

  • Deliver configuration files, parameter settings and version records, so your team can reproduce the setup on other clusters.
  • Document the runbook for changing logged classes, rotating logs and handling extension updates during PostgreSQL upgrades.
  • Provide the test evidence and a walkthrough with your platform and security engineers, so they can operate the setup without us.

How we support

  • Engagements are fixed-scope, with deliverables and timelines agreed in writing before work starts.
  • Ask for a retest of logging coverage after each PostgreSQL minor or major upgrade, and after any SIEM pipeline change.
  • Ongoing support, upgrades and continuous testing are available as a retainer, scoped to your clusters and audit needs.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.