improved postgres support
Merge pull request #743 from wenshao/master

improved postgres support