Enable auditing / logging
Oracle
-- Unified Auditing (12c+):
CREATE AUDIT POLICY table_audit
ACTIONS SELECT, INSERT, UPDATE, DELETE ON hr.employees;
AUDIT POLICY table_audit;
-- Monitoring: SELECT * FROM unified_audit_trail ORDER BY event_timestamp DESC;With Unified Auditing, a policy is created and enabled with AUDIT; records are kept in the unified_audit_trail view.
PostgreSQL
-- pgaudit extension (recommended; first shared_preload_libraries = 'pgaudit' + restart + CREATE EXTENSION pgaudit):
ALTER SYSTEM SET pgaudit.log = 'write, ddl';
SELECT pg_reload_conf();
-- Simple built-in method:
ALTER SYSTEM SET log_statement = 'ddl';
SELECT pg_reload_conf();pgaudit provides detailed audit logging; set it with ALTER SYSTEM to apply server-wide (a session-level SET audits only that session). Without the extension, basic logging is enabled with log_statement ('ddl','mod','all'). Watch the log volume.
MySQL
-- Enterprise/MariaDB audit plugin:
INSTALL PLUGIN audit_log SONAME 'audit_log.so';
SET GLOBAL audit_log_policy = 'ALL';
-- Simple alternative (all queries):
SET GLOBAL general_log = 'ON';The audit_log plugin (Enterprise, or server_audit in MariaDB) keeps a detailed audit trail; general_log logs all queries but degrades performance.
SQL Server
USE master;
CREATE SERVER AUDIT Audit_A TO FILE (FILEPATH = 'C:\\audit\\');
ALTER SERVER AUDIT Audit_A WITH (STATE = ON);
USE mydb;
CREATE DATABASE AUDIT SPECIFICATION db_spec
FOR SERVER AUDIT Audit_A
ADD (SELECT, INSERT, UPDATE, DELETE ON SCHEMA::dbo BY public)
WITH (STATE = ON);First create and enable a SERVER AUDIT target (file/event log), then define which events to track with a server or database AUDIT SPECIFICATION.
MongoDB
# MongoDB Enterprise / Atlas only. Configuration (mongod.conf):
# auditLog:
# destination: file
# format: JSON
# path: /var/log/mongodb/audit.json
# filter: '{ atype: { $in: ["authCheck","createCollection","dropCollection"] } }'
# mongod --auditDestination file --auditPath /var/log/mongodb/audit.jsonAuditing is available only in Enterprise and Atlas; it is enabled with the auditLog section of the mongod configuration. It does not exist in the Community edition.
Redis
ACL LOG
# Shows rejected authentication/command/key access attempts.
# To reset: ACL LOG RESET
# For general command auditing: an external proxy or MONITOR (with care).ACL LOG automatically records security events (failed authentication, unauthorized commands/keys); full command auditing is not built in.
Elasticsearch
# elasticsearch.yml (on all nodes, restart required):
xpack.security.audit.enabled: true
# Optional event filter:
xpack.security.audit.logfile.events.include: [ "authentication_failed", "access_denied" ]Audit logging is enabled with xpack.security.audit.enabled; it is set in elasticsearch.yml and requires a node restart (it is not dynamic). Requires a commercial license.