在Postgres上创建用户 - 身份验证问题 - 安装

时间:2014-02-18 18:49:37

标签: ruby-on-rails postgresql ubuntu

我正在尝试创建一个使用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:身份验证失败”。

我正在尝试使用本指南: 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"?

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

1 个答案:

答案 0 :(得分:0)

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