How can I call psql so that it doesn\'t prompt for a password?
This is what I have:
psql -Umyuser < myscript.sql
You have to create a password file: see http://www.postgresql.org/docs/9.0/interactive/libpq-pgpass.html for more info.
An alternative to using PGPASSWORD
environment variable is to use conninfo
string according to the documentation
An alternative way to specify connection parameters is in a conninfo string or a URI, which is used instead of a database name. This mechanism give you very wide control over the connection.
$ psql "host=<server> port=5432 dbname=<db> user=<user> password=<password>"
postgres=>
Use -w in the command: psql -h localhost -p 5432 -U user -w
If you intend on having multiple hosts/database connections, the ~/.pgpass file is the way to go.
Steps:
vim ~/.pgpass
or similar. Input your information in the following format:
hostname:port:database:username:password
Do not add string quotes around your field values. You can also use * as a wildcard for your port/database fields.chmod 0600 ~/.pgpass
in order for it to not be silently ignored by psql.alias postygresy='psql --host hostname database_name -U username'
The values should match those that you inputted to the ~/.pgpass file.. ~/.bashrc
or similar. Note that if you have an export PGPASSWORD='' variable set, it will take precedence over the file.
PGPASSWORD=[your password] psql -Umyuser < myscript.sql
You may find this useful: Windows PSQL command line: is there a way to allow for passwordless login?