Resolve #132: Fix some issues with the Postgres backend.
This does a lot of the work needed for #120.