# Ehrbase Performance Issue

**URL:** <https://discourse.openehr.org/t/ehrbase-performance-issue/11953>\
**Category:** Platform\
**Tags:** ehrbase\
**Created:** [15 April 2026 05:39 UTC](https://discourse.openehr.org/t/ehrbase-performance-issue/11953 "2026-04-15T05:39:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mancini](https://discourse.openehr.org/user_avatar/discourse.openehr.org/mancini/32/2002_2.png) [@Mancini](https://discourse.openehr.org/u/Mancini)\
**Post date:** [15 April 2026 05:39 UTC](https://discourse.openehr.org/t/ehrbase-performance-issue/11953/1 "2026-04-15T05:39:22Z")

</div>

We are using EHRbase (v2.5) in production with approximately **150 GB of clinical data**.  
**Infrastructure  
EHRbase (Kubernetes):**

- Replicas: 3

- CPU: 2–4 cores per pod

- Memory: 4–16 GB per pod

**Database:**

- CPU: 8 cores

Our data model includes relatively standard lab-related archetypes:

- `openEHR-EHR-OBSERVATION.laboratory_test_result.v1`

- `openEHR-EHR-CLUSTER.specimen.v1`

- `openEHR-EHR-CLUSTER.laboratory_test_analyte.v1`

## Use Case

We are executing a **cohort-style AQL query** to retrieve:

- Lab tests conducted for a given day

- Corresponding test results

- Associated specimen details

Essentially, this is a **time-filtered query (single day)** over lab observations with related clusters.

Problem is Even when querying for **a single day** , the response time is very high ~20 min.

Are there known optimizations or indexing strategies in EHRbase/PostgreSQL for improving performance of such AQL queries.

PS:

> select e/ehr\_id/value as ehr\_id, c/uid/value as composition\_id, c/name/value as template\_id, c1/items[at0001]/value/value as case\_id, o1/data[at0001]/events[at0002]/data[at0003]/items[at0005]/value/value as test\_name, o1/data[at0001]/events[at0002]/data[at0003]/items[at0005]/value/defining\_code/code\_string as test\_name\_code, o1/data[at0001]/events[at0002]/data[at0003]/items[at0005]/value/defining\_code/terminology\_id/value as test\_name\_codesystem, o1/data[at0001]/events[at0002]/data[at0003]/items[at0073]/value/value as overal\_test\_status from EHR e CONTAINS COMPOSITION c[openEHR-EHR-COMPOSITION.report.v1] CONTAINS OBSERVATION o1[openEHR-EHR-OBSERVATION.laboratory\_test\_result.v1] AND CLUSTER c1[openEHR-EHR-CLUSTER.case\_identification.v0] WHERE c/archetype\_details/template\_id/value=‘lab\_report\_template.en.v0’ AND c/context/start\_time/value\>=‘2026-04-01’ AND c/context/start\_time/value\<=‘2026-04-02’

---

<div class="post-metadata">

**Author:** ![vidi42](https://discourse.openehr.org/user_avatar/discourse.openehr.org/vidi42/32/2609_2.png) [@vidi42](https://discourse.openehr.org/u/vidi42)\
**Post date:** [17 April 2026 10:36 UTC](https://discourse.openehr.org/t/ehrbase-performance-issue/11953/2 "2026-04-17T10:36:42Z")

</div>

@Mancini before thinking of indexes at the DB level, I want to mention some options:

1. (tip) When comparing `start_time`, use the time object in comparisons instead of `/value`, so `c/context/start_time>"2026-04-01"`
2. I see in your projections that you are reusing a common path `o1/data[at0001]/events[at0002]/data[at0003]`, maybe think of extracting it in a contains if this still fulfills your needs
3. Split this into 2 queries: one that only handles the retrieval of composition IDs that match your criteria, and another one that does the projections

For more dedicated support you can reach out to me in DMs

---

<div class="post-metadata">

**Author:** ![Mancini](https://discourse.openehr.org/user_avatar/discourse.openehr.org/mancini/32/2002_2.png) [@Mancini](https://discourse.openehr.org/u/Mancini)\
**Post date:** [20 April 2026 09:49 UTC](https://discourse.openehr.org/t/ehrbase-performance-issue/11953/3 "2026-04-20T09:49:28Z")

</div>

Thanks @vidi42
