Cloudanix Joins AWS ISV Accelerate Program

What Is Database Audit Logging? Who Ran What, and How to Prove It

Database audit logging records who connected, which queries they ran and what changed. Learn what to log, native limits, retention and how to meet audit needs.

Database audit logging is the practice of recording who connected to a database, what they ran, what data was affected, and when. A good audit log lets you answer, after the fact, questions such as “who exported the customer table last Tuesday?” and “which account changed this schema?” with evidence instead of guesses.

Audit logging is easy to confuse with ordinary operational logging, and the difference matters. A server log tells an engineer why the database is slow or why a connection failed. An audit log is a security and compliance record: it is meant to be complete, tamper-resistant, attributable to a person and kept for as long as your obligations require.

This page explains what an audit log should contain, the limits of native database logging, how to configure the basics, how long to keep records, what regulators and auditors expect, and where a dedicated query-level audit layer fits.

What a useful audit record contains

For each event, you need enough to reconstruct what happened without relying on memory.

FieldWhy it matters
Timestamp (with time zone)Orders events and supports investigation windows
Who (the named person or service, not a shared role)Attribution is the whole point of an audit log
Source (client address, application, tool)Distinguishes a production application from a laptop
Session or connection identifierLinks statements that belong together
Statement (the query text or its normalized form)Shows what was attempted
Target (database, schema, table, sometimes columns)Shows which data was touched
Outcome (success, failure, error)Failed attempts are often the first sign of misuse
Volume (rows returned or changed)Separates a lookup from a bulk export
Why (a ticket or approval reference)Ties the access to a reason of record

If a record lacks the “who,” it is a log. If it has the “who,” the “what” and the “which data,” it is an audit trail.

Events worth capturing

  • Connections and disconnections, including failed logins
  • Privilege and role changes, such as grants, revokes and new users
  • Schema changes (DDL), such as creating, altering or dropping objects
  • Reads of sensitive data, such as queries against tables that hold personal or financial information
  • Writes and deletes on important tables
  • Administrative actions, such as configuration changes and extension installs
  • Bulk operations, such as large exports or COPY

Capturing every statement from every application can be expensive and noisy. A sensible approach is to log everything for human and administrative access, and to be selective for high-volume application traffic.

What native database logging gives you

Every major database engine can write some form of log. The detail varies.

  • Connection and statement logging. PostgreSQL, for example, can log connections, disconnections and statements by setting parameters such as log_connections, log_disconnections and log_statement. See the PostgreSQL logging documentation.
  • Audit extensions. The pgAudit extension adds session and object-level audit logging for PostgreSQL. MySQL and SQL Server have their own audit features, and managed cloud databases expose audit options through the provider.
  • Cloud-level logs. Managed services also log control-plane actions, such as who changed a database’s configuration. In AWS this goes to CloudTrail.

A starting configuration for PostgreSQL:

-- See current settings
SHOW log_connections;
SHOW log_disconnections;
SHOW log_statement;

-- Log connections, disconnections and schema-changing statements
ALTER SYSTEM SET log_connections = 'on';
ALTER SYSTEM SET log_disconnections = 'on';
ALTER SYSTEM SET log_statement = 'ddl';
SELECT pg_reload_conf();

Use 'mod' to include data-changing statements, or 'all' to log everything, bearing in mind the volume and the fact that statement text can contain sensitive values. See secret redaction in logs.

The limits of native logging

Native logs are a good floor, but they leave important gaps.

  • Shared accounts hide the person. If five engineers connect as the same role, the log shows the role. It cannot say which engineer ran the query.
  • Reads are often not logged by default. Turning on full statement logging helps, and it produces large volumes that are hard to search.
  • They record that a query ran, not what came back. You may see the statement without knowing how many rows were returned or whether sensitive columns were included.
  • They live on the database host. Someone who gains control of the server can alter or delete them. Logs must be shipped elsewhere quickly.
  • They do not mask or block. A log tells you about a harmful query after it ran.
  • Formats differ per engine. Each database has a different format, so a multi-database estate needs normalization.
  • Statement text can leak secrets. A query with a literal password or card number writes that value into the log.

None of this means native logging is wrong. It means it is the foundation, not the whole answer.

Protecting the audit log itself

An audit log is only useful if it can be trusted.

  • Ship it off the database host in near real time to a separate store.
  • Make it append-only or write-once where possible, for example object storage with retention locks.
  • Restrict who can read and who can delete. Administrators of the database should not be the only people able to erase its audit trail.
  • Time-synchronize servers so events line up across systems.
  • Monitor the logging itself. Alert if logging stops or the volume drops sharply.
  • Protect sensitive content. Logs can hold personal data, so apply access controls and retention limits to them too.

How long to keep audit logs

Retention depends on the frameworks and contracts that apply to you. Common requirements include:

  • PCI DSS requires audit trail history to be retained for at least a year, with a recent period immediately available for analysis.
  • HIPAA requires documentation relevant to security compliance to be kept for six years. Organizations often keep audit records on a similar schedule.
  • SOC 2 and ISO 27001 do not set a number, and expect you to define and follow a retention policy appropriate to your commitments.

Check the current text of each requirement and confirm it with your auditor, because interpretations differ. As a practical matter, keep recent data in searchable storage and move older data to cheaper, immutable storage.

What auditors typically ask

  • Who has access to the production database, and who approved it?
  • Can you show every access to this sensitive table in the last 90 days?
  • Can you show that access was removed when someone left or changed roles?
  • Who changed this schema or this permission, and when?
  • How do you know the log is complete and unaltered?

The most common failure is not a missing log. It is an inability to connect a database action to an approved request and a named person. See closing the audit trail gap.

Query-level audit and database activity monitoring

Database activity monitoring (DAM) is the next step beyond native logs. A DAM layer sits in the path of each query and records it with the identity of the person, the statement, the outcome and often the volume, in one searchable place. It can also enforce rules before the query runs and mask sensitive values in the result. See database activity monitoring, DSPM vs DAM and our explainer on how DAM differs from native database logging.

A practical checklist

  • Every human connection is tied to a named person, not a shared account
  • Connections, privilege changes and schema changes are logged
  • Reads of sensitive tables are captured
  • Logs are shipped off the database host in near real time
  • Logs are immutable or access-restricted, with monitoring for gaps
  • Retention is defined and matches your obligations
  • Statement text is checked for secrets and personal data
  • You can link a query to an approved request or ticket
  • You have tested a real question, such as “who read this table last month?”

How Cloudanix helps

Cloudanix addresses the gaps that native logging leaves: attribution, query-level detail and keeping the record in your own environment.

  • Access that names the person. Database JIT gives people keyless, identity-stamped access to PostgreSQL, MySQL, MariaDB, SQL Server and CosmosDB, with no shared passwords. Each request, approval, session and revocation is logged with the real person’s identity to storage you own.
  • Query-level audit. Database Access Management (DAM) is an add-on to Database JIT. It runs as a query proxy inside your own environment. For PostgreSQL, MySQL and MSSQL, it logs every query with full state and metadata to your storage, where it is queryable and searchable. It can also block risky operations through guardrails and mask sensitive values by role. DAM requires Database JIT and cannot be bought on its own.
  • Evidence for audits. See query-level audit evidence for ISO 27001 and SOC 2 and query-level audit and PII masking for MySQL databases.
  • Your data stays with you. The proxy and the logs live in your infrastructure. See data-sovereign DAM.

Be clear about scope: Cloudanix does not replace the audit settings in your database engine, and it does not supply retention policy. You define what must be kept and for how long.

Further reading

Frequently asked questions

What is database audit logging?

It is the recording of who connected to a database, what they ran and what data was affected, kept in a form that supports security investigation and compliance.

What is the difference between audit logs and regular database logs?

Regular logs help engineers operate the database. Audit logs are a security record that is complete, attributable to a person, protected from tampering and retained to meet policy and regulation.

Does PostgreSQL have built-in audit logging?

It has configurable logging of connections and statements. The pgAudit extension adds more detailed session and object audit logging. Neither replaces attribution of shared accounts.

How do I know who ran a query if everyone shares one account?

You often cannot from native logs alone. Give each person their own identity when they connect, or use an access layer that stamps each session with the person behind it.

How long should database audit logs be kept?

It depends on your obligations. PCI DSS expects at least a year of audit trail history, and HIPAA expects six years for related documentation. Confirm with your auditor and set a written policy.

People Also Read

What Our Users Are Saying

Customer Reviews

Cloudanix is trusted by security leaders worldwide to deliver proactive, reliable, and cutting-edge cloud security.

One day, I changed the password of a root account, and my CTO called me within less than a minute to confirm if I did so. I was not expecting a reaction this quick. He told me Cloudanix alerted him of this password change and that he wanted to confirm as it was a critical security notification. I couldn't believe it!

Ritesh Agarwal
Ritesh Agarwal
CEO, Airgap Networks

Compliance is one way of staying secure, but what I want is the ability to go deeper and attain 'true security.' Cloudanix provides us the capability to do so.

Vishal Madan
Vishal Madan
Head of Engineering, iMocha

Cloudanix is building for the future of the cloud, which makes the product all the more desirable.

Ritesh Agarwal
Ritesh Agarwal
CEO, Airgap Networks

Cloudanix gave us the visibility we were missing. Being able to move from permanent access to a robust Just-In-Time (JIT) workflow has fundamentally changed our security posture without slowing down our engineering velocity.

Pavan Kumar Lekkala
Pavan Kumar Lekkala
SRE Lead, HugoHub

We are excited to leverage Cloudanix's comprehensive multi-cloud DevSecOps solution to secure our production workloads on AWS. Cloudanix has demonstrated that it can solve many challenges that DevSecOps teams face while continually adding new features such as SOC2 compliance and drift detection.

Satish Mohan
Satish Mohan
Co-founder & CTO, Airgap Networks

Managing third-party partner access was once a major concern for our security posture. With Cloudanix JIT Cloud, we've effectively achieved zero third-party risk. We can now grant access confidently, knowing that it is temporary, audited, and automatically revoked, resulting in a 100% reduction in our privileged access exposure.

Okesh Badhiye
Okesh Badhiye
Head of Technical Engineering, Finfinity

The snooze feature and responsible alerts have helped us save time and prioritize what to tackle first.

Satish Mohan
Satish Mohan
Co-founder & CTO, Airgap Networks

Implementing Cloudanix JIT internally allowed us to practice what we preach. By eliminating permanent access to our own clouds and databases, we've neutralized the risk of standing privileges, ensuring our own 'keys to the kingdom' are never left exposed.

Girish Manghnani
Girish Manghnani
Managing Partner, Tech Inspira

The problem with permissions is a lot of times, the gaps are left open due to oversights from inside the organization itself. With Cloudanix's CIEM, we get a complete view of user permissions and access. This enables us to update the permissions, reducing the attack surface.

Nilesh Pethani
Nilesh Pethani
Application Architect, iMocha

In the world of Fintech, trust is our currency. Cloudanix provided the frictionless visibility we needed to secure our EKS workloads across AWS, ensuring we stay audit-ready for SOC2 and GDPR without slowing down our engineering velocity.

Amol Naik
Amol Naik
Head of Security & Infrastructure, HugoHub

Cloudanix delivered value within 5 minutes of onboarding. Continuous monitoring, timely detection, and excellent documentation helped us attain a great cloud security posture.

Divyanshu Shukla
Senior DevSecOps, Meesho

Technology strategies and business strategies are in a state of constant change which includes centralization and decentralization of responsibilities. Regardless of strategic shift, we still have intellectual property to protect. Cloudanix are critical partners for us in our public cloud security posture across our three cloud providers.

Jerry Locke
Jerry Locke
Senior Director Global Solutions Engineering, Eversana

Cloudanix has been amazing. They opened up a common Slack channel with us — and it feels like we are talking to our own team and getting things done with Cloud security. The support team is always available, friendly, helpful, and ready to go out of their way.

Satish Mohan
Satish Mohan
CTO, Airgap Networks

Beyond just access management, Cloudanix CSPM has given us a unified view of our AWS environment. The real-time alerting and anomaly detection allow us to prevent any untoward activity before it happens, which is critical for a marketplace connecting 50+ financial institutions.

Okesh Badhiye
Okesh Badhiye
Head of Technical Engineering, Finfinity

For a Fintech company, data is our most valuable — and most sensitive — asset. Cloudanix DAM hasn't just improved our visibility; it has given us control. The ability to mask data and prevent unauthorized queries in real-time is a game-changer for our compliance and customer trust.

Jiten Gala
Jiten Gala
President Engineering and Product, Kapittx

Our clients, especially in the Middle East financial sector, demand absolute accountability. Cloudanix JIT Cloud has been a competitive differentiator for us, allowing us to provide secure, governed access to customer accounts that meet their strictest audit and compliance requirements.

Girish Manghnani
Girish Manghnani
Managing Partner, Tech Inspira

Cloudanix is always on my team's lips because of its exceptional support. Be it a small or big query, Cloudanix has gone above and beyond to resolve them. This one's a keeper for us.

Sujit Karpe
Sujit Karpe
CTO, iMocha

For a long-lasting partnership, great support goes a long way. Cloudanix has delivered exceptional support whenever required. Their edge is their team is always ready to go beyond to solve any issues that we have. This speaks volumes about the culture at Cloudanix.

Akash Maheshwari
Akash Maheshwari
Co-founder, MoveInSync

Beyond the technology, Cloudanix feels like an extension of our own team. Their willingness to stand up a dedicated Middle East tenant for us and provide exceptional support at a sensible price makes them a long-term partner for Hugosave.

Surya Tamada
Surya Tamada
CTO, HugoHub

The real-time notifications that Cloudanix provides are a real lifesaver. Their adaptive notifications ensure that my team stays productive and doesn't get interrupted all the time.

Digvijay Singh
Staff Security Engineer, Meesho

The whole point in technological evolution is to help improve the world we live in. We must protect that and to do so requires an effective and efficient security strategy. The Cloudanix team helped make our public cloud security posture management strategy a reality. The symbiotic relationship we have allows for a continuous feedback loop which is how business should operate.

Larry Wheat
Larry Wheat
Staff Solutions Engineer, Eversana

Ready to see your graph?

Connect a cloud account in under 30 minutes. See every finding rooted in identity, asset, and blast radius — with a fix path attached.

Book a Demo