【问题标题】:Creating Users on Postgres - Authentication Issues - Installing在 Postgres 上创建用户 - 身份验证问题 - 安装
【发布时间】:2014-02-19 03:07:01
【问题描述】:

我正在尝试创建一个使用 postgres 作为其数据库的 Ruby on Rails Web 应用程序。我无法使用 postgres 连接到服务器

我已经安装了 PostgreSQL 并成功创建了一个使用 postgres 的 Rails 应用程序。但是,当我运行“rails server”时,它会返回..

=> Booting WEBrick
=> Rails 3.2.13 application starting in development on XXX:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/usr/lib/ruby/vendor_ruby/active_record/connection_adapters/postgresql_adapter.rb:1215:in `initialize': could not connect to server: Connection refused (PG::ConnectionBad)
    Is the server running on host "localhost" (127.0.0.1) and accepting
    TCP/IP connections on port 5432?

我认为我遇到了身份验证问题。我尝试关注两个 SO 链接,这些链接似乎对很多人都有效,但对我来说第一步都失败了。

How to configure postgresql for the first time?

此链接的第一步(su root)导致:“su: Authentication Failure”。

我正在尝试使用本指南: https://www.digitalocean.com/community/articles/how-to-install-and-use-postgresql-on-ubuntu-12-04

如果我使用“sudo -i”,“su - postgres”命令会起作用。 “createuser”然后结果:

Enter name of role to add: XXX(root username)
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) n
createuser: could not connect to database postgres: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

在尝试遵循https://help.ubuntu.com/community/PostgreSQL 的 Ubuntu Postgres 指南时,我没有成功,与

sudo -u postgres psql postgres

返回:

psql: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

谢谢!我还是一个初学者,所以请尽可能简单和详细地解释。

【问题讨论】:

  • 请将pg_lsclusters 的结果添加到您的问题中。这将告诉您是否安装了 postgres 实例以及它们是否在线。

标签: ruby-on-rails postgresql ubuntu


【解决方案1】:

您仍然需要启动 postgres 服务器。在ubuntu中sudo /etc/init.d/postgresql-8.4 restart

【讨论】:

  • 我已成功重启服务器,但问题中列出的所有错误(尝试添加用户、启动我的 Rails 应用程序等)均保持不变。
  • 在命令行netstat -tulpn | grep postgres 中执行此操作,它将显示 postgresql 正在侦听的端口。也许您已将其配置为侦听 5432 以外的其他内容(这是 postgresql 的默认值)。另外,请在您的 rails 应用程序中包含您的 config/database.yml 的内容,以便我可以看到您如何尝试访问 postgres。这是一个示例 database.yml 文件gist.github.com/erichurst/…
猜你喜欢
  • 1970-01-01
  • 2019-07-02
  • 1970-01-01
  • 2012-11-22
  • 1970-01-01
  • 2017-02-08
  • 2016-11-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多