0

I have a Java Spring project which does a lot of database reading. The database I have available is a shared postgresql database on a remote machine and it's quite slow to get data from it, especially when I'm doing a lot of back-and-forth.

When I'm doing local testing and development, I use the embedded H2 in-memory database. Things easily go 100 times faster.

This made me wonder. Is there a way to use the embedded H2 in-memory database so that:

  • Data manipulation (INSERT, UPDATE, DELETE) is ("eventually") replicated to the PostgreSQL database
  • Upon start/restart of the Spring project, the H2 database is automatically filled with the data of the PostgreSQL server

This would allow me to use the fast H2 to provide a seamless user experience while at the same time also storing the data in a longer-term data storage. In a way, I'd be using the H2 as a fully cached version of the PostgreSQL database.

Is there a known / standardized way to approach this? Google for H2 and PostgreSQL and replication gives me results on transitioning from one to the other, but I'm not finding much as to using one as a sort of cache for the other.

JayVeeInCorp
  • 144
  • 1
  • 3
  • 12

1 Answers1

0

I remain on the lookout for a Spring / JPA / Hibernate focused answer, but if none comes: I may have found an alternative domain to investigate. Dedicated database replication software might be able to manage this. Specifically, I've discovered SymmetricDS, which seems (I've only given the documentation a cursory glance) like it might be able to be embedded into my Spring application, do an initial load of my embedded in-memory H2 database on startup and then trickle feed data changes to the remote database.

(I'm not in any way affiliated with SymmetricDS, it just looks like it might be a solution.)

JayVeeInCorp
  • 144
  • 1
  • 3
  • 12