Thread

  1. misleading error message from connectMaintenanceDatabase()

    Josh Kupershmidt <schmiddy@gmail.com> — 2012-02-28T05:05:13Z

    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
    
  2. Re: misleading error message from connectMaintenanceDatabase()

    Robert Haas <robertmhaas@gmail.com> — 2012-03-21T14:58:40Z

    On Tue, Feb 28, 2012 at 12:05 AM, Josh Kupershmidt <schmiddy@gmail.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