views:

71

answers:

2

I'm busy backing up my postgres db, I run the following command

pg_dump -d data -U postgres -h 127.0.0.1 -CdiOv > data.sql

I however have one problem I get asked for the password, if I want to add this into a cron I do not want to get promted for the password. Is there any way to do this without the password prompt?

+1  A: 

Use ~/.pgpass. pgpass documentation

Lots more details to be found on Google, searching for "pg_dump password".

Wade Williams
+1  A: 

First of all: never use -d option to pg_dump. Do you even know what it does?

Second: use pgpass file or PGPASSWORD env variable.

depesz
I'll bite. I do know what -d is for and have needed it sometimes (cross database engine migrations on occasion). Do you mean "it doesn't do what you think it does" or do you really man "never"?
Nic Gibson
It means dump data as INSERT command?
Roland
Whats wrong with that except making restoration slow/
Roland
@newt - not sure where you're migrating to, but migration is the case when you can use inserts. for backups there is no point.
depesz
@Roland: it's slow. and most people use it because they think it's "--database". And it is dropped in 8.4 (finally).
depesz
@depesz - ok, makes sense. I was migrating to mysql (I know, that's just plain *wrong*) and it was the quickest way at the time.
Nic Gibson