Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

*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

I ran

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 rake db:create:all

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

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.
share|improve this question

migrated from stackoverflow.com May 13 '13 at 12:17

This question came from our site for professional and enthusiast programmers.

Restart your Mac. The older version of Postgres (the one that's installed by OSX) might still be running. –  Denis May 3 '13 at 19:05
(Or the new one might not be running yet.) –  Denis May 3 '13 at 19:18
I restarted my Mac, but got the same problem. I ran the start command and it told me that another server might be running but that it would try to start it anyways. Is there anyway to check if it's running or not? –  Tomoko Yamaguchi May 3 '13 at 19:39
I did this-- ps aux | grep postgres to get --this result: 562 0.6 0.0 2432768 588 s000 S+ 12:45pm 0:00.01 grep postgres so I think postgres is running. I'm not sure if it's the old or the new. –  Tomoko Yamaguchi May 3 '13 at 19:46
The result of ps mentioned above actually indicates that postgres is not running, and it's confirmed by every other error you get. Look at the server log /usr/local/var/postgres/server.log. It probably tells what fatal error the server encountered that made it stop. –  Daniel Vérité May 3 '13 at 20:50

2 Answers 2

I have not watched the RailsCast, but here are the steps I took to set up PostgreSQL on OS X:

Mac OS X comes with PostgreSQL 9.0.4 installed automatically, and we need to change the symbolic links for the postgres, pg_ctl, and psql commands. After installing the latest PostgreSQL:

$ cd /usr/local/bin
$ rm postgres
$ ln -s /Library/PostgreSQL/9.2/bin/postgres postgres
$ rm psql
$ ln -s /Library/PostgreSQL/9.2/bin/psql psql
$ rm pg_ctl
$ ln -s /Library/PostgreSQL/9.2/bin/pg_ctl pg_ctl

The '/Library/PostgreSQL/9.2/bin' portion of the commands assumes you left that as default install location during the installer. If not you will have to modify that portion to where PostgreSQL is installed.

We need libpq-dev to be able to install the Ruby pg gem. After the setup completes, then run the following commands (where "user_name" can be whatever user name you would like Rails to use to access your database):

$ sudo -u postgres createuser --superuser $USER
$ sudo -u postgres createuser --superuser user_name
$ sudo -u postgres psql postgres

The first command creates a user that matches your user name. The second command creates a user for the Rails application to use. The third command will bring you directly into the psql console, and will open up the postgres database. It's just the database corresponding to the postgres user, which for some reason is necessary when installing PostgreSQL.

Once in the psql prompt, type the following command:

postgres=# \password user_name

and create a password.

You will also need to change the password for $USER (again this is your user name on your mac; you are not going to use this from Rails):

postgres=# \password <username>

You could use your system user password for consistency (the one you log in with). Once it returns you to the prompt, type "\q" to exit the psql prompt.

Now you'll be back in your terminal, and you can then create a database for your user, of course using whatever database name you like in place of my_database:

$ createdb my_database

Now, you need to change the postgresql.conf file to make PostgreSQL listen on at least localhost. If you have a setup where you want to listen on an external IP or something, change this line to either the IP or just '*'.

listen_addresses = 'localhost'

Then, in pg_hba.conf, make sure you've got this:

# "local" is for Unix domain socket connections only
local   all         all                               md5

Otherwise you'll probably get an error when trying to login from your Rails app. After this, all you've got to do is simply start PostgreSQL using this command:

$ sudo -u postgres pg_ctl -D /Library/PostgreSQL/9.2/data -l /Library/PostgreSQL/9.2/data/server.log start

And to stop:

sudo -u postgres pg_ctl -D /Library/PostgreSQL/9.2/data/ stop -s -m fast

Next step is to install the PostgreSQL ruby gem. This assumes that you have installed Ruby, Rails 3, and Bundler on your machine.

Place this in your project's Gemfile:

gem 'pg'

and then to install the gem:

$ bundle install

Finally, configure your Rails project to use PostgreSQL. Modify your config/database.yml file as follows:

  adapter: postgresql
  encoding: unicode
  host: localhost
  database: my_database
  pool: 5
  username: user_name
  password: password

Where "password" is whatever you set as the password for user_name. The "test:" and "production:" sections should be similar, but you could of course create three separate databases (something like my_database_dev, my_database_test, and my_database_prod, or whatever you want). Just create any additional databases using the createdb command, as you did above:

$ createdb my_database_dev

And you're good to go!

share|improve this answer
Thanks for this. I'll keep it in mind (and give you an upvote) however I'm hoping someone can identify the problem that i'm currently facing. –  Tomoko Yamaguchi May 3 '13 at 19:50
Also, I think I uninstalled or unlinked the version that came with mac in order to try the Railscast way. –  Tomoko Yamaguchi May 3 '13 at 20:03

Hello world :)
The best but strange way for me was to do next things.

1) Download postgres93.app or other version. Add this app into /Applications/ folder.

2) Add a row (command) into the file .bash_profile (which is in my home directory):

export PATH=/Applications/Postgres93.app/Contents/MacOS/bin/:$PATH
It's a PATH to psql from Postgres93.app. The row (command) runs every time console is started.

3) Launch Postgres93.app from /Applications/ folder. It starts a local server (port is "5432" and host is "localhost").

4) After all of this manipulations I was glad to run $ createuser -SRDP user_name and other commands and to see that it worked! Postgres93.app can be made to run every time your system starts.

5) Also if you wanna see your databases graphically you should install PG Commander.app. It's good way to see your postgres DB as pretty data-tables

Of, course, it's helpful only for local server. I will be glad if this instructions help others who has faced with this problem.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.