我正在創建一個Rails應用程序並使用Postgresql數據庫。我創建了幾個表和一個用戶,core
,它是每個表的所有者。Postgresql的密碼驗證失敗
postgres=# create user core with password 'n7zD5FG5';
CREATE ROLE
postgres=# create database core_apps_prod with owner core;
CREATE DATABASE
postgres=# create database core_apps_dev with owner core;
CREATE DATABASE
postgres=# create database core_apps_test with owner core;
CREATE DATABASE
而且我database.yml
文件:
development:
adapter: postgresql
database: core_apps_dev
username: core
password: n7zD5FG5
host: localhost
然而,當我運行rake db:migrate
,我得到的錯誤
rake aborted!
FATAL: password authentication failed for user "core"
我也無法連接到psql
手動:psql -U core -W -d core_apps_dev
- 我得到的同樣的錯誤。
我如何允許core
連接到PostgreSQL的localhost
?
的SELECT * FROM pg_roles where rolname='core';
輸出是:
rolname | rolsuper | rolinherit | rolcreaterole | rolcreatedb | rolcatupdate | rolcanlogin | rolreplication | rolconnlimit | rolpassword | rolvaliduntil | rolconfig | oid
---------+----------+------------+---------------+-------------+--------------+-------------+----------------+--------------+-------------+---------------+-----------+-------
core | f | t | f | f | f | t | f | -1 | ******** | | | 16392
添加'-h localhost'給psql連接到本地主機,否則它的使用具有不同的身份驗證規則的Unix域套接字。另外通過使用'-W',你不知道服務器是否需要密碼,這在解決密碼問題時增加了混淆。只是省略'-W' –
我試過,通過運行命令'psql -h localhost -U core -d core_apps_dev'並輸入密碼,但它仍然顯示'psql:FATAL:用戶密碼驗證失敗「核心」 。我通過運行'ALTER USER核心口令'n7zD5FG5';'確保密碼是正確的,但它仍然失敗。 – josh
你做了什麼爲我工作。在這一點上,我懷疑有幾種可能性:1.在不同的PG實例上創建帳戶。 2. [pgadmin bug on valuntil](http://stackoverflow.com/questions/14564644),儘管你從未提到過pgadmin。 3. pg_hba.conf中的怪異。 4.驗證選項中postgresql.conf中的怪異。爲了清楚一點,我將auth方法設置爲在相關行上的pg_hba.conf中「trust」,重新加載PG並重試。它應該連接而不要求輸入密碼。 –