Thread: psql \c error

psql \c error

From
Philip Yarra
Date:
Hi folks, I've found that CVS HEAD psql's \c doesn't quite behave as expected 
when postmaster is listening on non-default port. In this case I have 
postmaster listening on port 5434:

[pyarra@punky pgsql]$ /usr/local/pgsql-cvs-head/bin/psql -p5434 -dpyarra
Welcome to psql 8.2devel, the PostgreSQL interactive terminal.

Type:  \copyright for distribution terms      \h for help with SQL commands      \? for help with psql commands      \g
orterminate with semicolon to execute query      \q to quit
 

pyarra=# \d
No relations found. (correct, nothing in DB 'pyarra')
pyarra=# \l      List of databases  Name    | Owner  | Encoding
-----------+--------+----------postgres  | pyarra | LATIN1pyarra    | pyarra | LATIN1spctest   | pyarra |
LATIN1template0| pyarra | LATIN1template1 | pyarra | LATIN1
 
(5 rows)

pyarra=# \c spctest
could not connect to server: No such file or directory       Is the server running locally and accepting
connectionson Unix domain socket "/tmp/.s.PGSQL.5432"?
 
Previous connection kept
pyarra=# \c spctest - - 5434
You are now connected to database "spctest" as user "pyarra" on host "(null)" 
at port 5434.
could not connect to server: No such file or directory       Is the server running locally and accepting
connectionson Unix domain socket "/tmp/.s.PGSQL.5432"?
 
Previous connection kept
could not connect to server: No such file or directory       Is the server running locally and accepting
connectionson Unix domain socket "/tmp/.s.PGSQL.5432"?
 
Previous connection kept
spctest=# \d      List of relationsSchema | Name | Type  | Owner
--------+------+-------+--------public | foo  | table | pyarra
(1 row)
(correct, one table in DB 'spctest')

The comments in src/bin/psql/command.c, starting at line 192, indicate the new 
connection should use the current port (5434) but this is not happening. Also 
note that when port is explicitly specified (\c spctest - - 5434) it does 
connect to the new DB on the right port, but still prints a spurious error.

The comments further down say "default" instead of "current" when the dash is 
used, so the comments may not be quite right. What behaviour was this change 
(http://archives.postgresql.org/pgsql-patches/2006-03/msg00154.php) actually 
supposed to give us?

Regards, Philip.

-- 

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it." - Brian W. Kernighan

-----------------
Utiba Pty Ltd 
This message has been scanned for viruses and
dangerous content by Utiba mail server and is 
believed to be clean.



Re: psql \c error

From
Tom Lane
Date:
Philip Yarra <philip@utiba.com> writes:
> Hi folks, I've found that CVS HEAD psql's \c doesn't quite behave as
> expected 

Yeah, there were complaints about this already.  I think the problem was
introduced by this patch:

2006-02-11 21:54  momjian
* doc/src/sgml/ref/psql-ref.sgml, src/bin/psql/command.c,src/bin/psql/help.c: Please find enclosed a patch that lets
youuse\c to connect (optionally) to a new host and port without exitingpsql.  This eliminates, IMHO, a surprise in that
youcan nowconnect to PostgreSQL on a differnt machine from the one where youstarted your session. This should help
peoplewho use psql as anadministrative tool.David Fetter
 

The patch seems not to behave very reasonably with respect to preserving
prior values for the newly-changeable connection parameters.  I haven't
got time to look into it myself right now though --- do you want to?
        regards, tom lane


Re: psql \c error

From
David Fetter
Date:
On Wed, Mar 29, 2006 at 10:19:51PM -0500, Tom Lane wrote:
> Philip Yarra <philip@utiba.com> writes:
> > Hi folks, I've found that CVS HEAD psql's \c doesn't quite behave as
> > expected 
> 
> Yeah, there were complaints about this already.  I think the problem was
> introduced by this patch:

I sent one patch to fix this, which went ignored, and Volkan Yazici
sent another one, to which the same thing happened.

Cheers,
D
> 
> 2006-02-11 21:54  momjian
> 
>     * doc/src/sgml/ref/psql-ref.sgml, src/bin/psql/command.c,
>     src/bin/psql/help.c: Please find enclosed a patch that lets you use
>     \c to connect (optionally) to a new host and port without exiting
>     psql.  This eliminates, IMHO, a surprise in that you can now
>     connect to PostgreSQL on a differnt machine from the one where you
>     started your session. This should help people who use psql as an
>     administrative tool.
>     
>     David Fetter
> 
> The patch seems not to behave very reasonably with respect to preserving
> prior values for the newly-changeable connection parameters.  I haven't
> got time to look into it myself right now though --- do you want to?
> 
>             regards, tom lane
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings

-- 
David Fetter <david@fetter.org> http://fetter.org/
phone: +1 415 235 3778        AIM: dfetter666                             Skype: davidfetter

Remember to vote!


Re: psql \c error

From
Neil Conway
Date:
On Thu, 2006-03-30 at 11:20 +1000, Philip Yarra wrote:
> Hi folks, I've found that CVS HEAD psql's \c doesn't quite behave as expected 
> when postmaster is listening on non-default port.

I've committed a patch to HEAD that should improve this behavior. Let me
know if the current behavior is still unsatisfactory.

-Neil




Re: psql \c error

From
Philip Yarra
Date:
On Mon, 3 Apr 2006 06:13 am, Neil Conway wrote:
> I've committed a patch to HEAD that should improve this behavior. Let me
> know if the current behavior is still unsatisfactory.

Yes, thanks, it fixes the stuff that bugged me:

[pyarra@punky pgsql]$ psql -p5434 -dpyarra
[snip opening car chase]
pyarra=# \c foo
You are now connected to database "foo".
foo=# \c philip - - 5432
You are now connected to database "philip" at port "5432".
philip=#                                                   

Regards, Philip.

-- 

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it." - Brian W. Kernighan

-----------------
Utiba Pty Ltd 
This message has been scanned for viruses and
dangerous content by Utiba mail server and is 
believed to be clean.