user2490003
user2490003

Reputation: 11890

Automating a PG_DUMP of a PSQL database on Heroku

I'm trying to pg_dump certain schemas from my Heroku-hosted PSQL database into a local file.

Heroku provides me a DATABASE_URL in the form

# postgres://username:password@host:port/database
postgres://abcde:[email protected]:5762/riza3dj029012

Based on the above I tried dumping some schemas -

> pg_dump --username=abcde --host=ec2-21-82-72-112.compute-1.amazonaws.com --port=5762 --dbname=riza3dj029012 --create --schema=my_schema --password  > ~/pg_dump.dmp
> password: (enter password)

Is there any way to provide the password as a flag so I don't have to type it in manually? I want to automate this in a script.

I know --no-password exists, but not sure what use that is, because it just prevents prompting for a password and then authentication (obviously) fails.

Thanks!

Upvotes: 1

Views: 639

Answers (1)

Steve Glick
Steve Glick

Reputation: 706

As @eabates mentioned in the comments you can create a .pgpass file for this purpose. More info can be found in the official documentation for Postgres: https://www.postgresql.org/docs/9.5/static/libpq-pgpass.html

Just create a file named .pgpass in the user home directory with as many lines as needed in the following format:

hostname:port:database:username:password

Upvotes: 1

Related Questions