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

The exit code from the psql sub-process was not correctly reported.