Postgres migration

This merges the latest code from the CfA repo, and includes SMC-specific changes.