Tests for BZ-1022910 (postgresql and HT task instance retrieval)
(cherry picked from commit 9326f32ff1966eae45f8a66d8cd17a25f5924a96)