Posted By: Anonymous
I am trying to automate database creation process with a shell script and one thing I’ve hit a road block with passing a password to psql.
Here is a bit of code from the shell script:
psql -U $DB_USER -h localhost -c"$DB_RECREATE_SQL"
How do I pass a password to
psql in a non-interactive way?
From the official documentation:
It is also convenient to have a ~/.pgpass file to avoid regularly having to type in passwords. See Section 30.13 for more information.
This file should contain lines of the following format:
The password field from the first line that matches the current connection parameters will be used.