# EhrBase DB schema definition

**URL:** https://discourse.openehr.org/t/ehrbase-db-schema-definition/4249
**Category:** Platform
**Tags:** ehrbase
**Created:** [17 July 2023 19:17 UTC](https://discourse.openehr.org/t/ehrbase-db-schema-definition/4249 "2023-07-17T19:17:16Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![thomas.beale](https://discourse.openehr.org/user_avatar/discourse.openehr.org/thomas.beale/32/35_2.png) [@thomas.beale](https://discourse.openehr.org/u/thomas.beale)
#### Post date: [17 July 2023 19:17 UTC](https://discourse.openehr.org/t/ehrbase-db-schema-definition/4249/1 "2023-07-17T19:17:16Z")

</div>

I was trying to find the DB schema definition for Postgres in EhrBase in the EhrBase code base . So far I have not found it - can anyone provide a pointer? Ping @birger.haarbrandt

---

<div class="post-metadata">

### Author: ![borut.jures](https://discourse.openehr.org/user_avatar/discourse.openehr.org/borut.jures/32/1391_2.png) [@borut.jures](https://discourse.openehr.org/u/borut.jures)
#### Post date: [17 July 2023 19:37 UTC](https://discourse.openehr.org/t/ehrbase-db-schema-definition/4249/2 "2023-07-17T19:37:38Z")

</div>

Is this the right folder?

> <https://github.com/ehrbase/ehrbase/tree/develop/base/src/main/resources/db/migration>
>
> //github.com/ehrbase/ehrbase/tree/develop/base/src/main/resources/db/migration

---

<div class="post-metadata">

### Author: ![birger.haarbrandt](https://discourse.openehr.org/user_avatar/discourse.openehr.org/birger.haarbrandt/32/24_2.png) [@birger.haarbrandt](https://discourse.openehr.org/u/birger.haarbrandt)
#### Post date: [18 July 2023 06:21 UTC](https://discourse.openehr.org/t/ehrbase-db-schema-definition/4249/3 "2023-07-18T06:21:58Z")

</div>

yap, that’s correct

---

<div class="post-metadata">

### Author: ![thomas.beale](https://discourse.openehr.org/user_avatar/discourse.openehr.org/thomas.beale/32/35_2.png) [@thomas.beale](https://discourse.openehr.org/u/thomas.beale)
#### Post date: [18 July 2023 23:21 UTC](https://discourse.openehr.org/t/ehrbase-db-schema-definition/4249/4 "2023-07-18T23:21:33Z")

</div>

Is there a DB schema / ER diagram or similar available? The reason I am looking at this is to consider how a ‘standard RDBMS’ schema could be derived from an RM. My supposition is that this is via a transform of the RM to a simplified model that is optimised for RDBMS persistence, e.g certain fields stringified, maybe some inheritance simpification, and so on.

---

<div class="post-metadata">

### Author: ![pablo](https://discourse.openehr.org/user_avatar/discourse.openehr.org/pablo/32/3505_2.png) [@pablo](https://discourse.openehr.org/u/pablo)
#### Post date: [19 July 2023 01:09 UTC](https://discourse.openehr.org/t/ehrbase-db-schema-definition/4249/5 "2023-07-19T01:09:55Z")

</div>

Generally speaking, all those techniques are used if the DBMS is relational. For instance, denormalization is applied to avoid the cost of too many joins, resulting in sparse tables, or multiple table inheritance vs. single table inheritance, depending on the case (it’s also about joins vs. sparse tables). Also small structures might get serialized as a single string column. I also simplify the OBJECT\_REFs, most of the times as FKs, and other tricks. I did that analysis back in 2011-2013 while designing EHRServer, even testing XML and JSON databases. After that designed the “Design and Implementation of Clinical Databases with openEHR” course, that basically shows all those techniques and where can be applied.

About EHRBASE specifically, the only thing I know is everything is normalized but the content, which is saved as native JSON columns in Postgres, then AQL is translated to SQL which contains parts that query inside the JSON structure. Then there are some history columns for the locatables that are versioned, to store the older versions. In EHRServer and Atomik we don’t have those history tables, everything is stored in the same tables and there is an is\_last flag for quick access to the last version.

That’s another thing: on RDBMS we also add stuff that is not part of the RM that we use to speed up queries or simplify some use cases, like storing different forms of paths to query and reconstruct data when retrieving.

Hope that helps.

---

<div class="post-metadata">

### Author: ![birger.haarbrandt](https://discourse.openehr.org/user_avatar/discourse.openehr.org/birger.haarbrandt/32/24_2.png) [@birger.haarbrandt](https://discourse.openehr.org/u/birger.haarbrandt)
#### Post date: [5 March 2025 10:11 UTC](https://discourse.openehr.org/t/ehrbase-db-schema-definition/4249/7 "2025-03-05T10:11:43Z")

</div>

Another bot? I did not dare to follow the link. Maybe @marcusbaw can remove.

---

<div class="post-metadata">

### Author: ![Koray\_Atalag](https://discourse.openehr.org/user_avatar/discourse.openehr.org/koray_atalag/32/70_2.png) [@Koray\_Atalag](https://discourse.openehr.org/u/Koray_Atalag)
#### Post date: [6 March 2025 11:02 UTC](https://discourse.openehr.org/t/ehrbase-db-schema-definition/4249/8 "2025-03-06T11:02:29Z")

</div>

Hi Tom,  
Here’s the schema/EER diagram. I used pgadmin4 tool to generate it. It’s a fully fledged RDMS management tool and if you want to play with it I can create a user account for you. Please DM me.

I have a working EHRbase instance on AWS and pgadmin4 connected.  
I wrote a comprehensive guide to install and configure EHRbase - [HERE](https://openehr.atlassian.net/wiki/external/ODIzZGIwMjA2MjhhNDNiOTg4OWJlNTAzY2U3ZTZmZjc)

Enjoy!

 ![EHRbase-DB_Schema(Koray)](https://discourse.openehr.org/uploads/default/original/2X/b/b86d175dc404e5de287375d6042bdbe8dcea6526.png)  
@thomas.beale

---

<div class="post-metadata">

### Author: ![borut.jures](https://discourse.openehr.org/user_avatar/discourse.openehr.org/borut.jures/32/1391_2.png) [@borut.jures](https://discourse.openehr.org/u/borut.jures)
#### Post date: [11 March 2025 15:51 UTC](https://discourse.openehr.org/t/ehrbase-db-schema-definition/4249/9 "2025-03-11T15:51:08Z")

</div>

Thank you for this diagram @Koray_Atalag 👏

I noticed that the table names are missing (only 👁 is shown). Is there a setting in pgadmin4 to show the names?

---

<div class="post-metadata">

### Author: ![thomas.beale](https://discourse.openehr.org/user_avatar/discourse.openehr.org/thomas.beale/32/35_2.png) [@thomas.beale](https://discourse.openehr.org/u/thomas.beale)
#### Post date: [11 March 2025 18:41 UTC](https://discourse.openehr.org/t/ehrbase-db-schema-definition/4249/10 "2025-03-11T18:41:20Z")

</div>

Thanks Koray - any chance you can do what @borut.jures said?

---

<div class="post-metadata">

### Author: ![birger.haarbrandt](https://discourse.openehr.org/user_avatar/discourse.openehr.org/birger.haarbrandt/32/24_2.png) [@birger.haarbrandt](https://discourse.openehr.org/u/birger.haarbrandt)
#### Post date: [11 March 2025 20:53 UTC](https://discourse.openehr.org/t/ehrbase-db-schema-definition/4249/11 "2025-03-11T20:53:11Z")

</div>

The table name is there right below the schema name “ehr”

---

<div class="post-metadata">

### Author: ![borut.jures](https://discourse.openehr.org/user_avatar/discourse.openehr.org/borut.jures/32/1391_2.png) [@borut.jures](https://discourse.openehr.org/u/borut.jures)
#### Post date: [11 March 2025 21:19 UTC](https://discourse.openehr.org/t/ehrbase-db-schema-definition/4249/12 "2025-03-11T21:19:16Z")

</div>

Thank you @birger.haarbrandt. The shaded header row looks so “unused”. It is there that the name is usually displayed. I should have looked better.

Sorry @Koray_Atalag for missing the table names in your diagram.

---

<div class="post-metadata">

### Author: ![Koray\_Atalag](https://discourse.openehr.org/user_avatar/discourse.openehr.org/koray_atalag/32/70_2.png) [@Koray\_Atalag](https://discourse.openehr.org/u/Koray_Atalag)
#### Post date: [11 March 2025 22:01 UTC](https://discourse.openehr.org/t/ehrbase-db-schema-definition/4249/13 "2025-03-11T22:01:07Z")

</div>

Non worries @borut.jures I had the same impression when I first generated it.

---

<div class="post-metadata">

### Author: ![borut.jures](https://discourse.openehr.org/user_avatar/discourse.openehr.org/borut.jures/32/1391_2.png) [@borut.jures](https://discourse.openehr.org/u/borut.jures)
#### Post date: [26 April 2025 12:46 UTC](https://discourse.openehr.org/t/ehrbase-db-schema-definition/4249/14 "2025-04-26T12:46:12Z")

</div>

A diagram generated with IntelliJ (intersections have little “jumps” to make it easier to follow the lines):

 ![EHRbase DB schema v2 - 2025-04-26 - light](https://discourse.openehr.org/uploads/default/original/2X/7/73896a0cd545eececca30f5590851d9624c5f15e.jpeg)
