Re: Bug? 'psql -l' in pg_ctl? - Mailing list pgsql-general

From Tatsuo Ishii
Subject Re: Bug? 'psql -l' in pg_ctl?
Date
Msg-id 20001127105304J.t-ishii@sra.co.jp
Whole thread Raw
In response to Bug? 'psql -l' in pg_ctl?  (GH <grasshacker@over-yonder.net>)
Responses Re: Bug? 'psql -l' in pg_ctl?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
> Er, did anybody notice trouble when starting Postgres if a password has
> been set for user pgsql?
>
> On my FreeBSD 5.0-20000528-CURRENT box, psql -l (from pg_ctl)
> sucks down a big 28% cpu.
>
> Here is the relevant section of the startup script:
>
> start)
>     [ -d /usr/local/pgsql/lib ] && /sbin/ldconfig -m /usr/local/pgsql/lib
>     [ -x /usr/local/pgsql/bin/pg_ctl ] && {
>         su -l pgsql -c \
>             'exec /usr/local/pgsql/bin/pg_ctl -w start > /usr/local/pgsql/errlog
>  2>&1' &
>         echo -n ' pgsql'
>     }
>     ;;
>
> Postgres will start, but I still have that psql -l process cycling
> waiting for a password...
> errlog shows "DEBUG:  Data Base System is in production state..."
>
> Ah hah, I think I founnd the source of this and the file descriptor
> problem (for those of you who are familiar with it):

psql tries to read a password from stdin that is not available at boot
time. In simple_prompt in common.c:

        do
        {
            fgets(buf, 512, stdin);
        } while (buf[strlen(buf) - 1] != '\n');

Here the return value of fgets() should be checked if fgtes() returns
EOF or not. Otherewise above goes into an infinite loop. Even this
gets fixed, psql would return a fail status and that would be not
suitable for current pg_ctl implementation.

Probably we really need here is a kind of ping tool for PostgreSQL,
instead of using psql.

You could directory invoke postmaster but problem is there is no
reliable way to detect if PostgreSQL up and running other than
trying to make an actual communication with backend...
--
Tatsuo Ishii


pgsql-general by date:

Previous
From: Oleg Bartunov
Date:
Subject: RE: [HACKERS] Indexing for geographic objects?
Next
From: selkovjr@mcs.anl.gov
Date:
Subject: Re: [HACKERS] Indexing for geographic objects?