How to handle special characters in the password of a Postgresql URL connection string?

See Connection URIs in the doc.

There are a few things that don’t seem quite right in your question:

  • URIs are supported by postgres since version 9.2 only, so with a 9.1 client that’s not supposed to work at all. Or you’re using a client that implements connection URIs itself.

  • Percent-sign encoding is supported. Per doc:

    Percent-encoding may be used to include symbols with special meaning
    in any of the URI parts.

  • Percent-encoding is not even necessary for a dollar character.

Tried with 9.3:

sql> alter user daniel password 'p$ass';

$ psql 'postgresql://daniel:p$ass@localhost/test'

works

$ psql 'postgresql://daniel:p%24ass@localhost'

works

psql 'postgresql://daniel:pass@localhost/test'

fails as expected: bad password.

Leave a Comment