DataSunrise Achieves AWS DevOps Competency Status in AWS DevSecOps and Monitoring, Logging, Performance

Database Audit in YugabyteDB

Introduction

In today’s digital landscape, implementing robust database audit trails is crucial for maintaining security and compliance in database operations. Moreover, YugabyteDB, a distributed SQL database, offers built-in capabilities for tracking database activities. At the same time, it supports enhanced monitoring through third-party solutions.

Native Audit Capabilities in YugabyteDB

YugabyteDB utilizes the PostgreSQL Audit Extension (pgaudit) to provide comprehensive audit logging. This integration, therefore, enables detailed session and object audit logging through YB-TServer logging, which is essential for meeting various compliance requirements.

Setting Up Native Audit Logging

To enable audit logging in YugabyteDB, administrators can configure several approaches. Below are the key steps for setup:

  1. Cluster Startup Configuration – You can configure audit logging using YB-TServer flags. For example:

    --ysql_pg_conf_csv="pgaudit.log='all, -misc',pgaudit.log_parameter=on,pgaudit.log_relation=on"
  2. Enable pgaudit Extension – In your YSQL session, you can create the extension with the following command:

    CREATE EXTENSION IF NOT EXISTS pgaudit;
  3. Configure Audit Logging Parameters – Set specific audit logging options. For instance:

    -- Enable DDL logging
    SET pgaudit.log = 'DDL';
    
    -- Log parameters with statements
    SET pgaudit.log_parameter = ON;
    
    -- Enable client-side logging
    SET pgaudit.log_client = ON;
    SET pgaudit.log_level = notice;

Sample Native Audit Log Output Examples

Once pgaudit is configured and active, YugabyteDB logs key activities to the YB-TServer logs. These logs can then be parsed or viewed using monitoring tools. Below are two sample output table examples that demonstrate typical audit log entries:

Example 1: General Activity Log

This table captures a variety of operations (SELECT, INSERT, UPDATE, DELETE) across different sessions.

Log TimeUserDatabaseSession IDCommandObject TypeObject NameDetails
2025-02-11 10:15:23adminyugadb8a1b2c3dSELECTtablecustomer_dataExecuted SELECT on table customer_data
2025-02-11 10:17:45adminyugadb8a1b2c3dINSERTtableordersInserted a new order record
2025-02-11 10:20:11analystyugadbd4e5f6g7UPDATEtableordersUpdated order status to ‘shipped’
2025-02-11 10:22:05analystyugadbd4e5f6g7DELETEtableobsolete_dataDeleted record with id 123

Example 2: Detailed DDL and Write Operations Log

This output is focused on Data Definition Language (DDL) and data-modification operations, including extra parameters and relation details as configured with pgaudit. Here are some sample entries:

Log TimeUserDatabaseSession IDCommandObject TypeObject NameQuery Parameters
2025-02-11 11:05:10dbayugadbf7g8h9i0CREATEtablesensitive_dataCREATE TABLE sensitive_data ( … )
2025-02-11 11:06:50dbayugadbf7g8h9i0ALTERtablesensitive_dataALTER TABLE sensitive_data ADD COLUMN …
2025-02-11 11:10:32app_useryugadbj1k2l3m4INSERTtablesensitive_dataINSERT INTO sensitive_data (username, email, …)
2025-02-11 11:15:44app_useryugadbj1k2l3m4UPDATEtablesensitive_dataUPDATE sensitive_data SET email = ‘…’ WHERE …

Advanced Auditing with Detailed Examples

Comprehensive Audit Rule Example

-- Create a sample table to audit
CREATE TABLE sensitive_data (
    user_id SERIAL PRIMARY KEY,
    username TEXT,
    email TEXT,
    credit_card_last4 TEXT
);

-- Configure extensive auditing
SET pgaudit.log = 'all';
SET pgaudit.log_parameter = ON;
SET pgaudit.log_relation = ON;

-- Perform some sample operations
INSERT INTO sensitive_data (username, email, credit_card_last4) 
VALUES ('johndoe', '[email protected]', '1234');

UPDATE sensitive_data 
SET email = '[email protected]' 
WHERE username = 'johndoe';

Enhanced Auditing with DataSunrise

While native capabilities provide basic auditing, DataSunrise’s database activity monitoring solution offers advanced features specifically designed for distributed databases like YugabyteDB. Thus, it provides a more comprehensive solution.

DataSunrise proxy managing multiple database connections

Key Features:

DataSunrise Session Trails hub allows you to manage ongoing connections to YugabyteDB

Best Practices for YugabyteDB Auditing

  1. Performance Optimization – In order to optimize performance, it is crucial to implement selective audit rules. For instance:
    • Use targeted logging configurations
    • Monitor the system’s performance impact
    -- Example of selective logging
    SET pgaudit.log = 'DDL, WRITE';  -- Only log DDL and write operations
    SET pgaudit.log_catalog = OFF;   -- Reduce noise from system catalog logs
  2. Security Considerations – Additionally, it is important to protect audit logs, implement granular access controls, and regularly review and rotate logs. These measures are essential for maintaining the security of your audit data.

Conclusion

In conclusion, effective database auditing in YugabyteDB requires a balanced approach between native capabilities and enhanced solutions. While native pgaudit provides essential logging features, organizations with complex compliance requirements may greatly benefit from the advanced monitoring and security features offered by specialized solutions like DataSunrise.

For more information about implementing comprehensive database auditing in YugabyteDB, consult the YugabyteDB security documentation.

If you want to learn more about comprehensive database audit in YugabyteDB with DataSunrise, we highly recommend scheduling our online demo or downloading the tool to explore it yourself.

Next

Data Audit for Hydra

Learn More

Need Our Support Team Help?

Our experts will be glad to answer your questions.

General information:
[email protected]
Customer Service and Technical Support:
support.datasunrise.com
Partnership and Alliance Inquiries:
[email protected]