Thread: BUG #14912: Undocumented: 'psql -l' assumes database 'postgresql' not$USER

BUG #14912: Undocumented: 'psql -l' assumes database 'postgresql' not$USER

From
mhwood@ameritech.net
Date:
The following bug has been logged on the website:

Bug reference:      14912
Logged by:          Mark Wood
Email address:      mhwood@ameritech.net
PostgreSQL version: 9.6.6
Operating system:   Gentoo Linux, kernel 4.12, glibc 2.25-r9
Description:

The 'psql' man page explains that the default database name is your OS
username, and that $PGDATABASE can be used to supply a different default.
That is true *unless* using -l / --list.  The code shows that this option
defaults to 'postgresql' instead, overriding the libpq defaulting.  I spent
quite some time reading and experimenting to determine why I was not seeing
the documented behavior.

The actual behavior may be reasonable, but if so it should be documented as
an exception for the --list function.


Re: BUG #14912: Undocumented: 'psql -l' assumes database 'postgresql'not $USER

From
"David G. Johnston"
Date:
On Thu, Nov 16, 2017 at 10:17 AM, <mhwood@ameritech.net> wrote:
The following bug has been logged on the website:

Bug reference:      14912
Logged by:          Mark Wood
​[...]​

That is true *unless* using -l / --list.  The code shows that this option
defaults to 'postgresql' instead, overriding the libpq defaulting.

​It actually defaults to "postgres"
​[...]​
 
The actual behavior may be reasonable, but if so it should be documented as
an exception for the --list function.

I can see an argument for either default, but given that this invocation has never defaulted to the user's database I cannot see changing it.

I agree this should be considered a doc bug and back-patched.  Possible verbiage for master below and attached.

Changing the "Usage" section to point out this exception to the rule seems undesirable.

David J.

diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index e520cdf3ba..ad2a505b1e 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -283,7 +283,9 @@ EOF
       <listitem>
       <para>
       List all available databases, then exit. Other non-connection
-      options are ignored. This is similar to the meta-command
+      options are ignored. If an explicit database name is not
+      found the <literal>postgres</literal> database, not the user's,
+      will be targeted for connection. This is similar to the meta-command
       <command>\list</command>.
       </para>
       </listitem>


Attachment

Re: BUG #14912: Undocumented: 'psql -l' assumes database'postgresql' not $USER

From
Bruce Momjian
Date:
Patch applied and backpatched through PG 10.  Thanks.

---------------------------------------------------------------------------

On Thu, Nov 16, 2017 at 02:27:06PM -0700, David G. Johnston wrote:
> On Thu, Nov 16, 2017 at 10:17 AM, <mhwood@ameritech.net> wrote:
> 
>     The following bug has been logged on the website:
> 
>     Bug reference:      14912
>     Logged by:          Mark Wood
>     ​[...]​
> 
>     That is true *unless* using -l / --list.  The code shows that this option
>     defaults to 'postgresql' instead, overriding the libpq defaulting.
> 
> 
> ​It actually defaults to "postgres"
> ​
> ​[...]​
>  
> 
>     The actual behavior may be reasonable, but if so it should be documented as
>     an exception for the --list function.
> 
> 
> I can see an argument for either default, but given that this invocation has
> never defaulted to the user's database I cannot see changing it.
> 
> I agree this should be considered a doc bug and back-patched.  Possible
> verbiage for master below and attached.
> 
> Changing the "Usage" section to point out this exception to the rule seems
> undesirable.
> 
> David J.
> 
> diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
> index e520cdf3ba..ad2a505b1e 100644
> --- a/doc/src/sgml/ref/psql-ref.sgml
> +++ b/doc/src/sgml/ref/psql-ref.sgml
> @@ -283,7 +283,9 @@ EOF
>        <listitem>
>        <para>
>        List all available databases, then exit. Other non-connection
> -      options are ignored. This is similar to the meta-command
> +      options are ignored. If an explicit database name is not
> +      found the <literal>postgres</literal> database, not the user's,
> +      will be targeted for connection. This is similar to the meta-command
>        <command>\list</command>.
>        </para>
>        </listitem>
> 
> 

> diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
> index e520cdf3ba..ad2a505b1e 100644
> --- a/doc/src/sgml/ref/psql-ref.sgml
> +++ b/doc/src/sgml/ref/psql-ref.sgml
> @@ -283,7 +283,9 @@ EOF
>        <listitem>
>        <para>
>        List all available databases, then exit. Other non-connection
> -      options are ignored. This is similar to the meta-command
> +      options are ignored. If an explicit database name is not
> +      found the <literal>postgres</literal> database, not the user's,
> +      will be targeted for connection. This is similar to the meta-command
>        <command>\list</command>.
>        </para>
>        </listitem>


-- 
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

+ As you are, so once was I.  As I am, so you will be. +
+                      Ancient Roman grave inscription +


Re: BUG #14912: Undocumented: 'psql -l' assumes database 'postgresql'not $USER

From
Peter Eisentraut
Date:
On 11/16/17 16:27, David G. Johnston wrote:
>        List all available databases, then exit. Other non-connection
> -      options are ignored. This is similar to the meta-command
> +      options are ignored. If an explicit database name is not
> +      found the <literal>postgres</literal> database, not the user's,
> +      will be targeted for connection. This is similar to the meta-command
>        <command>\list</command>.

What does "an explicit database name is not found" mean?  How does one
find an explicit database name?

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


Re: BUG #14912: Undocumented: 'psql -l' assumes database 'postgresql'not $USER

From
"David G. Johnston"
Date:
On Fri, Feb 2, 2018 at 2:49 PM, Peter Eisentraut <peter.eisentraut@2ndquadrant.com> wrote:
On 11/16/17 16:27, David G. Johnston wrote:
>        List all available databases, then exit. Other non-connection
> -      options are ignored. This is similar to the meta-command
> +      options are ignored. If an explicit database name is not
> +      found the <literal>postgres</literal> database, not the user's,
> +      will be targeted for connection. This is similar to the meta-command
>        <command>\list</command>.

What does "an explicit database name is not found" mean?

​A name was not supplied to the psql command either as the first non-option argument, via the --dbname command line option, in the connection URI (possibly indirectly via a pg_service.conf entry), or via the PGDATABASE environment variable.

How does one
find an explicit database name?

Given the answer above does this question still apply?

David J.

Re: BUG #14912: Undocumented: 'psql -l' assumes database 'postgresql'not $USER

From
Peter Eisentraut
Date:
On 2/2/18 17:05, David G. Johnston wrote:
>     What does "an explicit database name is not found" mean?
> 
> ​A name was not supplied to the psql command either as the first
> non-option argument, via the --dbname command line option, in the
> connection URI (possibly indirectly via a pg_service.conf entry), or via
> the PGDATABASE environment variable.

OK, clarified that a bit further.  Actually, an environment variable
does not take any effect for this.

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services