Postgresql 还原Postgres数据库失败:用户的密码身份验证失败

Postgresql 还原Postgres数据库失败:用户的密码身份验证失败,postgresql,Postgresql,我尝试恢复Postgres数据库,如下所示: cat backup.sql | docker run -i postgres:12 /usr/bin/psql \ -h mydb.elephantsql.com -U mydbanduser mydbanduser 这是输出: Password for user mydbanduser: psql: error: FATAL: password authentication failed for user "mydbanduse

我尝试恢复Postgres数据库,如下所示:

cat backup.sql | docker run -i postgres:12 /usr/bin/psql \
  -h mydb.elephantsql.com -U mydbanduser mydbanduser
这是输出:

Password for user mydbanduser:
psql: error: FATAL:  password authentication failed for user "mydbanduser"
FATAL:  password authentication failed for user "mydbanduser"
可以看到,显示了密码提示,但它只是一步一步地过去,因此我无法输入密码。

在运行
psql
的用户的主目录中创建密码:

用户主目录中的文件
.pgpass
可以包含在连接需要密码时使用的密码(并且没有另外指定密码)。在Microsoft Windows上,文件名为
%APPDATA%\postgresql\pgpass.conf
(其中
%APPDATA%
指用户配置文件中的应用程序数据子目录)。或者,可以使用连接参数或环境变量
PGPASSFILE
指定密码文件

此文件应包含以下格式的行:

主机名端口数据库用户名密码

这为我解决了问题:

cat backup.sql | docker run -e PGPASSWORD=mypassword -i postgres:12 /usr/bin/psql \
  -h mydb.elephantsql.com -U mydbanduser -d mydbanduser