Thanks for your guidance, very interesting.
I also use postgressql, to be more precise Timescale db. But I have created two separate databases. One for the recorder, which contains only the last 3 days. So the logbook and other functions within HA are more performant imho.
For the long term storage of states I use ltss cusom component to analyze the data with graphana or python afterwards. Custom component: Long Time State Storage (LTSS) utilizing TimescaleDB