Thread: Starting psql from Script - how to pass the password?

Starting psql from Script - how to pass the password?

From
Dani Oderbolz
Date:
Hi all,
I am sure, this has been answerde over and over again,
but I did not find anything in the list-Archives.

I would like to run psql from a script, using a user that requires
a password (I know that I could change pg_hba.conf, but thats not what I
want).
Now, psql doesn't seem to take the password as an option,right?

I tried this:

/usr/local/pgsql/bin/psql -d "$DB" -U "$USER" -o "$OFILE"  -q -c "$SQL"
-F "$SEPARATOR" -t <<EOT "$PASS"
EOT

Where $PASS stores my password.
But still, psql prompts me for the password...

Is there a way around this?

Thanks,
Dani


Re: Starting psql from Script - how to pass the password?

From
Hubert Lubaczewski
Date:
On Fri, 20 Jun 2003 13:22:50 +0200
Dani Oderbolz <oderbolz@ecologic.de> wrote:

> But still, psql prompts me for the password...
> Is there a way around this?

sure,
just:
export PGPASSWORD="your_password"
before calling postgresql programs.
than it doesn't ask.
but since it's raher dangerous, check if you can (version dependant), and use ~/.pgpass file instead.
you can find more information in postgresql-docs/html/libpq-envars.html

best regards

depesz


Re: Starting psql from Script - how to pass the password?

From
Dani Oderbolz
Date:
Hubert Lubaczewski wrote:

>sure,
>just:
>export PGPASSWORD="your_password"
>before calling postgresql programs.
>than it doesn't ask.
>but since it's raher dangerous, check if you can (version dependant), and use ~/.pgpass file instead.
>you can find more information in postgresql-docs/html/libpq-envars.html
>
Hey Hubert,
thats the solution I was after.
I realise that there are Security Implications,
but I can handle this here.

Thanks!