drop schema current_user cascade;
Native PostgreSQL Schema Script: postgres-audit.sql
This page documents schema objects parsed from config/sql/native/postgres-audit.sql.
Naming conventions:
-
M_prefix is used for tables in main part of the repo,MA_for audit tables (can be separate) Constraints/indexes use table_column(s)_suffix convention, withPKfor primary key,FKforeign key,IDXfor index,KEYfor unique index.TRis suffix for triggers. -
Names are generally lowercase (despite prefix/suffixes above in uppercase ;-)).
-
Column names are Java style and match attribute names from M-classes (e.g. MAuditEvent).
Other notes:
-
TEXTis used instead ofVARCHAR, see: DBA stackexchange -
Public schema is not used as of now, everything is in the current user schema. See secure schema usage pattern in PostgreSQL documentation.
-
Just in case CURRENT_USER schema was dropped (fastest way to remove all midpoint objects)
Tables
m_global_metadata
Stores internal audit schema metadata, including audit schema change tracking.
Columns
| Column | Type | Required / constraints | Description |
|---|---|---|---|
|
|
primary key, required |
Metadata entry name. |
|
|
Metadata entry value. |
ma_audit_delta
Stores serialized object deltas and related object information for audit events.
Columns
| Column | Type | Required / constraints | Description |
|---|---|---|---|
|
|
primary key, required |
Identifier of the audit event this delta belongs to. |
|
|
primary key, required |
Timestamp of the audit event this delta belongs to. Also used as partitioning key. |
|
|
primary key, required |
Checksum identifying this delta within the audit event. |
|
|
Serialized delta data. |
|
|
|
OID of the object affected by this delta. |
|
|
|
Type of change represented by this delta. |
|
|
|
Serialized full operation result related to this delta. |
|
|
|
Normalized name of the affected object. |
|
|
|
Original name of the affected object. |
|
|
|
OID of the affected resource, if the delta is resource-related. |
|
|
|
Normalized name of the affected resource. |
|
|
|
Original name of the affected resource. |
|
|
|
Kind of shadow affected by the delta, if applicable. |
|
|
|
Shadow intent affected by the delta, if applicable. |
|
|
|
Result status related to this delta. |
ma_audit_delta_default
Default partition for audit deltas that do not match a monthly audit delta partition.
No primary key is defined for this table.
This table is a partition of ma_audit_delta. Columns are inherited from the partitioned table.
Foreign keys
| Column | References | Notes |
|---|---|---|
|
ON DELETE CASCADE |
|
|
ON DELETE CASCADE |
ma_audit_event
Stores top-level audit event records, such as object changes, task actions, sessions, and other audited operations.
XSD type: http://midpoint.evolveum.com/xml/ns/public/common/audit-3#AuditEventRecordType
Columns
| Column | Type | Required / constraints | Description |
|---|---|---|---|
|
|
primary key, required |
Numeric identifier of the audit event. Together with timestamp it forms the primary key. |
|
|
primary key, required |
Time when the audited event happened. This is also the partitioning key. |
|
|
External or logical identifier of the audit event. |
|
|
|
Type of audited operation, for example object add, modify, delete, or session creation. |
|
|
|
Stage of the audited operation, such as request, execution, or resource. |
|
|
|
Session identifier associated with the audited operation. |
|
|
|
Request identifier associated with the audited operation. |
|
|
|
Task identifier associated with the audited operation. |
|
|
|
OID of the task associated with the audited operation. |
|
|
|
Host identifier where the audited operation was processed. |
|
|
|
Cluster node identifier where the audited operation was processed. |
|
|
|
Remote host address from which the operation originated, if known. |
|
|
|
OID of the principal that initiated the audited operation. |
|
|
|
Object type of the initiator. |
|
|
|
Human-readable name of the initiator. |
|
|
|
OID of the attorney when the operation was executed under delegation or attorney context. |
|
|
|
Human-readable name of the attorney. |
|
|
|
OID of the effective principal used to evaluate permissions. |
|
|
|
Object type of the effective principal. |
|
|
|
Human-readable name of the effective principal. |
|
|
|
Describes whether effective privileges were elevated, reduced, or otherwise changed. |
|
|
|
OID of the primary target object of the audited operation. |
|
|
|
Object type of the primary target. |
|
|
|
Human-readable name of the primary target. |
|
|
|
OID of the owner of the primary target, if applicable. |
|
|
|
Object type of the target owner, if applicable. |
|
|
|
Human-readable name of the target owner, if applicable. |
|
|
|
Full channel URI describing where or how the operation was initiated. |
|
|
|
Result status of the audited operation. |
|
|
|
Operation parameter summary stored with the audit event. |
|
|
|
Operation result summary stored with the audit event. |
|
|
|
User-friendly audit event message. |
|
|
|
Paths of changed items affected by the audited operation. |
|
|
|
OIDs of resources affected by the audited operation. |
|
|
|
Additional audit event properties stored as structured JSON. |
Indexes
| Name | Columns | Purpose / notes |
|---|---|---|
|
|
Speeds up searching and ordering audit events by timestamp. Used for: audit searches filtered or ordered by event time |
|
|
Speeds up lookup of audit events by event identifier. Used for: audit searches using eventIdentifier |
|
|
Speeds up lookup of audit events by session identifier. Used for: audit searches grouped or filtered by user session |
|
|
Speeds up lookup of audit events by request identifier. Used for: audit searches following one logical request |
|
|
Speeds up lookup of audit events by target object OID. Used for: audit searches for events related to a specific object |
|
|
Speeds up searches by changed item paths. Used for: audit searches filtering by changed item |
|
|
Speeds up searches by affected resource OIDs. Used for: audit searches filtering by resource |
|
|
Speeds up searches by structured audit event properties. Used for: audit searches filtering by JSON properties |
ma_audit_event_default
Default partition for audit events that do not match a monthly audit event partition.
No primary key is defined for this table.
This table is a partition of ma_audit_event. Columns are inherited from the partitioned table.
ma_audit_ref
Stores references related to audit events.
Columns
| Column | Type | Required / constraints | Description |
|---|---|---|---|
|
|
primary key, required |
Technical identifier of this audit reference row. |
|
|
required |
Identifier of the audit event this reference belongs to. |
|
|
primary key, required |
Timestamp of the audit event this reference belongs to. Also used as partitioning key. |
|
|
Reference name. Multiple references in one audit event can have the same name. |
|
|
|
OID of the referenced target object. |
|
|
|
Type of the referenced target object. |
|
|
|
Original name of the referenced target object. |
|
|
|
Normalized name of the referenced target object. |
Indexes
| Name | Columns | Purpose / notes |
|---|---|---|
|
|
Speeds up lookup of audit references by owning audit event. Used for: joining audit references to audit events |
ma_audit_ref_default
Default partition for audit references that do not match a monthly audit reference partition.
No primary key is defined for this table.
This table is a partition of ma_audit_ref. Columns are inherited from the partitioned table.
Foreign keys
| Column | References | Notes |
|---|---|---|
|
ON DELETE CASCADE |
|
|
ON DELETE CASCADE |
Enum types
Enum types define allowed database values for selected columns.
Functions and procedures
Functions and procedures implement repository-side database behavior.
apply_audit_change
Applies an audit schema or data change only once by tracking the latest executed audit change number.
Kind: procedure
audit_create_monthly_partitions
Creates monthly audit table partitions for audit events, deltas, and references.
| Only default partitions are created in this script! Consider, whether you need partitioning before doing anything, for more read the docs: Partitioning |
Use something like this, if you desire monthly partitioning:
call audit_create_monthly_partitions(120);
This creates 120 monthly partitions into the future (10 years). It can be safely called multiple times, so you can run it again anytime in the future. If you forget to run, audit events will go to default partition so no data is lost, however it may be complicated to organize it into proper partitions after the fact.
Create past partitions if needed, e.g. for migration. E.g., for last 12 months (including current):
call audit_create_monthly_partitions(-12);
Check the existing partitions with this SQL query:
select inhrelid::regclass as partition
from pg_inherits
where inhparent = 'ma_audit_event'::regclass;
Try this to see recent audit events with the real table where they are stored:
select tableoid::regclass::text AS table_name, *
from ma_audit_event
order by id desc
limit 50;
Kind: procedure
Procedural blocks
Procedural blocks run repository-side setup logic that is documented as a whole.
do-block-1
Creates shared audit enum types when they are not already present.
Statement type: DO block
Used for: audit schema initialization
do-block-2
Creates the shadow kind enum type for standalone audit databases when it is not already present.
Statement type: DO block
Used for: audit schema initialization
Extensions and schemas
Extensions and schemas are database infrastructure objects required by the repository schema.
Schema CURRENT_USER
Creates the current user’s schema used by the native audit repository.