How to use pg_dump with a connection uri / url?

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.


This is for newer versions of pg_dump:

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