1374 datastore use temp table

related to #1374, not sure if it's the root cause of it or if it's just another bug masking another one. I've changed the _read_connection_has_correct_priviliges function to use one connection instead of two(a read and a write) just to use the write connection and to execute the privileges test using the read connection user as a parameter to the postgres function has_table_privilege() that we get from the read url. I'm using a temporary table as well so that different processes should not interfere with each other. Did a little refactoring as well.