Re: dropdb utility command prompts for password despite valid .pgpass file in home directory - Mailing list pgsql-bugs

From Julien Rouhaud
Subject Re: dropdb utility command prompts for password despite valid .pgpass file in home directory
Date
Msg-id 20220624084026.n7p4zsio3t2ox5mg@jrouhaud
Whole thread Raw
In response to dropdb utility command prompts for password despite valid .pgpass file in home directory  (Alan Lin <alin@codecademy.com>)
List pgsql-bugs
Hi,

On Thu, Jun 23, 2022 at 03:21:52PM -0400, Alan Lin wrote:
> Problem:
>
> I'm trying to use the dropdb utility command in non-interactive mode to
> drop an existing database (with active connections) in a test environment,
> but it keeps prompting me for the password.
>
> Here's what I'm running with `.pgpass` with valid permissions (0600) and
> location (users home directory, though I've also explicitly set the path
> using PGPASSFILE envvar). This pass file was validated to work with other
> utility commands like pg_dump.
>
> Note: "myserverhost" is not a real host - I've just redacted our actual
> hostname for this bug report.
>
> Command:
>
> ```
> dropdb --host <myserverhost.amazonaws.com> -w <mydbname>
> ```
>
> Response:
>
> ```
> dropdb: error: could not connect to database template1: connection to
> server at "<myserverhost.amazonaws.com>" (<redacted IP>), port 5432 failed:
> fe_sendauth: no password supplied
> ```
>
> Note the `template1` error despite me passing the correct database name.

This is not a bug.  As mentioned in the documentation for the
maintenance-db option
(https://www.postgresql.org/docs/current/app-dropdb.html):

> --maintenance-db=dbname
> Specifies the name of the database to connect to in order to drop the target
> database. If not specified, the postgres database will be used; if that does
> not exist (or is the database being dropped), template1 will be used. This
> can be a connection string. If so, connection string parameters will override
> any conflicting command line options.

You should either specify a maintenance-db option for which there is a valid
match in your .pgass file, or adapt your .pgpass file to match the default
maintenance databases.



pgsql-bugs by date:

Previous
From: Andrey Lepikhov
Date:
Subject: Re: Errors on CREATE TABLE IF NOT EXISTS
Next
From: Peter Eisentraut
Date:
Subject: Re: BUG #17522: While using --with-ssl=openssl and PG_TEST_EXTRA='ssl' options, SSL test fails on OpenBSD 7.1