For example, running SQL statements using psql is a bit complicated if you do not want to be prompted for a password. Research on the topic is made a bit difficult by the fact that the answers are provided in the "libpq" section of the PostgreSQL manual, rather than the manpage for psql.
The upside is that I think it works with createdb, createuser and other commands (did not test that though).
There are a few recommended ways of doing this.
- One is to set "trust" in "pg_hba.conf" for your type of connection, which usually is good in a situation where you can trust the machines and users that are connecting to the database.
- Another is to store passwords in ~/.pgpass, as described here http://www.postgresql.org/docs/current/static/libpq-pgpass.html
PGPASSWORD="your_password" psql -U postgres -c "select 1;"
Such approach is carries a security risk of someone seeing the password, but can be quite useful in a situation where you need to run a list of commands and do not care about security.
Information on PGPASSWORD and other environmental variables is found here: http://www.postgresql.org/docs/current/static/libpq-envars.html
No comments:
Post a Comment