Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to do a script that will backup my psql databases, i want to use the wal archive mode and not pg_dump. I've wrote this from a script i found on the web :

#Test Script BackupSQL


PG_BACKUP_START="$PG_SQL_CMD -U $PG_SQL_USER -h $PG_SQL_HOST -c \"select pg_start_backup('$PG_BACKUP_LABEL')\""
PG_BACKUP_STOP="$PG_SQL_CMD -U $PG_SQL_USER -h $PG_SQL_HOST -c \"select pg_stop_backup()\""

sleep 2

My problem is : the script prompt me for the psql password when i run it. I didn't found a way to specify the password in the psql command like you can do in mysql with the -p option.

How can i make the script answer the prompt ?

share|improve this question
Upvoted Mattias for answering your question, but I see some potential issues with what you written above. Granted it's incomplete, so maybe you'll work it all out, but it seems easier to just reuse some existing scripts for this, like the ones we wrote at – xzilla Jan 7 '12 at 15:41

Try using the .pgpass file for not having to type the password.

Or you can use a shell syntax like the following:

 psql -h -U username <<EOF

Or as a final option you should be able to use the environmental variables PGUSER and PGPASSWD.

share|improve this answer

If you have the following line in your pg_hba.conf file, you don't need to supply a password. You just need to run this command as postgres user.

local   all         all           ident
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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