misleading error message from connectMaintenanceDatabase()

Поиск
Список
Период
Сортировка
От Josh Kupershmidt
Тема misleading error message from connectMaintenanceDatabase()
Дата
Msg-id CAK3UJRG_QZr3NoKjX0oEFGTPZQXhhz+sZydg9q366c-zo6HXJQ@mail.gmail.com
обсуждение исходный текст
Ответы Re: misleading error message from connectMaintenanceDatabase()  (Robert Haas <robertmhaas@gmail.com>)
Список 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

Вложения

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Pavel Stehule
Дата:
Сообщение: Re: Trigger execution role (was: Triggers with DO functionality)
Следующее
От: Fujii Masao
Дата:
Сообщение: Re: Checkpointer vs pg_stat_bgwriter