Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2002
    Location
    Calgary, Canada
    Posts
    30

    Talking Unanswered: passing a password

    Hi guys

    I have a shell script that connects to postgres, runs a bunch of sql scripts and disconnects. I would like to use a password to connect.

    How can I do it ?

    Right now it is simply

    psql -U $user -d $database

    \i scripts.sql

    \q

    I dont really want to keep the pg_hba.conf setings as trust for localmachines but it looks like that is how i have to do it ??

  2. #2
    Join Date
    Sep 2001
    Location
    Vienna
    Posts
    400

    password

    Set your in you pg_hba.conf file only at teh line where local is defined the authentification from trust to md5,ident ...

    and then it should prompt you the password
    http://www.postgresql.org
    --Postgresql is the only kind of thing--

  3. #3
    Join Date
    Apr 2002
    Location
    Calgary, Canada
    Posts
    30
    I guess I didnt explain it properly.

    Currently I have trust authentication on the local machine......which I do not want.

    I want to change it to md5. This i can do, however any scripts that I had that ran in the database will not work as you cannot specify a password in command line to access psql.

    Is there a method to allow you to pass a password to psql at the command line? the same way as you can specify a user with the -U, the -W only prompts you for a password and does not allow you to set the password in the script.

  4. #4
    Join Date
    Dec 2002
    Posts
    65

    Well...

    Let me know if this works for you:

    in your shell script add

    export PGPASSWORD=<the password of your db>

    before your call to pg_sql.

    There are probably some big security issues with doing this, but if you must do some automated cron stuff with postgres this may help you out until you find a better solution.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •