Use psycopg2's string handling to escape password string

This allows the password to contain single quotes and should make it safe to
use randomly generated passwords (provided passwords can be represented in the
connection encoding).
Merge pull request #2605 from b6d/postgresql_user-quote-pwd

Use psycopg2's string handling to escape password string