gpt4 book ai didi

postgresql - PSQL 不提示在 PowerShell 中输入密码

转载 作者:行者123 更新时间:2023-11-29 12:03:14 24 4
gpt4 key购买 nike

PowerShell 中的 PSQL 语句:

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

有效 - 并且不提示输入密码。

.\psql.exe --help

声明没有密码需要 -w 开关。

为什么这个命令在没有密码的情况下也能工作?数据库有密码。

该命令在没有密码身份验证的 PSQL 交互式 shell 中不起作用,仅在 PowerShell 中起作用。

最佳答案

-w 不需要“无密码”重读它所说的内容,来 self 的 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 脚本并且无法输入密码时,例如在 headless session 中。

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

即使数据库密码,如果您的pg_hba.conf 文件有信任,则不需要密码。为了进一步调试它,我们需要查看您的 pg_hba.conf

关于postgresql - PSQL 不提示在 PowerShell 中输入密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43639432/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com