Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escape password containing @ when using postgres pg_dump command

I 'm using postgres, I created db, user, password, this is the password:

password = name&text@sob

I'm using the following command to dump database and it works on my other databases I have:

pg_dump -Fc --no-acl --no-owner --dbname=postgresql://db_user:[email protected]:5432/db_name

But it doesn't work when using the DB with the password containing & and @:

pg_dump -Fc --no-acl --no-owner --dbname=postgresql://db_user:name&text@[email protected]:5432/db_name

doesn't work because of the & and @ in the password- So I escaped the & with \ but it didn't work for @ - any suggestions?

Thanks

like image 856
Roko Avatar asked Jun 15 '17 07:06

Roko


People also ask

How do I bypass a Pgdump password?

Create a . pgpass file in the home directory of the account that pg_dump will run as. Then, set the file's mode to 0600 . Otherwise, it will be ignored.

How do I connect to PostgreSQL without a password?

To make that entry work, do not specify a hostname or port for psql , then it will use a "local" connection through named pipes. Alternatively, you can local with host and then add 127.0. 0.1 as the (client) IP address to "trust".

Where is password stored in postgres?

PostgreSQL database passwords are separate from operating system user passwords. The password for each database user is stored in the pg_authid system catalog. Passwords can be managed with the SQL commands CREATE ROLE and ALTER ROLE, e.g., CREATE ROLE foo WITH LOGIN PASSWORD 'secret' , or the psql command \password .


1 Answers

adding ?password=name%26te‌​xt%40sob as uri parameter should do:

pg_dump -Fc --no-acl --no-owner --dbname=postgresql://db_user:[email protected]:5432/db_name?password=name%26te‌​xt%40sob

as per https://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-CONNSTRING

Components of the hierarchical part of the URI can also be given as parameters.

update

as Roko noticed, URL has to be encoded

like image 134
Vao Tsun Avatar answered Sep 20 '22 18:09

Vao Tsun