Skip to main content
This feature requires the Enterprise plan.
pgconsole emits audit logs as JSON lines to stdout, allowing you to capture and process them with your existing log infrastructure.

Events

EventDescription
auth.loginUser login attempt (success or failure)
auth.logoutUser logout
sql.executeSQL query execution
data.exportData exported (e.g., CSV download)

Log Format

All audit events are JSON objects with a common structure:
{
  "type": "audit",
  "ts": "2024-01-15T10:30:45.123Z",
  "action": "...",
  "actor": "[email protected]"
}

Common Fields

FieldDescription
typeAlways "audit"
tsISO 8601 timestamp
actionEvent type
actorUsername or email

auth.login

{
  "type": "audit",
  "ts": "2024-01-15T10:30:45.123Z",
  "action": "auth.login",
  "actor": "[email protected]",
  "provider": "google",
  "ip": "192.168.1.100",
  "success": true
}
FieldDescription
providerAuth provider (basic, google, keycloak)
ipClient IP address
successWhether login succeeded
errorError message (if failed)

auth.logout

{
  "type": "audit",
  "ts": "2024-01-15T10:35:00.000Z",
  "action": "auth.logout",
  "actor": "[email protected]"
}

sql.execute

{
  "type": "audit",
  "ts": "2024-01-15T10:32:15.456Z",
  "action": "sql.execute",
  "actor": "[email protected]",
  "connection": "prod-db",
  "database": "postgres",
  "sql": "SELECT * FROM users WHERE active = true",
  "success": true,
  "duration_ms": 45,
  "row_count": 150
}
FieldDescription
connectionConnection ID
databaseDatabase name
sqlFull SQL query text
successWhether query succeeded
duration_msExecution time in milliseconds
row_countNumber of rows returned (optional)
errorError message (if failed)

data.export

{
  "type": "audit",
  "ts": "2024-01-15T10:33:00.000Z",
  "action": "data.export",
  "actor": "[email protected]",
  "connection": "prod-db",
  "database": "postgres",
  "sql": "SELECT * FROM users WHERE active = true",
  "row_count": 150,
  "format": "csv"
}
FieldDescription
connectionConnection ID
databaseDatabase name
sqlSQL query that produced the exported data
row_countNumber of rows exported
formatExport format (csv)

Capturing Logs

Audit logs are written to stdout alongside other server output. Filter by "type":"audit" to capture audit events only:
# Filter and write to file
# --line-buffered: flush output after each line for real-time logging
pgconsole | grep --line-buffered '"type":"audit"' >> audit.log

# Parse and forward to log aggregator
# --unbuffered: disable jq's output buffering for real-time streaming
pgconsole | jq --unbuffered -c 'select(.type == "audit")' | nc logserver 5000