How to use pg_dump with a connection uri / url?

PostgresqlConnection String

Postgresql Problem Overview


I can invoke psql like this:

psql postgres://...

How can I use pg_dump with a connection string in the format postgres://...?
Would be more convenient than breaking URI's into host, post, username, password.

Is there syntax for this?

Postgresql Solutions


Solution 1 - Postgresql

pg_dump postgres://username:password@my_postgres_server:5432/databasename

I just downloaded a dump using this format. Optionally you can add -f filename to specify a local filename.

Solution 2 - Postgresql

This is for newer versions of pg_dump:

pg_dump -d postgres://username:password@my_postgres_server:5432/databasename > filename

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTronathanView Question on Stackoverflow
Solution 1 - PostgresqlJorge DiazView Answer on Stackoverflow
Solution 2 - PostgresqlMohammad BarbastView Answer on Stackoverflow