当我创建一个新用户,但它不能登录数据库。 我是这样做的:

postgres@Aspire:/home/XXX$ createuser dev
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) y
Shall the new role be allowed to create more new roles? (y/n) y

然后创建一个数据库:

postgres@Aspire:/home/XXX$ createdb -O dev test_development

之后,我尝试psql -U dev -W test_development登录,但得到错误:

psql: FATAL:  Peer authentication failed for user "dev"

我试图解决这个问题,但失败了。


当前回答

pg_dump -h localhost -U postgres -F c -b -v -F mydb。备份mydb

其他回答

为了方便以后看到这个,postgres在我的Ubuntu服务器的/usr/lib/postgresql/10/bin目录下。

我将它添加到.bashrc文件的PATH中,并在末尾添加这一行

PATH=$PATH:/usr/lib/postgresql/10/bin

然后在命令行上

$> source ./.bashrc

我刷新了bash环境。现在我可以在任何目录中使用postgres -D /

对等身份验证意味着postgres向操作系统询问您的登录名并使用此名进行身份验证。在postgres上使用对等身份验证以“dev”用户登录时,必须同时是操作系统上的“dev”用户。

您可以在Postgresql文档中找到身份验证方法的详细信息。

提示:如果没有任何身份验证方法,请断开服务器与网络的连接,并为“localhost”使用方法“trust”(并在启用方法“trust”时再次检查您的服务器是否无法通过网络访问)。

在终端试试:

>> psql -U role_name -d database -h hostname.<domain>.com -W

pg_dump -h localhost -U postgres -F c -b -v -F mydb。备份mydb

我只需要添加-h localhost