HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlModerate

In PostgreSQL URL I can't use a password containing special characters

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
postgresqlcontainingcanpasswordspecialcharactersuseurl

Problem

I have a postgresql database in Azure

The passwd string has special characters like these:

)mvd99/iyH_=ag=Por/W}%%aKY^ygt+,sC7%%P?APOU


psql --dbname=postgresql://db_user@mydemoserver:)mvd99/iyH_=ag=Por/W}%%aKY^ygt+,sC7%%P?APOU@mydemoserver.postgres.database.azure.com:5432/mydb


when executing the psql command, it shows me in following error:

psql: invalid percent-encoded token: "iyH_=ag=Por/W}%%aKY^ygt+,sC7%%P"


I already tried putting the passwd string in quotation marks but it does not work

What other options do I have?
I can not change the passwd

I'm interested in using the psql client, because I have to do very large backups

Solution

You have to use URI escapes for all problematic characters.

For this user:

CREATE ROLE "weird@name" PASSWORD '\/ @&?' LOGIN;


You can login like this:

psql postgresql://weird%40name:%5C%2F%20%40%26%3F@localhost:5432/test


The documentation has it:


Percent-encoding may be used to include symbols with special meaning in any of the URI parts, e.g. replace = with %3D.

Code Snippets

CREATE ROLE "weird@name" PASSWORD '\/ @&?' LOGIN;
psql postgresql://weird%40name:%5C%2F%20%40%26%3F@localhost:5432/test

Context

StackExchange Database Administrators Q#243219, answer score: 17

Revisions (0)

No revisions yet.