Database hostname

Use `localhost` instead of the system hostname as the default for connecting to Postgres, since the system hostname may resolve to an external IP. Also use `socket.gethostname` instead of an external command.