【发布时间】:2020-08-13 02:18:59
【问题描述】:
我已经查看了类似的问题并尝试了诸如编辑 pg_hba 文件以信任和执行 ALTER USER postgres PASSWORD 'newPassword'; 等方法。但都没有奏效。进行此类更改后,我确实重新启动了 postgres。
上下文是我有一个我工作的公司的 Web 应用程序,我正在尝试通过命令 bundle exec rake db:...
运行创建数据如果有帮助,我最初收到错误“PG::ConnectionBad: 无法连接到服务器:连接被拒绝服务器是否在主机“localhost”(::1) 上运行并接受端口 5432 上的 TCP/IP 连接? 无法连接到服务器:连接被拒绝服务器是否在主机“localhost”(127.0.0.1)上运行并接受端口 5432 上的 TCP/IP 连接?“centos””
注意:发生这种情况时,我正在使用 centOS。尝试切换到ubuntu,同样的交易。然后我尝试安装 PostgreSQL,直到那时,bundle install 命令只安装了'pg'。然后,这将错误消息更改为这篇文章的内容。我在 VirtualBox 上运行 Ubuntu 19.10。如果有人知道如何解决这个问题,我们将不胜感激;几个小时以来,我一直在尝试解决这个问题。作为参考,扩展的错误消息如下:
bundle exec rake db:create_organization['Organization Name']
rake aborted!
PG::ConnectionBad: FATAL: password authentication failed for user "postgres"
FATAL: password authentication failed for user "postgres"
/var/lib/gems/2.5.0/gems/pg-0.21.0/lib/pg.rb:56:in `initialize'
/var/lib/gems/2.5.0/gems/pg-0.21.0/lib/pg.rb:56:in `new'
/var/lib/gems/2.5.0/gems/pg-0.21.0/lib/pg.rb:56:in `connect'
/var/lib/gems/2.5.0/gems/activerecord-5.1.7/lib/active_record/connection_adapters/postgresql_adapter.rb:705:in `connect'
...
...
(more of the same)
...
...
/home/reeda19/dashboard/lib/tasks/onboarding/01_create_organization.rake:8:in `block (2 levels) in <top (required)>'
/var/lib/gems/2.5.0/gems/rake-12.3.3/exe/rake:27:in `<top (required)>'
Tasks: TOP => db:create_organization
(See full trace by running task with --trace)
再次感谢您的帮助
编辑:config/database.yml 文件:
默认值:&默认值 适配器:postgresql 编码:utf8 主机:本地主机 用户名:postgres 密码:密码 端口:5432 重新连接:真 池:10
发展:
测试:
分期:
生产:
编辑 2:更新了 postgres 用户密码,以匹配 database.yml 文件中使用 ALTER USER user_name WITH PASSWORD 'new_password'; 设置的密码。我不再收到致命的密码错误,而是收到了这个新错误:
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "businesses" does not exist
LINE 8: WHERE a.attrelid = '"businesses"'::regclass
^
: SELECT a.attname, format_type(a.atttypid, a.atttypmod),
pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod,
c.collname, col_description(a.attrelid, a.attnum) AS comment
FROM pg_attribute a
LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum
LEFT JOIN pg_type t ON a.atttypid = t.oid
LEFT JOIN pg_collation c ON a.attcollation = c.oid AND a.attcollation <> t.typcollation
WHERE a.attrelid = '"businesses"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
不确定 100% 是否这是我的数据库的问题,或者更多的是 psql 的问题。
将根据任何进一步的进展进行更新。
最终编辑:一个简单的 rake db:reset 修复了这个新错误!现在好像一切正常
【问题讨论】:
-
你试过了吗? stackoverflow.com/questions/7695962/… P.S 对不起,没有发表评论的声誉。
-
是的,我试过了,没用:(