Add test coverage for the PostgreSQL storage backend

Add a test suite for the PostgreSQL storage backend and, as an added bonus, fix the bugs it has uncovered.