2
votes

Team, I am using amazon redshift ( 8.0.2. ). While connect redshift cluster, we can connect without password ( this setting we can do in my local machine - pg_hba.conf entry ).But I have set "md5" to prompt password.

# IPv4 local connections:
host    all         all         127.0.0.1/32          md5
# IPv6 local connections:
host    all         all         ::1/128               md5
#host    postgres   postgres    <my_ip>      md5

Now i would like to connect redshift thro linux server. in my shell script, I am connecting redshift and doing my activities. But I should be able to connect redhsift (i.e i shold be able to pass the password as variable, and after connect, i should be able to perform my activities ).

Could you please guide me on this ?

Thaks

2

2 Answers

1
votes

Try using the below, it worked for me.

psql "host=yourhostname port=yourport_no dbname=your_DB_name user=your_user_id password=your_password" -F  --no-align    -c  " Your_SQL_statement"
0
votes

If I have not misunderstood you, you want to avoid being asked for your password by the terminal. If this is so, you can do it by using the environment variable "PGPASSWORD" in order to give your password to redshift.

Then you can use "-w" (in lowercase with nothing else) in your comand line to avoid asking the password.

Something like that:

export PGPASSWORD=your_password
psql -h your_hostname -d your_databae -U your_user -p your_port -w