Reworked API cleanContext psql sub-process execution (closes #4261)