Run PostgreSQL CLI (psql) in bash script without asking for password?

Running the PostgreSQL CLI (psql) through a bash script, as the postgres user invokes the password request, although I can start it manually without a password. When I try to put -w in a script, this error occurs:

psql: fe_sendauth: password not specified

Is it possible to run psql automatically without a password?

+3
source share
2 answers

You can use the password file pgpass.conf or use PGPASSWORD .

For local development, or if security is not an issue, you can also configure PostgreSQL to run in authentication mode by modifying your pg_hba.conffile.

+10

, , , , script. pghba.conf ( PostgreSQL):

host YOUR_DB YOUR_USER YOUR_IP trust

:

  • YOUR_DB:
  • YOUR_USER: , script
  • YOUR_IP: IP, script

expect ( , Linux - unix- , cygwin).

+1

All Articles