我已经在我的Ubuntu karma box上安装了PostgreSQL和pgAdminIII。
我能够成功地使用pgAdminIII(即连接/登录),但是当我尝试在命令行(使用psql)上使用相同的用户名/pwd登录到服务器时,我得到错误:
psql: FATAL: Ident authentication failed for user "postgres"
现在有人知道如何解决这个问题吗?
我已经在我的Ubuntu karma box上安装了PostgreSQL和pgAdminIII。
我能够成功地使用pgAdminIII(即连接/登录),但是当我尝试在命令行(使用psql)上使用相同的用户名/pwd登录到服务器时,我得到错误:
psql: FATAL: Ident authentication failed for user "postgres"
现在有人知道如何解决这个问题吗?
当前回答
对于Windows,如果您不想编辑pb_gba.conf,即保留MD5方法(默认),请在PGadmin的查询工具中运行此查询,创建一个新用户
CREATE USER admin WITH PASSWORD 'secret'
然后在CMD中
psql "dbname=Main_db host=127.0.0.1 user=admin password=secret port=5432
哪里dbname是你的db在postgresql
其他回答
编辑/etc/postgresql/8.4/main/pg_hba.conf文件,并将ident或peer替换为md5或trust,这取决于您是否希望它在您自己的计算机上询问密码。 然后重新加载配置文件:
/etc/init.d/postgresql reload
在pg_hba.conf中设置正确了吗?
参见https://ubuntu.com/server/docs/databases-postgresql如何做。
在Ubuntu 12.04中为Rails开发设置PostgreSQL之后,我也遇到了同样的问题
我尝试了其他答案,但我所要做的就是:“config/database.yml”
development:
adapter: postgresql
encoding: unicode
database: (appname)_development
pool: 5
username: (username you granted appname database priviledges to)
password:
对于fedora26和postgres9.6
首先,以root用户登录,然后通过以下命令进入psql
$ su postgres
then
$ psql
在PSQL中查找hba_file ==>的位置意味着pg_hba.conf
postgres=# show hba_file ;
hba_file
--------------------------------------
/etc/postgresql/9.6/main/pg_hba.conf
(1 row)
在pg_hba.conf文件中将用户访问权限更改为this
host all all 127.0.0.1/32 md5
以下步骤适用于在Ubuntu 12.04上重新安装postgres 9.1。(也适用于Ubuntu 14.04上的postgres 9.3.9)
默认情况下,postgres会创建一个名为'postgres'的用户。我们以她的身份登录,给她一个密码。
$ sudo -u postgres psql
\password
Enter password: ...
...
通过输入\q或ctrl+d退出psql。然后我们用postgres来联系。-h localhost部分很重要:它告诉psql客户端我们希望使用TCP连接(配置为使用密码身份验证)进行连接,而不是通过PEER连接(不关心密码)。
$ psql -U postgres -h localhost