*Update*I included an update at the bottom of this post with details from the logs explaining the problem that I haven't been able to fix.
Following along with this Railscast http://railscasts.com/episodes/342-migrating-to-postgresql, I just installed postgres on my Mac Lion using HomeBrew, (even though it apparently comes installed with Lion as Ryan notes in the video).
To start the server I ran the following command but got a message that another server might be running
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start pg_ctl: another server might be running; trying to start server anyway server starting
After 'server starting' my terminal window returned to normal (i.e. there was no indication that anything was running in the way that the Rails server webrick normally shows that a process is running).
I then created a new Rails application setting postgres as the option for the database and, following along with the Railscast, ran
rake db:create all but got an error
rake db:create all could not connect to server: No such file or directory Is the server running locally and accepting
This was also part of the error message
rake aborted! Don't know how to build task 'all'
Can anyone tell me what I might have to do to get this working properly?
This is the version of postgres I installed with home-brew.
me$ psql --version psql (PostgreSQL) 9.2.3 me$ which psql /usr/local/bin/psql
ps aux | grep postgres
and got this result:
562 0.6 0.0 2432768 588 s000 S+ 12:45pm 0:00.01 grep postgres
So I assume it's running but don't know which version.
I'm now getting this error when I run rake db:create:all
could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
There's an SO answer that deals with this problem here Postgres could not connect to server
It instructs to 'check that the socket file exists'
ls -l /tmp/.s.PGSQL.5432 srwxrwxrwx 1 you wheel 0 Nov 16 09:22 /tmp/.s.PGSQL.5432
When I do that, I get this error
ls: /tmp/.s.PGSQL.5432: No such file or directory
According to that answer, if it doesn't exist
If it doesn't then check your postgresql.conf for unix_socket_directory change.
$ grep unix_socket /usr/local/var/postgres/postgresql.conf #unix_socket_directory = '' # (change requires restart) #unix_socket_group = '' # (change requires restart) #unix_socket_permissions = 0777 # begin with 0 to use octal notation
That's the response that I also get. There's no further information available in that answer, but the person who answered the question found a solution by
$ mkdir /var/pgsql_socket/ $ sudo mkdir /var/pgsql_socket/ $ ln -s /private/tmp/.s.PGSQL.5432 /var/pgsql_socket/
I did all of those commands but still get the same error when I run
Update: I put the following command in my chrome browser for the purpose of searching how to retrieve postgres logs and it gave me the logs.
The problem seems to be in this line from the logs but I can't figure out how to remove that data directory.
DETAIL: The data directory was initialized by PostgreSQL version 9.1, which is not compatible with this version 9.2.3.
LOG: database system was shut down at 2012-02-27 19:18:09 PST LOG: autovacuum launcher started LOG: database system is ready to accept connections LOG: received fast shutdown request LOG: aborting any active transactions LOG: autovacuum launcher shutting down LOG: shutting down LOG: database system is shut down LOG: database system was shut down at 2012-02-27 21:30:56 PST LOG: autovacuum launcher started LOG: database system is ready to accept connections FATAL: role "shawsome" does not exist FATAL: role "shawsome" does not exist FATAL: role "shawsome" does not exist ERROR: role "myname" already exists STATEMENT: CREATE ROLE MYNAME PASSWORD 'md5b42169a737cea337fe663aa9fbb1df19' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN; WARNING: pgstat wait timeout WARNING: pgstat wait timeout WARNING: pgstat wait timeout LOG: database system was interrupted; last known up at 2012-02-28 21:32:13 PST LOG: database system was not properly shut down; automatic recovery in progress LOG: record with zero length at 0/1714388 LOG: redo is not required LOG: autovacuum launcher started LOG: database system is ready to accept connections WARNING: pgstat wait timeout WARNING: pgstat wait timeout FATAL: database files are incompatible with server DETAIL: The data directory was initialized by PostgreSQL version 9.1, which is not compatible with this version 9.2.3.