Jelphy
Jelphy

Reputation: 1059

PSQL not prompting for password in PowerShell

This PSQL statement in PowerShell:

.\psql --% -h localhost -p 5000 -U postgres -d mydatabase -c `
(SELECT * ...... do something);

Works - and does not prompt for a password.

.\psql.exe --help

States the -w switch is required for no password.

Why does this command work without a password? The database has a password.

The command does not work in the PSQL interactive shell without password authentication, only in PowerShell.

Upvotes: 2

Views: 1453

Answers (1)

Evan Carroll
Evan Carroll

Reputation: 1

-w is not required for "no password" reread what it says, from my man psql

-w --no-password Never issue a password prompt. If the server requires password authentication and a password is not available by other means such as a .pgpass file, the connection attempt will fail. This option can be useful in batch jobs and scripts where no user is present to enter a password. Note that this option will remain set for the entire session, and so it affects uses of the meta-command \connect as well as the initial connection attempt.

-w is meant for when you're running psql scripts and input for a password is not possible, like in a headless session.

Why does this command work without a password? The database has a password.

Even if the database has a password, if your pg_hba.conf file has trust no password will be required. To debug this further we need to see your pg_hba.conf.

Upvotes: 3

Related Questions