Re: psql -c "select * from a-user-name-that-exist fails - Mailing list pgsql-novice

From Josh Kupershmidt
Subject Re: psql -c "select * from a-user-name-that-exist fails
Date
Msg-id AANLkTi=ghxhwc0DScn3rL+ZLzb4MX8_oHZyi0qDqVVfy@mail.gmail.com
Whole thread Raw
In response to psql -c "select * from a-user-name-that-exist fails  (lalebarde <l.alebarde@free.fr>)
Responses Re: psql -c "select * from a-user-name-that-exist fails  (lalebarde <l.alebarde@free.fr>)
List pgsql-novice
On Thu, Sep 23, 2010 at 7:14 PM, lalebarde <l.alebarde@free.fr> wrote:
>
> Hi all,
>
> I have just installed PostGreSQL on my Gentoo Linux Desktop for the first
> time. Installation is ok. Then, I have started to install an application
> that uses PostGreSQL. To test if I am declared as a user in the data base,
> it executes the command :
>
> psql -c "select * from laurent
>
> More precisely this bash script :
>
> ----------------------------------------------------------------------------------------
> function exit_if_no_postgres_user
> {
>    set +e
>    ( psql -q template1 -c "select * from pg_user;" | grep $1 ) \
>                            >/dev/null 2>&1
>    if [ $? -eq 1 ]
>    then
>        echo ""
>        echo "*** Error: No postgresql user '$1'"
>        echo ""
>        exit 1
> #    else
> #       echo "Good: Postgresql can be accessed by $1"
>    fi
>    set -e
> }
> -----------------------------------------------------------------------------------------
> USER=$(whoami) is passed as an argument which is $1
> -----------------------------------------------------------------------------------------
>
>
> laurent being the user's name. The error is triggered, thought laurent was
> declared with the command : createuser -d -A laurent. laurent appears in the
> pgadmin3 roles list. As far as I have understood the documentation, roles
> and users are the same thing.
> Besides, I am surprised by the "template". What is it for ?
>
> Any clue why I get this error ?

I'm not in the mood to dig through that bash function of yours to
figure out where that error message is coming from... but I'm betting
your problem is because the createuser command you used didn't specify
the "--login" option. The pg_user view only shows those users able to
login.

To double check, try this command:

   SELECT rolcanlogin FROM pg_authid WHERE rolname = 'laurent';

from the psql client. I'm betting you'll see 'f' for false. To fix, try:

  ALTER ROLE laurent WITH LOGIN;

Josh

pgsql-novice by date:

Previous
From: lalebarde
Date:
Subject: psql -c "select * from a-user-name-that-exist fails
Next
From: Josh Kupershmidt
Date:
Subject: Re: psql -c "select * from a-user-name-that-exist fails