misleading error message from connectMaintenanceDatabase()

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
Thread:
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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Fujii Masao 2012-02-28 06:06:29 Re: Checkpointer vs pg_stat_bgwriter
Previous Message Pavel Stehule 2012-02-28 04:59:28 Re: Trigger execution role (was: Triggers with DO functionality)