Selecting some TV shows in library takes a long time when clicked and eventually returns an "Uh Oh"

When selecting a TV show in the library, some shows won’t display the details page (where you can then select the season and then episode). There is just a blank screen and eventually it returns an “Uh Oh…” message saying somethings not right, and check that the plex server is available and try again. Trying again makes no difference. Other shows work fine. It seems to be on TV shows with a large number of episodes.

The console shows an error as follows:
Held transaction for too long (D:\gha\plex-media-server\plex-media-server\Statistics\StatisticsManager.cpp:284): 0.109375 seconds

Same happens from search results too for the same shows.

I seem to have fixed this problem. Did a Database Optimization and now shows that were not working are ok.