Test postgres

Also fixes bugs that prevented tests from passing.