I am writing a non-interactive script that needs to execute postgres commands. The script will only be run by root
or a user with sudo
permissions, and the postgres commands need to be executed as the postgres
user in postgresql. The trouble is that postgresql always (as far as I can tell) prompts for a password interactively (i.e. pqsl -U postgres -W
) or does not accept a password at all (i.e. psql -U postgres -w
). I would like to pass a password on the command line, similar to how mysql allows mysql -u user -p password
. How can I do this with postgres?
Take the 2-minute tour
×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.
|
|||
Use the
|
||||
|
-p password
leaves your password visible in, for example,ps xa
output. – derobert Apr 22 '14 at 17:59peer
orident
authentication (if the script is running on the same machine as postgres) or you can use a~/.pgpass
file. – derobert Apr 22 '14 at 18:05