2
votes

I was using sqlite but switched to pg for some reasons.

I included pg gem in the makefile and made changes in the config/environments.

When I started migrating the data using rake db:migrate , I’m getting this error.

PG::ConnectionBad: 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"?

I've gone through all the posts related to this but did not find a solution.

I'm using ruby 2.1.5 and rails 4.2.0.

2
Switching from SQLite to Postgres is like switching from a Matchbox car to a Bugatti. You don't make those decisions lightly. Now, are you sure that you have the server running?Makoto
I'm getting the same error after starting the server too. But I was going through a couple of posts and run this command 'postgres -D /usr/local/var/postgres' . And now it says Fatal: User role 'sachilig' does not exist. Do I need to create an Account and password ?Novice
...Yes. Yes, you do. Hence my car analogy earlier; SQLite is a flat-file database which doesn't use credentials, whereas Postgres absolutely does use credentials.Makoto
A somewhat common configuration that you might consider is using SQLite for development and Postgres for production. That way, you don't get weighed down by the complexity of administering Postgres until you really need it.steve klein
@steveklein nonono, that way you fail to do all the important testing until you suddenly do it in production where there's the most chance of real harm caused by incompatibilities and problems. You also don't build experience with the system you're using in production in a safer environment. It's a terrible approach IMO. There's a reason that's not generally the recommended configuration anymore.Craig Ringer

2 Answers

1
votes

sudo /etc/init.d/postgresql start

or

sudo /etc/init.d/postgresql restart

Both should work just fine

If you still get an error you should fix the config/database.yml file one way to go about this is simply create a new project

rails new yourapp -d postgresql

then just copy the database.yml file

if you need to create an new user and password

sudo -u postgres createuser john -s

If you would like to set a password for the user, you can do the following

sudo -u postgres psql

postgres=# \password john

Most of this is from gorails

0
votes

You need to start your PG server:

$ postgres -D /usr/local/pgsql/data

http://www.postgresql.org/docs/9.1/static/server-start.html