PSQL 不提示在 PowerShell 中输入密码
PSQL not prompting for password in PowerShell
PowerShell 中的这条 PSQL 语句:
.\psql --% -h localhost -p 5000 -U postgres -d mydatabase -c `
(SELECT * ...... do something);
有效 - 并且不提示输入密码。
.\psql.exe --help
表示没有密码需要 -w 开关。
为什么这个命令在没有密码的情况下也能运行?数据库有密码。
该命令在没有密码身份验证的 PSQL 交互式 shell 中不起作用,仅在 PowerShell 中有效。
-w
不需要 "no password" 重读它所说的内容,来自我的 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
适用于当您使用 运行 psql 脚本并且无法输入密码时,例如在无头会话中。
Why does this command work without a password? The database has a password.
即使数据库 有 密码,如果您的 pg_hba.conf
文件有信任,则不需要密码。要进一步调试,我们需要查看您的 pg_hba.conf
.
PowerShell 中的这条 PSQL 语句:
.\psql --% -h localhost -p 5000 -U postgres -d mydatabase -c `
(SELECT * ...... do something);
有效 - 并且不提示输入密码。
.\psql.exe --help
表示没有密码需要 -w 开关。
为什么这个命令在没有密码的情况下也能运行?数据库有密码。
该命令在没有密码身份验证的 PSQL 交互式 shell 中不起作用,仅在 PowerShell 中有效。
-w
不需要 "no password" 重读它所说的内容,来自我的 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
适用于当您使用 运行 psql 脚本并且无法输入密码时,例如在无头会话中。
Why does this command work without a password? The database has a password.
即使数据库 有 密码,如果您的 pg_hba.conf
文件有信任,则不需要密码。要进一步调试,我们需要查看您的 pg_hba.conf
.