Search & Analysis

Querying Audit Logs

Search and analyze billions of audit events with powerful filtering, aggregations, and export capabilities.

Event Schema

Every audit event captured by DB Audit follows a consistent schema. Understanding these fields helps you write effective queries.

FieldTypeDescription
idstringUnique event identifier
typestringEvent type (e.g., database.query, security.threat_detected)
timestampdatetimeWhen the event occurred (ISO 8601)
database_idstringDatabase identifier
database_namestringHuman-readable database name
userstringDatabase user who performed the action
operationstringSQL operation (SELECT, INSERT, UPDATE, DELETE, etc.)
querystringThe SQL query (may be masked for sensitive data)
query_hashstringHash of the normalized query for pattern matching
source_ipstringClient IP address
source_hoststringClient hostname (if resolved)
duration_msnumberQuery execution time in milliseconds
rows_affectednumberNumber of rows affected by the query
severitystringEvent severity: info, warning, critical
classificationarrayData classification tags (PII, financial, etc.)
policy_matchesarrayList of matched audit policy IDs
geoobjectGeolocation data (country, city, coordinates)
session_idstringDatabase session identifier
applicationstringClient application name (if available)

Query Examples

Basic Time-Based Search

Search for events within a specific time range using the Events API.

# Search for events in the last 24 hours
GET /v1/events?
  start_date=2025-01-14T00:00:00Z&
  end_date=2025-01-15T00:00:00Z

Filter by Database and User

Narrow down results to specific databases and users.

# Filter by database and user
GET /v1/events?
  database_id=db_production&
  user=app_service&
  limit=100

Search SQL Patterns

Find events containing specific SQL patterns.

# Search for specific SQL patterns
GET /v1/events?
  query_contains=DELETE FROM users&
  severity=high

Advanced Queries

Complex Filtering

Use the search endpoint for complex queries with multiple conditions, wildcards, and sorting.

# Complex filter with multiple conditions
POST /v1/events/search
{
  "filters": {
    "databases": ["db_prod_*"],
    "users": ["admin", "dba_*"],
    "operations": ["DELETE", "DROP", "TRUNCATE"],
    "time_range": {
      "start": "2025-01-01T00:00:00Z",
      "end": "2025-01-15T23:59:59Z"
    }
  },
  "sort": {
    "field": "timestamp",
    "order": "desc"
  },
  "pagination": {
    "limit": 50,
    "offset": 0
  }
}

Aggregations

Group and aggregate events for analytics and reporting.

# Aggregate events by user and operation
POST /v1/events/aggregate
{
  "group_by": ["user", "operation"],
  "metrics": ["count", "avg_duration"],
  "filters": {
    "time_range": {
      "start": "2025-01-01T00:00:00Z",
      "end": "2025-01-15T23:59:59Z"
    }
  }
}

# Response
{
  "results": [
    {
      "user": "app_service",
      "operation": "SELECT",
      "count": 1542890,
      "avg_duration_ms": 12.5
    },
    {
      "user": "admin",
      "operation": "UPDATE",
      "count": 3421,
      "avg_duration_ms": 45.2
    }
  ]
}

Dashboard Metrics

Retrieve multiple metrics in a single request for dashboards.

# Query for dashboard metrics
POST /v1/events/metrics
{
  "metrics": [
    {
      "name": "events_by_severity",
      "type": "count",
      "group_by": "severity"
    },
    {
      "name": "events_over_time",
      "type": "timeseries",
      "interval": "1h",
      "aggregation": "count"
    },
    {
      "name": "top_users",
      "type": "top_n",
      "field": "user",
      "limit": 10
    }
  ],
  "time_range": {
    "start": "2025-01-14T00:00:00Z",
    "end": "2025-01-15T00:00:00Z"
  }
}

Filter Operators

DB Audit supports a rich set of filter operators for precise queries.

OperatorDescriptionExample
eqEquals"user": {"eq": "admin"}
neNot equals"operation": {"ne": "SELECT"}
inIn list"severity": {"in": ["critical", "high"]}
containsString contains"query": {"contains": "users"}
starts_withString starts with"user": {"starts_with": "app_"}
regexRegular expression match"query": {"regex": "DROP.*TABLE"}
gtGreater than"rows_affected": {"gt": 1000}
gteGreater than or equal"duration_ms": {"gte": 100}
ltLess than"rows_affected": {"lt": 10}
lteLess than or equal"duration_ms": {"lte": 50}
existsField exists/is not null"geo.country": {"exists": true}

Exporting Logs

Export audit logs for external analysis, compliance reporting, or archival. Supports CSV, JSON, and Parquet formats.

CSV Export

Human-readable format for spreadsheets and basic analysis.

JSON Export

Structured format for programmatic processing and SIEM ingestion.

Parquet Export

Columnar format optimized for big data analytics tools.

# Export logs to CSV
POST /v1/events/export
{
  "format": "csv",
  "filters": {
    "time_range": {
      "start": "2025-01-01T00:00:00Z",
      "end": "2025-01-31T23:59:59Z"
    },
    "severity": ["critical", "high"]
  },
  "fields": [
    "timestamp",
    "database_name",
    "user",
    "operation",
    "query",
    "source_ip",
    "severity"
  ],
  "delivery": {
    "method": "email",
    "recipients": ["security@company.com"]
  }
}

Data Retention & Storage Tiers

DB Audit uses tiered storage to balance query performance with cost efficiency. Recent data is instantly searchable, while older data is archived for compliance.

H

Hot Storage

7 days

Full-text search, instant queries, real-time dashboards

W

Warm Storage

30 days

Indexed search, sub-second queries

C

Cold Storage

1 year

Archived storage, minutes to query

G

Glacier Storage

7 years

Compliance archive, hours to retrieve

Custom Retention

Enterprise plans can customize retention periods to meet specific compliance requirements (e.g., 10-year retention for SOX).