Use psocopg2's string handling to escape password string

I had another pull request concerning the postgresql_user module (optional passwords) which wasn't tested well enough (sorry about that). I'll resubmit the optional-password one once this request is reviewed, since both requests target the same lines of code.

Commit message: 

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).