Postgres migration

Merge latest code from CfA upstream repo and add SMC-specific code back in.