Re: misleading error message from connectMaintenanceDatabase()

Lists: pgsql-hackers
From: Josh Kupershmidt <schmiddy(at)gmail(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: misleading error message from connectMaintenanceDatabase()
Date: 2012-02-28 05:05:13
Message-ID: CAK3UJRG_QZr3NoKjX0oEFGTPZQXhhz+sZydg9q366c-zo6HXJQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

I noticed a misleading error message recently while using createdb. Try:

test=# CREATE ROLE dummy NOLOGIN;

Now, attempt to use createdb as that role. Here's 9.1.1:

$ createdb -Udummy testdb
createdb: could not connect to database postgres: FATAL: role "dummy"
is not permitted to log in

And here is git head:

$ createdb -Udummy testdb
createdb: could not connect to databases "postgres" or "template1"
Please specify an alternative maintenance database.
Try "createdb --help" for more information.

Although I guess you could argue the latter message is technically
correct, since "could not connect" is true, the first error message
seems much more helpful. Plus, "Please specify an alternative
maintenance database" is a rather misleading hint to be giving in this
situation.

This seems to be happening because connectMaintenanceDatabase() is
passing fail_ok = true to connectDatabase(), which in turn just
returns NULL and doesn't print a PQerrorMessage() for the failed conn.
So connectMaintenanceDatabase() has no idea why the connection really
failed.

A simple fix would be just to pass fail_ok = false for the last
connectDatabase() call inside connectMaintenanceDatabase(), and give
up on trying to tack on a likely-misleading hint about the maintenance
database. Patch attached. This leads to:

$ createdb -Udummy testdb
createdb: could not connect to database template1: FATAL: role
"dummy" is not permitted to log in

which is almost the same as the 9.1.1 output, with the exception that
"template1" is mentioned by default instead of the "postgres"
database.

Josh

Attachment Content-Type Size
connectMDB_error.diff application/octet-stream 913 bytes

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Josh Kupershmidt <schmiddy(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: misleading error message from connectMaintenanceDatabase()
Date: 2012-03-21 14:58:40
Message-ID: CA+TgmoYcRz8J_T=ArcXR57TzPrPmXwfbdf_D6_-XYqTVd8BkAQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Feb 28, 2012 at 12:05 AM, Josh Kupershmidt <schmiddy(at)gmail(dot)com> wrote:
> A simple fix would be just to pass fail_ok = false for the last
> connectDatabase() call inside connectMaintenanceDatabase(), and give
> up on trying to tack on a likely-misleading hint about the maintenance
> database. Patch attached.

Committed. Thanks for the report and patch; sorry for the delay.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company