6.8.13

PGSQL | Pass Password in a Script

A quick help that I used to run my script by passing password authentication to connect to PGSQL database and run a function so I can get my output.

Let me tell you first what did't work for me - I use the arguement "-p password" to pass. But PGSQL is a little finicky and it doesn't accept that. It has its own T&C.

What worked is: adding export PGPASSWORD=pass on top of the script that runs and connects to the database.

#!/bin/bash
env
export PGPASSWORD=admin /path/pgsql/bin/psql -U postgres -c "select * function name();"

The credit to my knowledge goes to Mr Sunil Kumar, my senior and my colleague at my work place who helped me throughout with the tweaking of the script. Let me know if you need his help too!

See you next time!

0 comments:

Post a Comment