From: http://blog.ralreegorganon.com/2008/08/23/psql-and-passwords-on-the-command-line/
psql doesn’t let you pass it a password at the command line (and with good reason–otherwise everyone would be able to see it with ps) but it can be somewhat frustrating if you’re trying to use psql in a script, as it will prompt for the password. One way to deal with this is to create a .pgpass file in your home directory. The lines in the file should be in the following format:
hostname:port:database:username:password
All values but the password can have * to match anything. Additionally, the file needs to have its permissions restricted, otherwise it will be ignored.
chmod 0600 ~/.pgpass
With that in place, you should be able to run psql from the command line without being prompted for a password.