Subrat Sahoo Subrat Sahoo - 4 years ago 235
Bash Question

Run a psql query from a shell script

Hi i have a psql statement which needs to be run from a shell script.
i have tried below but no success

ctfdb is my database

psql ctfdb <<EOF
statement
EOF


psql: FATAL: Peer authentication failed for user "root"


i have even tried giving "sudo psql"

Sorry, user root is not allowed to execute '/bin/psql ctfdb' as root on my server


Any suggestions ??

Answer Source

psql -U postgres ctfdb

Connects as user postgres. You are connecting to the DB as your shell username root.

There are other ways such as setting the PGUSER environment variable or configuring pg_hba.conf to allow access for other users.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download