[#718] Try to avoid PL/pgSQL since we cannot guarantee that is is activated
[#642] Refactored datastore config to make it easier to understand and easier to test