4

I have been trying to set up my ruby on rails dev environment for a project I just started working on. I have installed Ruby 1.9.3, Rails 3.2, and postgresql 9.1.4 on Ubuntu 12, and when I try rake db:create:all I get the message:

/var/lib/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:1194:in `initialize': could not connect to server: No such file or directory (NameError)
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

I then added:

host: localhost

port: 5432

to my database.yml file, which let me do db:create:all and db:migrate, but when I run the rails server locally it still has the same error.

I have checked that the postgresql server is running, which it is (I also know it is running since rake worked earlier), and have tried a fresh install of postgresql. What might I be missing to make this work?

1 Answer 1

2

Are you sure your postgres server is running? If you do ps -aef|grep postgres, you should see something like this:

[root@haddock ~]# ps -aef|grep 'postgres'
postgres  5963  5475  0 21:28 ?        00:00:00 /usr/postgresql/bin/postmaster -D <your postgres directory>
postgres  5972  5963  0 21:28 ?        00:00:00 postgres: writer process                          
postgres  5973  5963  0 21:28 ?        00:00:00 postgres: wal writer process                      
postgres  5974  5963  0 21:28 ?        00:00:00 postgres: autovacuum launcher process             
postgres  5975  5963  0 21:28 ?        00:00:00 postgres: stats collector process                 
admin     6750  6607  0 21:30 ttyS0    00:00:00 grep postgres
Sign up to request clarification or add additional context in comments.

4 Comments

Also, does your postgres server have the standard config?
It did have the standard config until a few minutes ago, when I modified it to have unix_socket_directory = '/var/run/postgresql/.s.PGSQL.5432' in postgresql.config after reading askubuntu.com/questions/50621/… . Also, when I ran ps -aef|grep postgres before changing the config and restarting I had something that looked like that, but now I do not see any processes. Now when running the rails server I get an error saying the connection was refused, and to check that it is running on TCP/IP port 5432
Did you use the -h localhost option in your postgres config? If not, then you would get the error you mentioned.
I have reinstalled postgresql and the processes are now running, but I still have the original error. As of right now I have not modified the postgresql config from the default. I can create and migrate my databases for the project, but still cannot connect connect to the DB when running rails server. I thought that using the -h localhost when doing command line psql stuff makes it connect through TCP/IP sockets, is there a config where I need to put it as well? postgresql.config in /etc/? Is there a reason I would want to use TCP/IP instead of UNIX sockets? This is just for my dev setup.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.