0

I'm attempting to create a Ruby on Rails web app that uses postgres as its database. I am having trouble connecting to the server with postgres

I have installed PostgreSQL and have successfully created a Rails app that uses postgres. However, when I run "rails server", it returns..

=> 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?

I believe I have an authentication problem. I've tried to follow two SO links, which appear to have worked for a great number of people, but for which the first steps have failed for me.

How to configure postgresql for the first time?

The first step of this link (su root) resulted in: "su: Authentication Failure".

I am trying to use this guide: https://www.digitalocean.com/community/articles/how-to-install-and-use-postgresql-on-ubuntu-12-04

If I use "sudo -i", the "su - postgres" command works. "createuser" then results in:

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"?

When trying to follow the Ubuntu Postgres guide at https://help.ubuntu.com/community/PostgreSQL I had less success, with

sudo -u postgres psql postgres

returning:

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"?

Thanks! I'm still a beginner, so please explain things as simply as possible and elaborate.

Community
  • 1
  • 1
Emilia Flo
  • 31
  • 6
  • Please add the result of `pg_lsclusters` to your question. This will tell if postgres instances are installed and if they're online. – Daniel Vérité Feb 18 '14 at 20:42

1 Answers1

0

You still need to start the postgres server. In ubuntu sudo /etc/init.d/postgresql-8.4 restart

toolz
  • 871
  • 6
  • 12
  • I have succesfully restarted the server, but all errors (for trying to add users, starting my rails app, etc) listed in the question remain the same. – Emilia Flo Feb 18 '14 at 20:38
  • do this in the command line `netstat -tulpn | grep postgres` and it will show you what port postgresql is listening on. Maybe you've configured it to listen on something other than 5432 (which is postgresql default). Also, please include the contents of your config/database.yml from your rails app so I can see how you're trying to access postgres. Here is an example database.yml file https://gist.github.com/erichurst/961978#file-database-yml-example-postresql – toolz Feb 18 '14 at 20:49