Skip to content
verticalbarHQPublic

About

PostgreSQL extension for database-native object-centric process mining and accelerated OCEL analytics.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

37 Commits

Folders and files

pg_ocpm

pg_ocpm is a PostgreSQL extension for object-centric process mining (OCPM). It provides a source-neutral relational model and query primitives for events, directly-follows edges, object adjacency, case summaries, provenance, cached facets, and duration statistics.

The extension defines a normalized, source-neutral ocpm schema.

Why pg_ocpm

OCPM queries often repeat expensive derivations such as building object adjacency, reconstructing variants, and aggregating edge durations. pg_ocpm compacts those reusable facts into exact columnar buckets, rollups, and versioned adjacency capsules. Native operators filter the compact payloads without materializing one PostgreSQL tuple per fact.

The extension uses PostgreSQL's normal MVCC and WAL behavior. It does not add a custom table or index access method.

Current extension version: 1.0.0. See the release notes and academic implementation provenance. OCPA, Rust4PM, and PM4Py are isolated as benchmark references under the production dependency boundary. OCPQ appears only in archived benchmark results; no OCPQ benchmark code is supplied.

Compatibility

pg_ocpm is built and smoke-tested on PostgreSQL 13, 14, 15, 16, 17, and 18.

Build requirements

  • PostgreSQL 13–18
  • A C compiler and PostgreSQL server development headers
  • GNU Make

Authorized binary customers should use the versioned Debian/RPM packages or private OCI images documented in docs/private-distribution.md. pg_ocpm is not distributed through pip or npm because installation is tied to the server's PostgreSQL major version and system extension directories.

Install from source

The complete installation guide, covering prebuilt binary packages, Docker, source builds, enabling the extension, and upgrades, is in INSTALL.md.

make
make install

Installing into a system PostgreSQL directory may require sudo make install. If multiple PostgreSQL versions are installed, select one explicitly:

make PG_CONFIG=/path/to/pg_config
make PG_CONFIG=/path/to/pg_config install

Then enable the extension in a database:

CREATE EXTENSION pg_ocpm;
SELECT ocpm.version();

Exact DFG and complete-variant sufficient statistics can be computed over any set of aligned, lifecycle-contained windows without exporting event or case-ID rows:

SELECT *
FROM ocpm.lifecycle_dfg_window_counts(
    42, 7,
    ARRAY['2026-01-01', '2026-02-01']::timestamptz[],
    ARRAY['2026-01-31', '2026-02-28']::timestamptz[],
    ARRAY['Order']
);

SELECT *
FROM ocpm.lifecycle_variant_window_counts(
    42, 7,
    ARRAY['2026-01-01', '2026-02-01']::timestamptz[],
    ARRAY['2026-01-31', '2026-02-28']::timestamptz[],
    ARRAY['Order']
);

Both APIs support arbitrary caller-supplied windows and filters, accept at most 256 windows per invocation, and use PostgreSQL grouping and work_mem rather than a dataset-specific result cache.

Cases that are fully contained in an inclusive time window can be exported as ordered event rows without SQL array expansion, joins, or event-level sorting:

SELECT case_id, activity, event_timestamp, event_ordinal
FROM ocpm.event_log_rows(
    42,
    7,
    'Order',
    '2026-01-01 00:00:00+00',
    '2026-02-01 00:00:00+00'
);

event_ordinal is one-based and preserves the finalized per-case order, including deterministic order when events share a timestamp. The function reuses ocpm.case_bucket and adds no table, projection, or index.

Dataframe clients should use the factorized interface to avoid transferring one PostgreSQL tuple per event:

SELECT activity_path, activity_count, case_count,
       case_id_payloads, event_timestamp_payloads
FROM ocpm.event_log_batches(
    42,
    7,
    'Order',
    '2026-01-01 00:00:00+00',
    '2026-02-01 00:00:00+00'
);

Each result row represents at most one physical case-bucket segment. activity_path is a normalized one-dimensional text[]; every ID in case_id_payloads follows that path. The case payload contains case_count native-endian signed 64-bit IDs. event_timestamp_payloads concatenates one self-describing vector per case in the same order. Each timestamp vector contains a native-endian 32-bit activity count followed by that many native-endian signed 64-bit PostgreSQL timestamps (microseconds from 2000-01-01 UTC). A remote client can detect the server byte order by decoding the first timestamp-vector count in both orders and selecting the one equal to activity_count, then apply that order to both payloads. This representation is storage-neutral and preserves finalized per-case ordering without event-row sorting. PostgreSQL reads source buckets through a 32-row SPI portal and writes results to a work_mem-backed tuplestore. Peak backend request memory is therefore bounded by the current source chunk, one output bucket, and PostgreSQL's tuplestore budget rather than the complete result.

Training/evaluation and period-comparison clients can pass aligned timestamp arrays to scan the compact case buckets once for multiple windows:

SELECT window_ordinal, activity_path, activity_count, case_count,
       case_id_payloads, event_timestamp_payloads
FROM ocpm.event_log_window_batches(
    42,
    7,
    'Order',
    ARRAY['2026-01-01 00:00:00+00',
          '2026-02-01 00:00:00+00']::timestamptz[],
    ARRAY['2026-01-31 23:59:59.999999+00',
          '2026-02-28 23:59:59.999999+00']::timestamptz[]
);

window_ordinal is the one-based position in the input arrays. Overlapping windows deliberately return a matching case in every applicable window. An interval index avoids scanning every case against every sparse window. One call accepts at most 256 windows; chunk larger sets across calls. examples/pm4py_event_batches.py provides a validated NumPy/Pandas adapter that performs one output allocation pass before calling the installed PM4Py version and iterates DB-API results incrementally. For large remote results, supply a driver-level server-side cursor as well so the database driver does not buffer the result at execute().

Run with Docker

Build an image containing vanilla PostgreSQL 16 and only pg_ocpm:

docker build -t pg_ocpm:local .
docker run --name pg_ocpm \
  -e POSTGRES_PASSWORD=postgres \
  -p 5432:5432 \
  -d pg_ocpm:local

After PostgreSQL is ready:

docker exec pg_ocpm psql -U postgres \
  -c 'CREATE EXTENSION pg_ocpm; SELECT ocpm.version();'

Select another supported PostgreSQL major with PG_MAJOR:

docker build --build-arg PG_MAJOR=18 -t pg_ocpm:pg18 .

Data model

Register a logical dataset before loading normalized facts:

SELECT ocpm.register_dataset(
    'production_processes',
    1,
    '{"source":"erp"}'::jsonb
);

Load normalized facts into these relations:

  • ocpm.event_fact: typed object-centric events with activity, timestamp, actor, context, source attributes, and an optional first-class event_id. A logical event that references multiple objects must use the same event_id on every corresponding object row. The legacy numeric attributes.event_key field remains accepted for existing loaders.
  • ocpm.edge_fact: directly-follows and cross-object edges.
  • ocpm.link_adjacency: bidirectional, time-aware object adjacency.
  • ocpm.case_summary: case windows, variants, paths, and activity sets.

ocpm.finish_load(dataset_id) transforms the load rows into the serving relations:

  • ocpm.event_chunk and offset-aware ocpm.event_locator rows for object timelines.
  • ocpm.event_activity_rollup for exact activity/time counts.
  • ocpm.edge_bucket for directly-follows and duration queries.
  • ocpm.link_adjacency_bucket stores exact dictionary- and delta-encoded adjacency capsules; ocpm.link_adjacency_rollup serves aggregate adjacency queries.
  • ocpm.case_bucket for case, variant, and activity-set filters.

The remaining general-purpose relations are:

  • ocpm.provenance_fact: generic source-change provenance.
  • ocpm.result_cache: watermark-aware cached facets for stable filter sets.

Finalization preserves exact timestamps and identifiers, empties the row-wise load buffers, refreshes planner statistics, records the source watermark, and returns logical row counts. It rebuilds the small serving indexes by default; pass p_compact_indexes => false when the extra table locks are unacceptable. Any optional binding index is invalidated by finalization and must be rebuilt afterward with the workload declaration it should serve. Binding summaries require every finalized event to have a stable logical identity. Finalization reports event_identity_complete; ocpm.rebuild_binding_index(...) refuses a non-empty event dataset when that value is false, preventing ambiguous rows from being joined through the historical case_id storage fallback.

See docs/performance.md for the architectural cost model and docs/technical-performance-improvements.md for a code-referenced explanation of every optimization over vanilla relational PostgreSQL.

Query primitives

Find cases under dynamic time, status, variant, and activity filters:

SELECT ocpm.case_candidates(
    dataset_id,
    tenant_id,
    backbone_type,
    from_timestamp,
    to_timestamp,
    status,
    variant_hashes,
    included_activities,
    excluded_activities
);

Additional primitives include:

  • ocpm.connected_objects(...) for traversal over persisted adjacency.
  • ocpm.connected_objects_one_hop(...) and ocpm.connected_objects_closure(...) for bounded application query shapes.
  • ocpm.adjacency_neighborhood(...) and ocpm.adjacency_links(...) for exact native filtering and decoding of versioned adjacency capsules.
  • ocpm.adjacency_selected_ids(...) for vectorized expansion of selected backbone cases.
  • ocpm.edge_duration_stats(...) for filtered edge-duration statistics.
  • ocpm.rework_counts(...) for exact per-transition multiplicity, unique-case, repeated-case, excess-transition, and maximum-occurrence counts.
  • ocpm.dfg_counts(...) and ocpm.variant_counts(...) for filtered aggregate interfaces without event or case-row hydration.
  • ocpm.dfg_window_counts(...) and ocpm.variant_window_counts(...) for aligned counts across arbitrary training, test, comparison, or drift windows in one native aggregate state.
  • ocpm.activity_profile(...) for filtered case frequency, occurrence frequency, and start/end activity frequency from compact case capsules.
  • ocpm.rebuild_binding_index(...) for workload-declared object types, activities, typed-neighbor summaries, and optional directed relation constraints. The one-argument overload indexes all object types and activities but deliberately creates no neighbor or relation vectors. Every overload fails closed when stored events lack validated logical event IDs. The six-argument overload orders its inputs as (dataset_id, object_types, activities, event_universe_activities, neighbor_specs, relation_specs) so event-to-object constraints do not require global vectors for unrelated activities; earlier overloads remain callable and use their activity selection as the event-universe selection.
  • ocpm.binding_object_activity_count(...), ocpm.binding_requires_activity(...), ocpm.binding_event_object_count(...), ocpm.binding_neighbor_eventually(...), ocpm.binding_neighbor_actor_equal(...), ocpm.binding_max_activity_delay(...), and ocpm.binding_neighbor_pairs(...) for generic binding and constraint operations over those summaries.
  • ocpm.binding_ids(...), ocpm.binding_same_object_event_pairs(...), and ocpm.binding_neighbor_event_pairs(...) for compact complete child-node output without tuple-at-a-time SQL materialization. Temporal-pair bounds are inclusive microseconds of target time minus source time; a negative maximum means unbounded.
  • ocpm.binding_relation_universal_equal(...) and ocpm.binding_relation_children(...) for request-time evaluation of an opt-in packed directed relation. Target bindings are distinct from their related-object memberships, so a target with multiple related objects is emitted once and a target with no related object remains a violated child. Duplicate source bindings are preserved, sources without a target binding are omitted, and declared empty tenant/spec combinations return valid empty capsules. The low-level five-array OCPR v1 pack overload remains available for universal-equality compatibility, but child expansion rejects it because that historical format never encoded target object or event identifiers.
  • ocpm.binding_capsule_rows(...) for exact SQL expansion of versioned native result capsules when a row representation is required.
  • ocpm.edge_feature_aggregates(...) for count, mean, range, sample deviation, threshold count, and threshold-rate sufficient statistics.
  • ocpm.edge_duration_time_series(...) for exact caller-defined time buckets with count, mean, range, median, and sample deviation.
  • ocpm.duration_stats(value) for exact count, mean, minimum, maximum, median, sample standard deviation, and coefficient of variation.
  • ocpm.time_series_json(...) and ocpm.process_map_summary(...) for native time-series and process-map aggregation over compact buckets.
  • ocpm.cache_get(...) and ocpm.cache_put(...) for watermark-safe results.

Design invariants

  • Dataset and tenant identifiers lead every serving index.
  • Reverse adjacency retains the original source and target timestamps.
  • Dynamic time predicates are reapplied when adjacency is read.
  • Adjacency payloads carry a magic value and format version and reject malformed, truncated, or unsupported data.
  • Cached results are keyed by a canonical filter hash and source watermark.
  • Load buffers are removed after successful compaction to avoid storing the same logical facts twice.
  • Binding summaries are opt-in and workload-declared; finalization never performs an unbounded all-neighbor expansion.
  • Relation declarations are directed from source_object_type to target_object_type; each declared object-type and activity name is bounded to 256 database-encoded bytes so the compact lookup key remains portable across all supported PostgreSQL majors.

Test

The test suite performs a clean extension install, validates registration, filtered case selection, duration statistics, capsule encoding and decoding, adjacency traversal, cache watermarks, and load finalization, then verifies in-place upgrades from 0.2.0 through 1.0.0:

./scripts/test-docker.sh

Run the same test against a specific supported PostgreSQL major:

PG_MAJOR=13 ./scripts/test-docker.sh
PG_MAJOR=18 ./scripts/test-docker.sh

CI runs the suite on every PostgreSQL major from 13 through 18.

Benchmark status

Immutable end-to-end release evidence that includes ocpm-engine, result transfer, and result materialization is owned by the ocpm-engine benchmark suite. This repository keeps extension correctness tests and the pg_ocpm 1.0 release notes. The SAP runner in benchmarks/sap_pm4py_export.py imports the pinned owning suite's fixtures and fixed PM4Py workloads rather than maintaining divergent dataset or algorithm definitions.

The older in-repository SAP tables and machine-readable artifact were withdrawn because their measurement protocol was superseded. See docs/benchmarks.md for benchmark ownership and the requirements that corrected comparisons must satisfy.

The clean 1.0 Docker run shows a 1.338x geometric-mean end-to-end latency improvement over vanilla PostgreSQL with fixed PM4Py across eight SAP O2C/P2P workloads and a 102.5 MiB serving schema versus vanilla's 125.3 MiB. On the OCPQ fixture, pg_ocpm improves the unchanged PM4Py evaluator by 1.456x; pg_ocpm plus ocpm-engine is 16.137x faster than OCPQ 0.6.7 in the strict all-node same-host result. The complete four-arm OCPQ table is in docs/ocpq-benchmark-comparison.md.

License and contributions

Copyright 2026 Vertical Bar, Inc..

Licensed under the Apache License, Version 2.0. The Apache license permits commercial use and redistribution subject to its terms. It does not grant trademark rights or support obligations. See NOTICE and third-party notices.

Contributions require the applicable Contributor License Agreement, which allows Vertical Bar, Inc. to keep the public project Apache-2.0 and offer separately licensed commercial editions.

See governance, the code of conduct, security policy, and first public-release strategy.

About

PostgreSQL extension for database-native object-centric process mining and accelerated OCEL analytics.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages