121

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?

1
  • 10
    If an answer solves your problem (such as the one by @Jorge Disaz) you should probably accept it.
    – Neowizard
    Commented Jan 3, 2018 at 14:51

2 Answers 2

223
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.

0
37

This is for newer versions of pg_dump:

pg_dump -d postgres://username:password@my_postgres_server:5432/databasename > filename
2
  • 1
    I did not need the -d flag, it worked anyway. Commented May 9, 2023 at 12:45
  • 1
    thanks, i also had to upgrade pg_dump to match the version of the server Commented May 16 at 21:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.