How do I run a Postgres SQL script without being prompted for a password for Control-M/Enterprise Manager or Control-M/Server?
The psql command always prompts for a password. postgresql postgres password noprompt |
There are 2 ways to allow a Postgres script to run without being prompted for a password: 1. Using the PGPASSWORD environment variable
a. export(unix) or set (windows) the environment variable PGPASSWORD
set PGPASSWORD=mypass
b. run the psql command with a SQL input and output file. Here is the syntax:
psql -f script_inputfile -o script_outputfile DBNAME username
for example,
psql -f C:\temp\scriptin.sql -o C:\temp\scriptout.txt ctrlm640 ctmuser
2. use the .pgpass.conf file
a. export(unix) or set (windows) the environment variable PGPASSFILE
set PGPASSFILE=C:\Program Files\BMC Software\CONTROL-M EM 6.4.01\Default\pgsql\pgpass.conf
b. create the file: C:\Program Files\BMC Software\CONTROL-M EM 6.4.01\Default\pgsql\pgpass.conf. with the following syntax:
hostname:port:database:username:password
note that the * can be used as a wildcard.
for example,
*:*:*:ctmuser:mypassword
c. run the psql command with a SQL input and output file. Here is the syntax:
psql -f script_inputfile -o script_outputfile DBNAME username
for example,
psql -f C:\temp\scriptin.sql -o C:\temp\scriptout.txt ctrlm640 ctmuser
|